Skip to content

Comment on A Week with Elixir

Comments

Joe's points are really good. This drives me crazy in Elixir:

iex(1)> f = fn x -> x + 1 end

#Function<erl_eval.6.82930912>

iex(2)> f()

(UndefinedFunctionError) undefined function(stack trace trimmed...)

iex(2)> f.(1)

2

https://groups.google.com/forum/?fromgroups#!topic/elixir-la...

This was José Valim's rationale on the mailing list. Once you understand what's involved, f.() begins to look like a pretty good compromise.

That kind of variable shadowing is a smell. The compiler should warn about it, and/or re-bind the local method as expected (possibly shooting programmer in the foot, but hey... that's why it's a smell, Don't Do It). Forcing an inconsistent syntax to handle one corner case seems like another smell in itself.

Personally I would rather leave the syntax disambiguation to the programmer when relevant, rather than enforcing a single, awkward-looking syntax for all cases.

Its true, but Joe is also correct that this is going to be something people complain about for decades.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.