forked from alex-eg/sex
remove closures, keep lambdas
A closure was a code pointer beside an inline environment: capture records, per-signature structs, conversion thunks and call helpers. It is gone; a lambda still lifts to an ordinary function and a (fn ...) value is still a bare code pointer. The capture budget, the environment union and the closure glyph go with it. The implementation is kept at tag 0.0.1.
This commit is contained in:
@@ -3,12 +3,6 @@
|
||||
(fn sum ((a int) (b int)) int
|
||||
(return (+ a b)))
|
||||
|
||||
;;; A lambda captures nothing and is a bare function pointer; a closure
|
||||
;;; captures and is a value carrying its own environment
|
||||
(fn make-adder ((a int)) (closure ((int)) int)
|
||||
(return (closure ((b int)) int (a)
|
||||
(return (+ a b)))))
|
||||
|
||||
(pub fn main () int
|
||||
(var a int 10)
|
||||
(var b int 20)
|
||||
@@ -41,8 +35,4 @@
|
||||
(return (+ 60 a))))
|
||||
(return (+ 600 (l-2 a)))))
|
||||
(printf "Calling nested lambdas: %d\n" (l-1 6))
|
||||
|
||||
(var add-10 (closure ((int)) int) (make-adder 10))
|
||||
(var add-20 (closure ((int)) int) (make-adder 20))
|
||||
(printf "Calling closures: %d %d\n" (add-10 24) (add-20 24))
|
||||
(return 0))
|
||||
|
||||
Reference in New Issue
Block a user