[erlang-questions] Reassigning variables

Richard O'Keefe <>
Thu Mar 19 02:06:42 CET 2009


Just on the subject of multiple returns,
and using a name swiped from a possibly defective memory of VLisp,

	escape(Body) ->
	    Unique = make_ref(),
	    try
		Body(fun (Result) -> throw({escape,Unique,Result}) end)
	    catch
		throw:{escape,Unique,Result} -> Result
	    end.

Use this as

	escape(fun (Return) ->
	   ...
		Return(this)
	   ...
		Return(that)
	   ...
	   or_just_return_as_usual
	end)

As I remarked before, I don't like using exceptions _as_ control
structures, but using them in a hidden way to _implement_
sensible control structures is another thing.

I'm old enough to think of the value that Return is bound to
as a "J-function", rather like the 'jumpout' functions in Pop-2.
These days it may be more useful to describe it as (mimicking)
a single-use continuation.



More information about the erlang-questions mailing list