[erlang-questions] Simple Erlang Recommendation (last returned value)

doug mansell doug.mansell@REDACTED
Fri Jul 25 18:31:12 CEST 2008

On Fri, Jul 25, 2008 at 6:14 PM, Berlin Brown <berlin.brown@REDACTED> wrote:
> When I am coding, I end up forgetting to define Q1, Q2
> NewQ = queue:new(),
> queue:add(joe, NewQ),
> queue:add(mike, NewQ), ...
> Logic error!!!
> I wish there were something like this to get the result of the last
> call
> queue:new(),
> queue:add(joe,  erlang:last_value()),
> queue:add(mike, erlang:last_value())), ...

What's the order of evaluation of function call arguments?  if it's
left to right... last_value in these calls to queue:add/2 would be
'joe' and 'mike' - not what you expected...

You don't have to bind everything to a variable, you could write like
this: queue:add(mike, queue:add(joe, queue:new()))

You'll get the hang of it.  :)

More information about the erlang-questions mailing list