[erlang-questions] Newbie question: function include/1 undefined
Mon Oct 3 12:43:18 CEST 2016
On 10/02, Donald Steven wrote:
>Thanks Richard. I had (alas) come to that conclusion.
>In c (or m4 or the like), I can include blocks of text or code quite
>freely. In this case, primarily as a matter of aesthetics, I wanted
>to off load some repetitive initializations to a file which could be
>included at the appropriate point, with a neat % comment on the side
>to keep my head straight. It's a big, ugly block in an otherwise
>elegant set of funs. I guess I'm stuck with it, as I'm reluctant to
>make things too complicated by running the whole thing through m4
>first before the erlang pre-processor. I do wish it could be done
>though. (Dare I suggest a modest proposal?)
Another approach, although a bit more painful to make work and correlate
with all scope would be to use macros:
-define(CODE_SNIPPET, begin <whatever> end).
YOu can then -include("myheader.hrl"). and just call ?CODE_SNIPPET
Richard O'Keefe's solutions would be cleaner in the long run (and I
definitely recommend running with that option), but this could be an
immediate workaround for what you had in mind.
More information about the erlang-questions