3 ms·
It's trivial to add an arg words style lambda to Rebol. For example, here is a very naive version: lambda: function [block] [ args: sort unique collec
by draegtun 11y ago
It's trivial to add an arg words style lambda to Rebol.
For example, here is a very naive version:
lambda: function [block] [
args: sort unique collect [
parse block [
any [
w: set arg get-word! (
keep to-word arg
change w to-word arg
)
| skip
]
]
]
function args block
]
test in REPL...
>> f: lambda [:a + :b]
>> f 1 2
== 3
>> foo: lambda [c: :a + :b print [:a "+" :b "=" c]]
>> foo 1 2
1 + 2 = 3
NB. However you wouldn't really use :arg-name here because this is already reserved for the get-word! datatype.
- gokr 11y agoYes, and I never implied its not hard to do. And examples such as this one are quite impressive - which is what got me interested in Rebol in the first place and triggered the development of Ni. However... if I understand your code properly - you are basically generating an argument declaration by scanning for "get words". So its still a static declaration. In Ni an arg word is an operation. That means a Ni func can decide how many arguments to pull, and in which order, dynamically, much like stack oriented languages can do. Usefulness? Dunno :) But its not the same. Also, yes, I opted out of set words in Ni since I want to be able to have keyword syntax á la Smalltalk/Self. And I use "^" instead of ":" prefix for get words, because I wanted the argwords to be similar to how they look in Smalltalk. :)