add lambda shorthand with params
This commit is contained in:
parent
371615a899
commit
4d437eaac1
@ -69,8 +69,12 @@ function Lisp (input, lib) {
|
|||||||
__fn: function (input, context) {
|
__fn: function (input, context) {
|
||||||
return async function () {
|
return async function () {
|
||||||
const lambdaArguments = arguments
|
const lambdaArguments = arguments
|
||||||
const lambdaScope = [].reduce(function (acc, x, i) {
|
const keys = input.slice(2).filter(i =>
|
||||||
acc[x.value] = lambdaArguments[i]
|
i.type === TYPES.identifier &&
|
||||||
|
i.value[0] === '%'
|
||||||
|
).map(x => x.value).sort()
|
||||||
|
const lambdaScope = keys.reduce(function (acc, x, i) {
|
||||||
|
acc[x] = lambdaArguments[i]
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
return interpret(input.slice(1), new Context(lambdaScope, context))
|
return interpret(input.slice(1), new Context(lambdaScope, context))
|
||||||
|
@ -1,6 +1 @@
|
|||||||
(
|
(echo (map '(add %1 2) (4 5 6))
|
||||||
|
|
||||||
(echo (map '(add 1 2) (4 5 6))
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user