[erlang-questions] Thinking in Erlang

Richard O'Keefe ok@REDACTED
Thu Apr 29 00:55:18 CEST 2010


On Apr 29, 2010, at 12:58 AM, David N Murray wrote:
> It looks like either way I'm passing around additional data (either  
> the
> queue or the pid) in Erlang.

If you wanted to use a mutable queue in Lisp,
you would have to pass around *SOME* kind of reference to it.
In the Erlang world, all that changes is that the reference
is a process ID instead of the address of a mutable object.

Let me show another example, assuming my previous code:

	newt(N) ->
	    Queue = new(N),
	    fun ({push,X}) -> push(Queue, X)
               ; (pop)      -> pop(Queue, X)
               ; (quit)     -> quit(Queue)
             end.

	> F = newt(10).
	> F({push,1}).
	> F({push,2}).
	> F(pop).
==>	1
	> F(pop).
==>	2
	> F(quit).

Whether you return an "object identifier" which can then be
passed to various functions, or you return a "handler function"
which can then be passed "messages", is really quite unimportant.
You can take EITHER approach in Lisp.
You can take EITHER approach in Erlang.
You have to pass ONE thing around, either way, with either language.
You don't "pass" anything "additional".



>
> Thanks,
> Dave
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>



More information about the erlang-questions mailing list