[erlang-questions] Versioned variable names

Peter Sabaini peter@REDACTED
Wed Jun 10 15:41:28 CEST 2009


On Tue, 2009-06-09 at 18:22 +0200, Mikael Pettersson wrote:
> Attila Rajmund Nohl writes:
>  > Hello!

 -- snip --

> 
> In Erlang you can't do this, so you're stuck with:
> - numbered variables (ugly but often reasonably practical)
> - function composition like f(x) -> a(b(c(x))), but that
>   quickly gets unreadable

How do you deal with tagged return values? 

Erlang/OTP has this convention of passing results back with an atom tag,
like {ok, Value}, which makes function composition a bit impractical
since often a called function doesn't expect the tag.

I've settled with numbered variables personally...

peter.

> - using a separate function for each stage and tailcall
>   between the stages:
> 	  f() -> g(init()).
> 	  g(X) -> h(update(X)).
> 	  h(X) ->
> 	    NewX = if ... -> update2(X); true -> X end,
> 	    i(NewX).
> 	  i(X) ->
>   this doesn't entirely eliminate the variable naming problem,
>   but it does limit it to say two versions per function body,
>   which is manageable (I use this approach quite a lot in the
>   HiPE compiler backends when translating generic intermediate
>   code to architecture specific code)
> - foldl (as another poster suggested), which is essentially
>   equivalent to function composition or using tailcalls between
>   per-stage functions, except it's expressed in different syntax
> 
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090610/7aa6da62/attachment.bin>


More information about the erlang-questions mailing list