Is it possible to implement a closure in Erlang?
For example, how would I translate this snippet from Scheme?
(define (make-adder n)
(lamdba (x) (+ x n)))
I've tried the following, but I'm clearly missing something.
make_adder(n) ->
fun (x) -> x + n end.
Compiling this gives the error
Warning: this expression will fail with a 'badarith' exception
You can't add atoms. Variables start with Capital Letters in erlang. words starting with lower case letters are atoms.
In other words your problem is not related to fun
s at all, you just need to capitalize your variable names.
make_adder(N) ->
fun (X) -> X + N end.
Variables start with Capital Letters in erlang. words starting with lower case letters are atoms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With