Alex Rivera | Logout

Erlang and run-time record limitations

Asked 2009-01-15T15:33:48.733
9

I'm developing an Erlang system and having reoccurring problems with the fact that records are compile-time pre-processor macros (almost), and that they cant be manipulated at runtime... basically, I'm working with a property pattern, where properties are added at run-time to objects on the front-end (AS3). Ideally, I would reflect this with a list on the Erlang side, since its a fundamental data type, but then using records in QCL [to query ETS tables] would not be possible since to use them I have to specifically say which record property I want to query over... I have at least 15 columns in the larges table, so listing them all in one huge switch statement (case X of) is just plain ugly.

does anyone have any ideas how to elegantly solve this? maybe some built-in functions for creating tuples with appropriate signatures for use in pattern matching (for QLC)?

thanks

Edit
Report

1 Answer

1

I solve this problem (in development) by use the parse transform tools to read the .hrl files and generate helper functions.

I wrote a tutorial on it at Trap Exit.

We use it all the time to generate match specs. The beauty is that you don't need to know anything about the current state of the record at development time.

However once you are in production things change! If your record is the basis of a table (as opposed to the definition of a field in a table) then changing an underlying record is more difficult (to put it mildly!).

answered 2009-02-27T00:42:02.317

Your Answer