First, why is it not sufficient to provide your router rules as configuration information for a static module?<div>If you do that, then you will have no problems with in-place code update etc. It will also be easier to debug!</div>
<div><br></div><div>Second, if you need to parameterize routing, then you can use parameterized modules. There are some gotchas, such as the "real" arity of functions is actually higher than the "apparent" arity, but they work well for certain cases.</div>
<div><br></div><div>If you really need to go code generation, then I suggest you consider the case of changing rules carefully, and plan out how your system will perform in that case. (Also, HiPE vs interpreter, etc)</div>
<div><br></div><div>Sincerely,</div><div><br></div><div>jw</div><div><br clear="all"><br>--<br>Americans might object: there is no way we would sacrifice our living standards for the benefit of people in the rest of the world. Nevertheless, whether we get there willingly or not, we shall soon have lower consumption rates, because our present rates are unsustainable. <br>
<br>
<br><br><div class="gmail_quote">On Thu, Jun 16, 2011 at 12:48 PM, Dan Kelley <span dir="ltr"><<a href="mailto:djk121@gmail.com">djk121@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br><div>Hi,</div><div><br></div><div>I'm working on a router of sorts.  I'd like to have a config file which specifies how to classify messages, what channels are available, and routing rules based on classifications and channels.</div>

<div><br></div><div>When my application starts, I'd like to transform the configuration into a module (let's call it 'router') so I can do someting like 'router:route(Message)'.  Message will be a record that encapsulates a bunch of things about the message, and the returned value will be the channel to which the message should be delivered.  The Message record is reasonably complicated - the top level thing contains several layers of different records.  I also have a large number of macros that I use to extract different fields/subrecords of a top-level Message.</div>

<div><br></div><div>When I started looking at how to do this, I quickly found erl_scan, erl_parse, and friends.  I can easily create a module on the fly with these, but everything falls apart when I need to get at the Message record and macro definitions.  Despite the access provided to compiler-ish things by erl_scan, erl_parse and friends, it looks like the only way to get at the preprocessor is to use epp on files.  This is a problem because the code I want to dynamically create needs to use the record definitions and macros from the Message header file.</div>

<div><br></div><div>Trying to figure a way around this led me to aleppo, which neatly solved the problem of including the header file, but aleppo doesn't process records.  For a brief and exciting moment, it looked like erl_expand_records might save the day, but it expects forms, and I can't get anything with records through erl_parse:parse_form.</div>

<div><br></div><div>Am I missing an easier way to dynamically create code that references macros and records?</div><div><br></div><div>Thanks,</div><div><br></div><font color="#888888"><div>Dan</div><div><br></div><div><br>
</div>
</font><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>