Combinatory programing offers functional control flow. (Here is a straight forward explanation: https://blog.zdsmith.com/series/combinatory-programming.html ) I was inspired to write `better-cond` in Janet: (defn better-cond [& pairs] (fn [& arg] (label result (defn argy [f] (if (> (length arg) 0) (f ;arg) (f arg))) # naming is hard (each [pred body] (partition 2 pairs) (when (argy pred) (return result (if (function?…
When if is just a function
31–40 of 111 posts
Re: When if is just a function
#32Earlier quoted context omitted.
Rye is foremost a REBOL and REBOL has this notion of many types of words at it's core: `word` - regular word, can evaluate to value it's bound to or call a funtion if bound to a function `word: "value"` - set-word, assignment that you noticed `probe :word` - get-word, always returns bound value, doesn't call a function if it's bound to a function, in Rye this is `?word`, because `:word` is left-set-word. `'word` - li…
> Rye also has left to right flow so it adds left-set-word. In Rye all assigned words with set-words are constants and they are used by default. So we also need a "mod-word", that is the double colon that you noticed, and left-mod-word So I would assume that the :i is actually constant within the loop body scope. That is, the loop function is doing something like this: ; i is not assigned in this scope evaluate {1 :i…
It would be costly to have this on by default. If you want separation there are many ways to achieve it. Rye has many functions related to contexts / scopes. For creating contexts in multiple ways and evaluating code inside contexts or with context as parent or isolated context, etc.
And a lot of builtins directly accept anonymous functions in place of blocks of code.
For example for loop also accepts function if you want separation and don't mind the cost.
for { 1 2 3 } fn { x } { print x }
; which can also be written with fn1
for { 1 2 3 } fn1 { .print }
; or latest experiment where we have syntax for 3 injected blocks
; .() - same as "with"
; .[] - same as "reduce/with"
; .{} - same as "fn1"
; where it's already decided department from REBOL:
; () is "do"
; [] is "vals"
; {} is literal block
for { 1 2 3 } .{ .print }Re: When if is just a function
#33I wish they showed the `else` syntax, because the traditional ALGOL-style if-then-else statement doesn't look native when shoved into most function call notations, unless you have something pretty interesting around named parameters and expressions delimiters.
Re: When if is just a function
#34=if(condition, value-if-true, value-if-false)
Re: When if is just a function
#35Interestingly, Excel provides "if" as a function: =if(condition, value-if-true, value-if-false)
Re: When if is just a function
#36Re: When if is just a function
#37Seems a bit like Tcl, which lets you create your own control structures like that.
Re: When if is just a function
#38Re: When if is just a function
#39Re: When if is just a function
#40Earlier quoted context omitted.
Certainly: I can tell the rye devs like the idea of everything being a function. But in their very first "language basics" section, they introduce assignment not as a function call, but as some kind of magic that happens when you have colons in a name. So when we get to the "looping" section, it is the first time we have seen a colon-having-name outside the context of assignment: > loop 3 { ::i , prns i } And it is e…
If you treat assignment as a function, then you have to reify environments as run-time objects, whereby you basically lose lexical scope. Lisp originally, as in LISP, had assignment as a function: it was called SET. To use it, you usually had to quote: (SET 'VAR 42). It worked without an environment parameter because variables were in a pervasive environment, but the quote was needed to get the variable symbol as a r…
set a 5
puts $a #prints 5
and of course because it is modeled as a function (albeit an impure one) you can pass arguments to it as normal: set a b
set $a 5 #equivalent to set b 5
puts $b #prints 5
of course, everything in tcl is a string, so this works too lol set a 5
set $a b
puts $5 #prints b