List constructor is AST node too.<br><br>1> erl_parse:parse(element(2, erl_scan:string("strings() -> [\"foo\", \"bar\"]."))).<br>{ok,{function,1,strings,0,<br>              [{clause,1,[],[],<br>
                       [{cons,1,<br>                              {string,1,"foo"},<br>                              {cons,1,{string,1,"bar"},{nil,1}}}]}]}}<br><br>Anyway, ets is better solution for you, it will be faster for most of your tasks. It is easier and you don't need learn AST :-)<br>
<br><div class="gmail_quote">2008/6/8 Jacob Perkins <<a href="mailto:japerk@gmail.com">japerk@gmail.com</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
So I decided to try generating the AST, and got most of the way there. I don't want to use ets because I don't want to have a process dependency.<div><br></div><div>I was able to use compile:forms to generate a module and function, but my function clause isn't correct. The function and clause forms I can get to compile are:</div>

<div><br></div><div>{function, LINE, strings, 0,</div><div>    [{clause, LINE, [], [],</div><div>        [{string, LINE, "foo"}, {string, LINE, "bar"}]}]}</div><div><br></div><div>But the above form appears to generate</div>

<div><br></div><div>strings() -> "foo", "bar".</div><div><br></div><div>when what I really want is</div><div><br></div><div>strings() -> ["foo", "bar"].</div><div><br></div><div>

It's probably a simple fix in the forms, but the obvious change of enclosing the string literals in another list causes a compile error:</div><div><br></div><div><div>{function, LINE, strings, 0,</div><div>    [{clause, LINE, [], [],</div>

<div>        [[{string, LINE, "foo"}, {string, LINE, "bar"}]]}]}</div></div><div><br></div><div>Any help?</div><div>Thanks,</div><div>Jacob</div><div><div></div><div class="Wj3C7c"><div><br></div><div>
<div class="gmail_quote">On Sun, Jun 8, 2008 at 9:45 AM, Howard Yeh <<a href="mailto:hayeah@gmail.com" target="_blank">hayeah@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">see ERTS manual chapter 4 to see the abstract format.<br>
<br>
<a href="http://www.erlang.org/doc/apps/erts/part_frame.html" target="_blank">http://www.erlang.org/doc/apps/erts/part_frame.html</a><br>
<br>
there's also Core Erlang. But I am not sure where it's documented.<br>
<div><div></div><div><br>
<br>
On 6/8/08, Robert Virding <<a href="mailto:rvirding@gmail.com" target="_blank">rvirding@gmail.com</a>> wrote:<br>
> There are basically two ways of doing this:<br>
><br>
> - From you list of files generate a file, grammar.erl, containing the module<br>
> grammar with functions adjectives/0 and nouns/0. You then compile with<br>
> compile:file and load with code:load.<br>
><br>
> - You can generate the code as AST in memory and then compile with<br>
> compile:forms. This is a bit tricky the first time, but easy once you get<br>
> the hang of it.<br>
><br>
> - As someone else mentioned save them in a database on disk.<br>
><br>
> Robert<br>
><br>
> 2008/6/8 Jacob Perkins <<a href="mailto:japerk@gmail.com" target="_blank">japerk@gmail.com</a>>:<br>
> > Hi all,<br>
> ><br>
> ><br>
> ><br>
> > I need some help understanding how to dynamically compile/generate an<br>
> erlang module. I've seen other projects do this kind of thing, such as<br>
> erlydtl, but my needs are much simpler.<br>
> ><br>
> ><br>
> > I have a few files that are basically lists of words. What I want to do is<br>
> generate a module whose functions will return each list of words. So if I<br>
> have two files named "adjectives" and "nouns", then the generated module<br>
> (let's call it 'grammar') should have two functions, adjectives() and<br>
> nouns(), that return their respective list of words.<br>
> ><br>
> ><br>
> > How can I do this?<br>
> ><br>
> ><br>
> > Thanks,<br>
> > Jacob<br>
> > _______________________________________________<br>
> > erlang-questions mailing list<br>
> > <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
> > <a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
> ><br>
><br>
><br>
> _______________________________________________<br>
>  erlang-questions mailing list<br>
>  <a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
>  <a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
<br>
<br>
</div></div><font color="#888888">--<br>
<a href="http://hayeah.wordpress.com" target="_blank">hayeah.wordpress.com</a><br>
   --metacircular thinking<br>
</font></blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br></blockquote></div><br><br clear="all"><br>-- <br>--Hynek (Pichi) Vychodil