At the moment there is support for lambdas and closures in inception so this works:
(defun makeAdder (n)
(lambda (x)
(+ x n)))
(defun main ()
(let ((ten (makeAdder 10)))
(println (ten 15))
(println (ten 25))
))
However the captured values are essentially read-only, so this example fails:
(defun counter ()
(let ((n 0))
(lambda ()
(set! n (+ n 1))
n)))
(defun main()
(let ((f (counter)))
(println (f))
(println (f))))
I think this should be an easy fix, since we're passing around env everywhere. While we cannot have a closure modify a single value in the parent scope we do have the ability to change things in-place for lists, via nth! and our closure is itself a list:
(defun closure (params body env)
(list "closure" params body env))
When the closure runs it should mutate its own env, and that would be enough?
At the moment there is support for lambdas and closures in
inceptionso this works:However the captured values are essentially read-only, so this example fails:
I think this should be an easy fix, since we're passing around
enveverywhere. While we cannot have a closure modify a single value in the parent scope we do have the ability to change things in-place for lists, vianth!and our closure is itself a list:(defun closure (params body env)
(list "closure" params body env))
When the closure runs it should mutate its own env, and that would be enough?