Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
47
Task/Call-a-function/Lambdatalk/call-a-function.lambdatalk
Normal file
47
Task/Call-a-function/Lambdatalk/call-a-function.lambdatalk
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
The command
|
||||
|
||||
replace :a0 :a1 ... an-1
|
||||
in expression containing some occurences of :ai
|
||||
by v0 v1 ... vp-1
|
||||
|
||||
is rewritten in a prefixed parenthesized form
|
||||
|
||||
{{lambda {:a0 :a1 ... an-1}
|
||||
expression containing some occurences of :ai}
|
||||
v0 v1 ... vp-1}
|
||||
|
||||
so called IIFE (Immediately Invoked Function Expression), and defines an anonymous function containing a sequence of n arguments :ai, immediately invoked on a sequence of p values vi, and returning the expression in its body as so modified:
|
||||
|
||||
1) if p < n (partial application)
|
||||
|
||||
• the occurrences of the p first arguments are replaced in the function's body by the corresponding p given values,
|
||||
• a function waiting for missing n-p values is created,
|
||||
• and its reference is returned.
|
||||
• example:
|
||||
{{lambda {:x :y} ... :y ... :x ...} hello}
|
||||
-> {lambda {:y} ... :y ... hello ...} // replaces :x by hello
|
||||
-> LAMB_123 // the new functions's reference
|
||||
• called with the value world this function will return ... world ... hello ...
|
||||
|
||||
2) if p = n (normal application)
|
||||
|
||||
• the occurences of the n arguments are replaced in the function's body by the corresponding p given values,
|
||||
• the body is evaluated and the result is returned.
|
||||
• example
|
||||
{{lambda {:x :y} ... :y ... :x ...} hello world}
|
||||
-> {{lambda {:y} ... :y ... hello ...} world} // replaces :x by hello
|
||||
-> {{lambda {} ... world ... hello ...} } // replaces :y by world
|
||||
-> ... world ... hello ... // the value
|
||||
|
||||
3) if p > n (variadicity)
|
||||
|
||||
• the occurrences of the n-1 first arguments are replaced in the function's body by the corresponding n-1 given values,
|
||||
• the occurrences of the last argument are replaced in the body by the sequence of p-n supernumerary values,
|
||||
• the body is evaluated and the result is returned.
|
||||
• example:
|
||||
{{lambda {:x :y} ... :y ... :x ...} hello world good morning}
|
||||
-> {{lambda {:y} ... :y ... hello ...} world good morning}
|
||||
-> {{lambda {} ... world good morning ... hello ...}}
|
||||
-> ... world good morning ... hello ... // the value
|
||||
|
||||
More can be seen in http://lambdaway.free.fr/lambdawalks/?view=lambda
|
||||
Loading…
Add table
Add a link
Reference in a new issue