Erlang: Why does this fail with a 'badarith' exception?

Viewed 9484

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
3 Answers
Related