[erlang-questions] Here's hoping we get frames or structs in 2009!
Kostis Sagonas
kostis@REDACTED
Mon Jan 12 13:59:59 CET 2009
James Hague wrote:
> I've been using Erlang as my primary language for personal projects
> for some years now, though I also use and enjoy Perl, Python, REBOL,
> C++, Lua, and occasionally Forth. Quite often I'm surprised at how
> much easier it is write certain types of code in Erlang...and I'm also
> surprised at how awkward it is to write other types of code in Erlang.
> Sometimes the awkwardness is because I just can't think of a pretty
> way to avoid destructive updates in an algorithm that's inherently
> destructive. But much of the time it's from working around the lack
> of lightweight dictionaries or hashes.
>
> In Perl, I don't think twice about creating hashes:
>
> (width => 1280, height => 1024, colors=655536)
>
> The Python version is similarly clean:
>
> dict(width=1280, height=1024, colors=65536)
>
> In Erlang, I can create a property list:
>
> [{width,1280}, {height,1024}, {colors,65536}]
>
> which isn't bad in itself, but not being able to pattern match on
> these is what hurts.I work around it by manually grabbing properties,
> but the code ends up bulky and contrived. Yeah, we've all discussed
> this for years, so here's hoping there's some movement on this front.
> Syntactically, the version I like the most at the moment is the record
> syntax without a record name:
>
> #{width=1280, height=1024, colors=65536}
Perhaps I am missing the obvious but I fail to see how the presence of
the record name prevents you from doing this today -- especially for
things that have a fixed number of "properties" (e.g. width, height,
colors) as the above.
Kostis
More information about the erlang-questions
mailing list