Ditch Multi-Expression Bodies

11 views
Skip to first unread message

rvirding

unread,
Jun 24, 2011, 8:50:32 PM6/24/11
to Lisp Flavoured Erlang
This is a suggestion that has come up in the LFE wiki on github. It is
included here "as is" including my comment:

Ditch Multi-Expression Bodies

The core forms tend to take multiple expressions as the “body”,
evaluated sequentially but only the result of the last one being
returned. This approach seems to stem from other Lisp implementations,
and has two problems:

1. It relies on side effects. Expressions preceding the last one are
only useful if they have side effects, and expressions that exist only
for their side effects are very rare in well-written Erlang. At a
minimum, the return value must be pattern matched against ‘ok’. This
is clearly seen in LFE code, where side effects are usually carried
out in a let* rather than a progn.

2. It complicates syntax, necessitating separate styles for pattern
matches and non-pattern matches. This steepens the learning curve and
makes code look more intimidating – for no particular benefit, due to
1.

The latter can be fixed with new macros (I’m putting together a
Clojure-like defn and fn as I write this) but the first is a subtle
property of well-written Erlang code, and much harder to encourage.

COMMENT: I think this is an interesting idea but it entails changes in
many places. There are a number of core forms which use this: lambda,
match-lambda, case, receive, try and progn :-) , and also many of the
pre-defined macros like cond and lc. Many macros generate such bodies
without actually knowing anything about them. You would probably need
to keep progn (and eval-when-compile) for some cases. I would have
nothing against such a change but users accept it?
Reply all
Reply to author
Forward
0 new messages