[erlang-questions] idea: ml9 (sort of) in the erlang shell
Ulf Wiger
ulf@REDACTED
Thu Nov 15 15:04:08 CET 2007
2007/11/13, Ulf Wiger <ulf@REDACTED>:
>
>> Here's a more outlandish idea:
>
> Allow for arbitrary syntax to be inserted in the shell, by
> catching lines starting with '@' (only because this is what
> Joe used in his ML9).
Now for the ultimate display of usefulness:
6> @ type(module).
-module(xXx).
-author('mats cronqvist').
-export([x/1]).
-define(x,x(.
-define(Xx,X.
-define(X,X)
->. ?x?X?Xx.
@
{module,xXx}
(So, we successfully defined, compiled and loaded a module from
the shell, but what does it do? The subtle macros have me confused.
Let's type it in again, with an added option. Luckily, copy/paste is easy
since the prompt isn't repeated for each line.)
7> @ type(module), return(pretty).
-module(xXx).
-author('mats cronqvist').
-export([x/1]).
-define(x,x(.
-define(Xx,X.
-define(X,X)
->. ?x?X?Xx.
@
"-module(xXx).\n-author('mats cronqvist').\n-export([x/1]).\nx(X) ->\n X.\n"
8> io:fwrite("~s~n", [v(7)]).
-module(xXx).
-author('mats cronqvist').
-export([x/1]).
x(X) ->
X.
ok
(Ah, now even I can understand it!)
9> xXx:x(17).
17
For this to work, I had to replace Mats's macro parser with epp,
and used my ram_file_io_server module and a slightly hacked epp
(to be able to hand it a descriptor to an already opened file.)
BR,
Ulf W
More information about the erlang-questions
mailing list