fix lambda shorthand, update array example

This commit is contained in:
Quentin Leonetti 2019-07-20 20:49:25 +02:00
parent 4d437eaac1
commit 55bff65635
2 changed files with 15 additions and 14 deletions

View File

@ -69,10 +69,10 @@ 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 keys = input.slice(2).filter(i => const keys = [...new Set(input.slice(2).flat(100).filter(i =>
i.type === TYPES.identifier && i.type === TYPES.identifier &&
i.value[0] === '%' i.value[0] === '%'
).map(x => x.value).sort() ).map(x => x.value).sort())]
const lambdaScope = keys.reduce(function (acc, x, i) { const lambdaScope = keys.reduce(function (acc, x, i) {
acc[x] = lambdaArguments[i] acc[x] = lambdaArguments[i]
return acc return acc

View File

@ -1,25 +1,26 @@
(echo (map (lambda (a) (add a 1)) (1 2 3))) (echo (map '(add %1 1) (1 2 3)))
(echo (first (1 2 3))) (echo (first (1 2 3)))
(echo (rest (1 2 3))) (echo (rest (1 2 3)))
(echo (echo
(filter (filter
(lambda (a) (eq 0 (mod a 2))) '(eq 0 (mod %1 2))
(1 2 3 4 5)) (1 2 3 4 5))
) )
(clear) (clear)
(map (lambda (a) (map
(stroke (rect (mul a 30) 20 50 50) '(stroke (rect (mul a 30) 20 50 50)
1 "red")) 1 "red")
(range 0 20 5)) (range 0 20 5))
(map (lambda (a) (map
(stroke '(stroke
(rect (rect
(mul a 10) (mul %1 10)
(add 50 (mul (sin a) 40)) (add 50 (mul (sin %1) 40))
a %1
(add 20 (mul (cos a) 50))) 1 "red")) (add 20 (mul (cos %1) 50))) 1 "red")
(range 0 200 5)) (range 0 200 5))