add lambda shorthand with params

This commit is contained in:
Quentin Leonetti 2019-07-20 20:34:23 +02:00
parent 371615a899
commit 4d437eaac1
2 changed files with 7 additions and 8 deletions

View File

@ -69,8 +69,12 @@ function Lisp (input, lib) {
__fn: function (input, context) {
return async function () {
const lambdaArguments = arguments
const lambdaScope = [].reduce(function (acc, x, i) {
acc[x.value] = lambdaArguments[i]
const keys = input.slice(2).filter(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 interpret(input.slice(1), new Context(lambdaScope, context))

View File

@ -1,6 +1 @@
(
(echo (map '(add 1 2) (4 5 6))
)
(echo (map '(add %1 2) (4 5 6))