Using Rye

How can we use Rye for fun and profit …

Values and assignment

“values, values everywhere …” Values All that Rye is, is a bunch of Rye values. All your code is made of Rye values and all your code works with are Rye values. Some values are atomic. For example integers, decimals, text, emails, URLs, words … 33 ; integer 3.14 ; decimal "Hello word" ; text jim@example.com ; email https://example.com ; URL 'word ; literal word Also a Rye value, a Block, is a colections of values.

Calling functions

“all day I sit here and make function calls” Print hello When you are writing programs in Rye, almost all that you actually do is make function calls. Well, you do that in every language, but in Rye, this statement is much more true than in most of them. More on that in the next page. Many functions are already built into Rye runtime, they are written in it’s host language Go.

Do-ing blocks

“to do or not to do, is now the question” REBOL and Lisp In REBOL, contrary to Lisps, blocks or lists don’t evaluate by default. For better or for worse, this little difference is what makes REBOL - REBOL. Fire up random online Lisp REPL and enter: ; Lisp (print (+ 11 22)) ; prints: 33 -- evaluated the list and printed the result (print '(+ 11 22)) ; prints: (+ 11 22) -- we had to quote it so it doesn't evaluate the list When we give Lisp a block it evaluates it and prints the result.


“if it has no special forms, how does it have if” Revisit Do again On the previous page we looked at the do function. It accepts one argument, a block of code and evaluates it. do { print "Hello" } ; prints: Hello If Now think of a function similar to do function. But it takes another argument and only evaluates the block of code if the first argument is True (1).


Just functions again Like conditionals (if, either, switch) looping constructs in Rye are also just functions. Rye has many of them, and you can create your own. Simple loop Sometimes you just need to loop N times. And there is a function for that. It accepts integer - a number of loops and a block of code. loop 2 { print "Hey!" } ; prints: ; Hey! ; Hey! ; Hey!

Making functions

Builtin functions Rye comes with many builtin functions. Functions that are defined in a host language (Go). Rye functions You can create your own functions in Rye. To make a function you again use a function (that constructs functions). The simpler such builtin function is fn. It returns a function which we assign to a word using a set-word, like any other value. double: fn { x } { x + x } square: fn { y } { y * y } Fn takes two blocks.