[erlang-questions] Thinking in Erlang

Robert Virding <>
Thu Apr 29 21:42:23 CEST 2010


On 29 April 2010 18:10, David N Murray <> wrote:
> On Apr 29, é»^Cè^@^@è³¢ (Yau-Hsien Huang) scribed:
>
>> On Wed, Apr 28, 2010 at 10:29 AM, David N Murray <>wrote:
>>
>> {#Fun<test.0.44084711>,[c]}
>> 15>
>>
>> Right?
>>
>
> No, the lisp returns the queue (list).
>
> * (defparameter q (make-fqueue 3))
> Q
> * (funcall q 1)
> (1)
> * (funcall q 2)
> (2 1)
> * (funcall q 3)
> (3 2 1)
> * (funcall q 4)
> (4 3 2)
> *

Yes it returns the queue but it also destructively modifies a local
variable inside the lambda so you can reuse the lambda, without having
to return a new one each go. This you must do in Erlang so you must
return a new fun each time as well.

Robert


More information about the erlang-questions mailing list