Is there a way to use records directly in erl? No matter what I try, it always says it canno find the record. I am trying to do mnesia transactions and I cannot go too far without my records. Any help is greatly appreciated - thank you!
+11
A:
Yes, use help() and find these commands in the shell.
rd(R,D) -- define a record
rf() -- remove all record information
rf(R) -- remove record information about R
rl() -- display all record information
rl(R) -- display record information about R
rp(Term) -- display Term using the shell's record information
rr(File) -- read record information from File (wildcards allowed)
rr(F,R) -- read selected record information from file(s)
rr(F,R,O) -- read selected record information with options
These are a clever hack in the shell, they allow you to load record definitions used in modules when they were compiled. Use the rr command to load it from your module.
Remember that these are only available for the interactive shell to use.
Christian
2009-09-06 17:45:52
A small note to add: Records don't really exist... they are just tagged tuples. E.g. say that you define -record(state, { sessions }). then when ever you use #state{ session = N } it will actually be the tuple {state, N}. likewise, if you only type #state{} then this will be {state, undefined}. Knowing this you can easily "fake" records for example when working with mnesia in the shell. Good luck.
Mazen Harake
2009-09-11 11:37:23
+3
A:
How do you mean? In the shell, then it is as Christian wrote. If you mean in a module then you still have to define records before you can use them. See the erlang docs, online at http://erlang.org/doc/, for a description on how to do this. They are only a compile time construction, so they don't exist as such.
rvirding
2009-09-07 00:03:13