[erlang-questions] Creating records dynamically

Ulf Wiger <>
Fri Jan 22 10:56:42 CET 2010


Kiran Khaladkar wrote:
> hi all,
> I have record name in a variable how do i create variable of that.
> e.g.  (just a rough example of what the intention is)
> -record(sample, {a,b}).
> put_vals(T) ->
>       V = #T{a =1,b=2}.
> 
> now when i call put_vals like
> put_vals(sample).
> it will fill the record and return the variable
> The values may be passed as list to put vals like [{a,1}, {b,2}]
> 
> there is a way i found but want to know if there is any better way ..
> One can write several put_vals, one each record precisely.

The exprecs parse transform does this automatically for selected
records.

http://forum.trapexit.org/viewtopic.php?p=21790#21790

FWIW, the very latest version can be found as part of

http://svn.ulf.wiger.net/parse_trans/

BR,
Ulf W
-- 
Ulf Wiger
CTO, Erlang Solutions Ltd, formerly Erlang Training & Consulting Ltd
http://www.erlang-solutions.com
---------------------------------------------------

---------------------------------------------------

WE'VE CHANGED NAMES!

Since January 1st 2010 Erlang Training and Consulting Ltd. has become ERLANG SOLUTIONS LTD.

www.erlang-solutions.com



More information about the erlang-questions mailing list