[erlang-questions] Dynamically access record fields

ok@REDACTED ok@REDACTED
Mon Feb 11 01:01:16 CET 2013


> Hmm, upon reading more, it seems like all record functionality is
> implemented in the compiler pass.

That is what the manual says.
>
> It seems like the ability to address particular variable named locations
> in
> tuples would be desirable.

Why?

Suppose I want to tell a function "I want you to work
on the 'david' field of an 'icke' record."

If the -record(icke, {...,david...}) declaration is in
scope, I can pass in #icke.david .

If the -record declaration is NOT in scope, I have no
right to expect there to *be* a 'david' field or, if
there is one, for it to mean anything I might imagine
it to mean.

For that matter, if the -record declaration is in
scope, I can pass a *function*
    fun (#icke{david = X}) -> X end
or  fun (Icke, New_X) -> Icke#icke{david = New_X} end
to say what I want.





More information about the erlang-questions mailing list