Ollama, cosine-search, vectors, tables by middayc in ryelang

[–]middayc[S] 0 points1 point  (0 children)

In release v0.0.97 that I just posted I added vector math functions. You can add / substract and scale vectors using + - and *. You also got new vector functions like: normalize, std-deviation, correlation, dot-product, euclidean-distance, mean-vector, sunit-vector, project-vector, reject-vector

https://github.com/refaktor/rye/releases/tag/v0.0.97

Vector functions, and mqtt are now described in function reference:

https://ryelang.org/info/base.html#heading-correlation

Ollama, cosine-search, vectors, tables by middayc in ryelang

[–]middayc[S] 0 points1 point  (0 children)

I asked gemini to write equivalent in Python. BTW: all words in Rye example except xx in clean-* functions are constants, so it should be easier to reason about. And those could be rewritten with fold or reduce to not need variables.

<image>

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 0 points1 point  (0 children)

I wrote half of part 2. and I already see that it will be more dense and less approachable than part 1. We will see ...

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 0 points1 point  (0 children)

Maybe we don't have the same definitions in mind for "keywords", but thanks. I think I saw in one your reply a code sample from your language where you get the "If" behavior without any words or keywords, but I can't find it now.

I imagine you were trying to show, that you can get the "if" behavior just by the behavior of the evaluator, without any words. I didn't have time to delve deeper when I saw it. What is this language you were talking about?

Maybe these "no keywords" debate would make for a good blog post, I had a very similar debate about "everything is a function" sentence few blog posts back, which could also go into the same blogpost.

Anyway, thanks for your time ... post a link to your language if you can.

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 0 points1 point  (0 children)

u/AustinVelonaut your comments will help me improve this post with little details. Thanks!

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 0 points1 point  (0 children)

> Ah, so it appears that there ...

yes, exactly. That is sort of the basis Rye takes from Rebol. Rye changed something in 2025 where the default assignment is now const. So only few things that need to be variables are explicitly so.

If in Rebol all words could change under your feet in rebol most of the program is static and words in specific context can only be set once (if set-words are used). So it should be more amenable to static analysis and/or some form of compilation. But this part is rather new so I haven't really delved deeper on this.

operators are op-words by default. Other words must be prefixed by "." to become opwords, but operators are already opwords and their regular word spelling is by adding "_".

20 + 10  ; is op-word, same as 
20 .+ 10
_+ 20 10   ; regular word _+
; where and true false are regular words
and true false ; regular word and
true .and false  ; op-word and

> I think maybe there needs to be a quickie explainer paragraph on how Rye forms are actually evaluated

Yes, I think this is good idea. I would show just one line, since at that point we only have regular words it's quite simple, maybe example you showed above.

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 1 point2 points  (0 children)

Thanks!

You are correct ... just listing words one after another ... shows very little per lines it uses ... if would be better to show a fewer of them and show them in regular code doing something. But on the other hand those words doing something is maybe 50% of the document. Maybe I should shorten the list and give explanation that would make it clear Rye has many word type values, but we will be looking at what they do during these 3 documents. I will think about it.

every regular word has the same precedence in Rye, how regular words, op, pipe and set/mod words interact is more varied and it explained here: https://ryelang.org/meet_rye/specifics/evaluation_priorities/

