[erlang-questions] Record metadata

89 views
Skip to first unread message

dmitry kolesnikov

unread,
Mar 27, 2012, 2:58:56 AM3/27/12
to erlang-questions Questions
Hello,

Let say I do have a record definition:
-record(my, {
a :: atom(),
b :: binary()
}).

Are there any possibility to extract a metadata of record elements
during run-time? E.g call_some_magic_fun that says R#my.a is atom,
R#my.b is binary...

Thanks for any advice!

Best Regards,
Dmitry >-|-|-*>
_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Tim Watson

unread,
Mar 27, 2012, 6:49:56 AM3/27/12
to dmitry kolesnikov, erlang-questions Questions
You'd need the abstract code available and then you can call
dialyzer_utils:get_record_and_type_info/1 which returns a dict
containing the type information. You can then pass this dict to
various functions in the erl_types module to get back information
about type specs.

If you don't want to rely on dialyzer at runtime, you'll need to
copy-paste the code from dialyzer_utils AFAICT. Also the erl_types
module is part of hipe.

Zabrane Mickael

unread,
Aug 14, 2012, 9:04:14 PM8/14/12
to Erlang Questions
Hi guys,

We want to provide a simple API to one of our customers not very familiar with Erlang.
This API involves records manipulations (set/get operations) and you know what I mean.

Before re-writing the wheel, I'd like to know is someone already used "recbird" before:

Any use case? Is it stable? Better alternatives?
Feedbacks welcome!

Regards,
Zabrane


Loïc Hoguin

unread,
Aug 14, 2012, 9:10:54 PM8/14/12
to Zabrane Mickael, Erlang Questions
Val = element(#myrec.fieldname, Rec).
Rec2 = setelement(#myrec.fieldname, Rec, NewVal).

Or something approximating that.
> _______________________________________________
> erlang-questions mailing list
> erlang-q...@erlang.org
> http://erlang.org/mailman/listinfo/erlang-questions
>


--
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu

Michael Truog

unread,
Aug 14, 2012, 9:20:24 PM8/14/12
to Zabrane Mickael, Erlang Questions
It may seem a bit silly, but you could wrap element and setelement in macros that relate to the record name with short get/set names. That would probably make it simpler for those that are addicted to get/set.

Juan Jose Comellas

unread,
Aug 14, 2012, 10:08:03 PM8/14/12
to Zabrane Mickael, Erlang Questions
We developed a similar parse transform that you can find here:


It's very simple to use. The explanation is at the beginning of the file. There's also Ulf Wiger's exprecs module from his parse_trans application:


Hope it helps,

Juanjo


Zabrane Mickael

unread,
Aug 15, 2012, 5:00:59 AM8/15/12
to Juan Jose Comellas, Loïc Hoguin, Michael Truog, Erlang Questions
Thanks for your feedbacks guys.

Regards,
Zabrane

Michael Uvarov

unread,
Aug 15, 2012, 5:34:16 AM8/15/12
to Zabrane Mickael, Erlang Questions
Something like this (but for multiple fields) is used here:
https://github.com/freeakk/rum#example-2

Zabrane Mickael

unread,
Aug 15, 2012, 9:49:09 AM8/15/12
to Juan Jose Comellas, Erlang Questions
Hi Juan,

What's the current emob's license (GPL, BSD...)?

Regards,
Zabrane

On Aug 15, 2012, at 4:08 AM, Juan Jose Comellas wrote:

Zabrane Mickael

unread,
Aug 15, 2012, 9:51:04 AM8/15/12
to Juan Jose Comellas, Erlang Questions
Sorry, just found it inside the code: New BSD, right?

Regards,
Zabrane

Mahesh Paolini-Subramanya

unread,
Aug 15, 2012, 10:08:57 AM8/15/12
to Zabrane Mickael, Erlang Questions
yup...

Cheers
That Tall Bald Indian Guy...
Blog   |   Twitter   |   Google+

Reply all
Reply to author
Forward
0 new messages