News for hackers. Stuff that matters.
Re:Erlang/OTP 17.0 has been released by talklittle on Wednesday April 09, 2014 @12:13PM (#7560237)
Reference manual for Maps: http://www.erlang.org/doc/reference_manual/maps.html

Manpage for Maps: http://www.erlang.org/doc/man/maps.html

Older documentation for Maps (EEP): http://www.erlang.org/eeps/eep-0043.html

Important note found on the reference manual page:

Maps are considered experimental during OTP 17 and may be subject to change.

The documentation below describes it being possible to use arbitrary expressions or variables as keys, this is NOT implemented in the current version of Erlang/OTP.

Exceptions returns badarg instead of badmap, this will change in the future releases.

Re:Erlang/OTP 17.0 has been released by bosky101 on Wednesday April 09, 2014 @02:02PM (#7561021)
I especially like this property of maps that cannot be done in either records or JSON ( had it been supported as a primitive)

    M4 = #{{"w", 1} => f()}.  % compound key associated with an evaluated expression
And of course self-referencing is a welcome addition (especially on the terminal)

    Fac = fun(0) -> 1; (N) -> N*Fac(N-1) end
~B
Re:Erlang/OTP 17.0 has been released by mononcqc on Wednesday April 09, 2014 @02:22PM (#7561215)
The syntax would actually be:

    fun Fac(0) -> 1; Fac(N) -> N*Fac(N-1) end
Note that the name `Fac` is not visible outside of the fun's scope, and to use the same variable name outside, you still need to bind it:

    F = fun Fac(0) -> 1; Fac(N) -> N*Fac(N-1) end
Re:Erlang/OTP 17.0 has been released by eurleif on Wednesday April 09, 2014 @02:32PM (#7561299)
Looks like this is pretty much identical to JavaScript?
Re:Erlang/OTP 17.0 has been released by mononcqc on Wednesday April 09, 2014 @02:58PM (#7561512)
Pretty much. Javascript has the same scoping rules for functions used as expressions:

    var f = function fac(n) { if (n==0) { return 1; } else {return fac(n-1)*n; } };
    console.log(f(3));
    console.log(fac(3));
This will log '6' and error out on the last one (fac is undefined). This is the same scoping Erlang uses for anonymous function names as far as I can tell, with one difference: Erlang's function name is a variable that can be used as such internally. In Javascript, the function name doesn't refer to a variable per se:

    var f = function fac() { console.log(fac) };
    console.log(f);
    f();
Which will log 'fac()' and 'undefined'. In Erlang:

    1> F = fun Fac() -> Fac end.
    #Fun<erl_eval.44.71889879>
    2> F().
    #Fun<erl_eval.44.71889879>
 
Both instances (F and Fac within the right scope) return the same anonymous function.
Re:Erlang/OTP 17.0 has been released by eurleif on Wednesday April 09, 2014 @04:48PM (#7562261)
Are you sure you didn't make a mistake, and confuse the undefined that f() returned with an undefined output from the console.log(fac)? It looks to me like the function is a perfectly normal variable.

    var f = function foo() { console.log('Me:', foo); }
    f();
    Me: function foo() { console.log('Me:', foo); }
    undefined
Re:Erlang/OTP 17.0 has been released by mononcqc on Wednesday April 09, 2014 @05:26PM (#7562556)
You're right, I've been fooled by Firebug merging in multiple identical output lines together and missed the (2) it had put on the right hand side of the screen. That makes a lot more sense.