4 ms·
Ask HN: Is there a life out of closures?
- martyalain 4y agoClosures are not a required functionality in a language. I'm experimenting a homemade language, lambdatalk, http://lambdaway.free.fr/lambdawalks/ http://lambdaway.free.fr/lambdawalks/ , in which lambdas don't create closures but accept partial application. For instance this is how the set [cons, car, cdr] could be defined in SCHEME: (def cons (lambda (x y) (lambda (m) (m x y)))) (def car (lambda (z) (z (lambda (x y) x)))) (def cdr (lambda (z) (z (lambda (x y) y)))) (car (cons 12 34)) -> 12 (cdr (cons 12 34)) -> 34 and in lambdatalk: {def cons {lambda {:x :y :m} {:m :x :y}}} {def car {lambda {:z} {:z {lambda {:x :y} :x}}}} {def cdr {lambda {:z} {:z {lambda {:x :y} :y}}}} {car {cons 12 34}} -> 12 {cdr {cons 12 34}} -> 34 In SCHEME the outer lambda saves x and y in a closure the inner lambda can access given m. In lambdatalk the lambda saves :x and :y and returns a new lambda waiting for :m. So, even if closure (and lexical scope) are usefull functionalities, there are not a necessity. Without any free variables, out of any lexical scope, functions are true black boxes without any side effect, in a total independance, following a true functional paradigm. Don't you think so?