[erlang-questions] Can I do var-assignment in a function?

Lev Walkin vlm@REDACTED
Wed Jul 23 14:03:13 CEST 2008


Circular Function wrote:
>   extract(Str) ->
>     A = string:tokens(Str," ").
>     lists:sort(A).
> 
> I could of course do this:
> lists:sort(string:tokens(Str," ")).
> 
> But lets say I want a bigger function that slo includes some deeper 
> function calls, lets say 4-5
> calls deep.
> 
> That's the main thing I dislike about functional programming, it is very 
> expressive but sometimes it is hard afterwards to follow what a function 
> does and it is hard hwen you have to read what is happening from right 
> to the left.
> It is easier to reason about when I can split into several calls.
> 
> I guess it is doable but I can't figure out the syntax.

Use comma.

extract(Str) ->
	A = string:tokens(Str," "),
	lists:sort(A).


That's it.

-- 
vlm



More information about the erlang-questions mailing list