[erlang-questions] Erlang/OTP R14A has been released

Ulf Wiger ulf.wiger@REDACTED
Thu Jun 17 14:48:47 CEST 2010


Vlad Dumitrescu wrote:
> On Thu, Jun 17, 2010 at 13:05, Ulf Wiger <ulf.wiger@REDACTED> wrote:
>> Hans Bolinder wrote:
>>> Now it is possible to state an integer range as "1 .. 10" (with a
>>> space after '..'). Before R14A the second dot was scanned as a 'dot'
>>> token.
>> So now we could introduce [1 .. 10] as syntactic sugar for
>> lists:seq(1,10)?  :)
> 
> Then it won't take long until someone suggests to allow [3, 7, 8..12,
> 23, 123..155, 88] !

Well, seriously though,

I previously wrote a little parse_transform, ct_expand
(part of http://github.com/esl/parse_trans), that could do
compile-time evaluation of an expression, e.g.

ct_expand:term(lists:seq(1,10))

would be expanded at compile-time to [1,2,3,4,5,6,7,8,9,10].

For this particular example, it is of course of little use, since
it is harder to understand and 9 keystrokes longer, but Paul
Mineiro provided a much better use case in this blog post:
http://dukesoferl.blogspot.com/2009/08/metaprogramming-with-ctexpand.html

As long as a construct like [1,2,3 .. 10,11] would contain only
constant terms, it could be expanded at compile-time. If not,
it should perhaps be treated much like "foo" ++ Suffix, which is
allowed, whereas Prefix ++ "foo" is a legal constructor, but
not a legal pattern.

I think it is perfectly reasonable to disallow that for starters,
until someone provides an implementation that handles it in a
complete and predictable way.

In the case where it is a constant list, the expansion is entirely
straightforward and improves readability significantly. It is
also a pattern used in other languages, and given that it is allowed
in type specs (implying that people are still expected to understand
what it means), it makes sense to allow it also in code.

EEP time? Personally, I don't have the time right now.

BR,
Ulf W
-- 
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
http://www.erlang-solutions.com
---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com



More information about the erlang-questions mailing list