[erlang-questions] Variable bindings

ok@REDACTED ok@REDACTED
Sun Jan 27 09:31:27 CET 2013


> Does there exist any particular function which would give me all variable
> bindings (including their values) at that point.

Maybe someone has already asked this,
but why do you want this?

There _are_ programming languages in which this degree
of runtime introspection is possible: Interlisp and S
spring to mind.  But that comes at a fairly heavy cost,
and Erlang does not support it.
This kind of thing is more commonly found in debuggers.

Is it a debugging task you want this for?

The parse-transform approach that's been mentioned does
this at compile time, not at run time.  Now consider

   f(X) -> Y = g(X), if Y >  0 -> {{A}} h(Y)
                      ; Y =< 0 -> {{B}} r(X)
                     end.

At point {{A}}, an Erlang compiler would normally say that
Y exists but X doesn't any more.  At point {{B}}, we'd
normally say that X exists but Y doesn't any more: a
variable "exists" from its binding time to its last use.
(If you kept variables around any longer than that, you'd
be hobbling the garbage collector.)

So I think we might need a clearer idea of what variables
_you_ expect to exist at a point and whether retaining
data longer than necessary is acceptable to do.





More information about the erlang-questions mailing list