fix lambda shorthand, update array example
This commit is contained in:
parent
4d437eaac1
commit
55bff65635
@ -69,10 +69,10 @@ function Lisp (input, lib) {
|
||||
__fn: function (input, context) {
|
||||
return async function () {
|
||||
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.value[0] === '%'
|
||||
).map(x => x.value).sort()
|
||||
).map(x => x.value).sort())]
|
||||
const lambdaScope = keys.reduce(function (acc, x, i) {
|
||||
acc[x] = lambdaArguments[i]
|
||||
return acc
|
||||
|
@ -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 (rest (1 2 3)))
|
||||
|
||||
(echo
|
||||
(filter
|
||||
(lambda (a) (eq 0 (mod a 2)))
|
||||
'(eq 0 (mod %1 2))
|
||||
(1 2 3 4 5))
|
||||
)
|
||||
|
||||
(clear)
|
||||
(map (lambda (a)
|
||||
(stroke (rect (mul a 30) 20 50 50)
|
||||
1 "red"))
|
||||
(map
|
||||
'(stroke (rect (mul a 30) 20 50 50)
|
||||
1 "red")
|
||||
(range 0 20 5))
|
||||
|
||||
(map (lambda (a)
|
||||
(stroke
|
||||
(map
|
||||
'(stroke
|
||||
(rect
|
||||
(mul a 10)
|
||||
(add 50 (mul (sin a) 40))
|
||||
a
|
||||
(add 20 (mul (cos a) 50))) 1 "red"))
|
||||
(range 0 200 5))
|
||||
(mul %1 10)
|
||||
(add 50 (mul (sin %1) 40))
|
||||
%1
|
||||
(add 20 (mul (cos %1) 50))) 1 "red")
|
||||
(range 0 200 5))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user