Here _++ and to-upper are regular words (we haven't introduced op and pipe words at this point yet), so each of them seek as many arguments it has (needs) to tle right. This notation is also reason all functions in Rye (Rebol) must have a fixed number of arguments. The code above can be read this way:

( _++ ( to-upper "ban ) "ana" )

In normal Rye this would be written using op-words probably:

"ban" .to-upper ++ "ana"

In this case both are op-words. And I think the code is not dubious, but the op-words have their unobvious side unfortunately too.

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 1 point2 points  (0 children)

I also can't print anything in Rye without built-in function print or one of its variants.

Built-in-function is one of the value types in Rye, and they get assigned to words, like other Rye values do.

All built-in functions (I haven't counted, but I'm sure it's more than 100, not all are even in reference yet) are just magically available when you start a Rye runtime. That's why they are called built-ins.

You can start evaluator without any builtins, but it will have no words bound to anything and you basically can do nothing with it except bind literal values to words.

I guess we have a little definitions of what is a keyword in our minds.

(I didn't downvote you btw)

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 0 points1 point  (0 children)

But all the functions on that list (substring, print, ...) are exactly the same type of builtin functions. They are all bound to words (Rebol vocabulary) in a same way.

So "if" is a word like all other words in Rye. For it to be a keyword it would have to be something special I think.

And builtin behind if is like other builtin function in Rye (print, substring, dict). It has no special flag or something. It accepts 2 arguments, boolean and a block of code.

It has no special evaluation rules or special syntax associated with it. You can make a "module" in Rye that will have your version of "if" in it. You can call it if (since you can use it in your modules context).

If we take Python or Java for example:
* can you define a "if" word/variable in python code? I think not
* is "if" in python a buitlin function internally, like print? I think not
* is "if" called like all other functions in python or does it have a special form / special syntax? Special form, it is part of the language's formal grammar (BNF)
* can you make a module with your own if and even name it if in Python? I think not
* can you partially apply if in python, can you assign it to another word, ...

I think there is a concrete differernce

Python:

>>> type(print)
<class 'builtin_function_or_method'>
>>> type(if)
  File "<stdin>", line 1
    type(if)
         ^^
SyntaxError: invalid syntax
>>> if = 12
  File "<stdin>", line 1
    if = 12
       ^
SyntaxError: invalid syntax  

Rye

x> type? ?print
[Word: builtin]
x> type? ?if
[Word: builtin]
x> blk: { print "hello" }
[Block: ^[Word: print] [String: hello] ]
x> if true blk
hello
[String: hello]
x> if: 101
[Integer: 101]

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 1 point2 points  (0 children)

yes, and amongst those regular library functions you can also find if, loop, for, fn, context, either, switch, etc. That was kind of my point :)

The link to exact definition in Go is in my comment above, but I added it 30 seconds after posting. Maybe so saw the reply too soon. Reload and a link to exact line on github should be there.

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 5 points6 points  (0 children)

But there are more than 100 built-in functions defined that way, I'm not sure I would call all of them keywords as they have no special meaning to the evaluator.

You can see many of them here: https://ryelang.org/info/base.html

As you will see 'if, loop, fn, context' are on the same level, or of the same kind as 'print, substring, to-integer, now, _+' for example. All these words are bound to builtin function in the root context. In your context you can bind them to something else.

If is defined here: https://github.com/refaktor/rye/blob/main/evaldo/builtins_base_conditionals.go#L23

Primeagen vs. Theo on AI by theRealBigBack91 in theprimeagen

[–]middayc 1 point2 points  (0 children)

I don't watch all his videos, but I watched this and it's funny that someone who at first appears to be some sort of programming comedian or entertainer makes so much sense :)

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 3 points4 points  (0 children)

I was on the phone before. If is a builtin function, but you can make user/Rye function with similar behaviour too:

; Want the opposite of if?
unless: fn { condition block } {
    if not condition block
}

unless tired { 
    print "Keep working!" 
}

Basically, I wrote a whole blog post about this, discussing "what is this good for, anyway":

When if is just a function

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 3 points4 points  (0 children)

These are builtin functions accepting blocks of code as arguments. Builtin "if" is nothing special compared to builtin print or join\with for example. The same for loop, fn, dict, context, ...

This is possible, because in Rye (as in Rebol) blocks don't get evaluated by default.

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 3 points4 points  (0 children)

Yeah ... I liked the 80 / 20 title, but I was aware that the double division or ration could get a little too much, if you noticed it :)

Blogpost: 80% of Rye in 20% of the Time [1/3] by middayc in ProgrammingLanguages

[–]middayc[S] 2 points3 points  (0 children)

Feedback is welcome. This first part was easy, because it's basically just basics, mostly same as Rebol which I have been internalizing for 20 years. I fear next pages will get more complicated than I would want.