Re: Metalanguages in environments where code is data.

Peter da Silva (peter@nmti.com)
Thu, 10 Nov 1994 18:58:48 GMT

In article <1994Nov9.194316.14800@netlabs.com>,
Larry Wall <lwall@netlabs.com> wrote:
> You can do it almost exactly the same in Perl, except there's no
> need to "eval" the final argument to "rule".

> use Make;

> $CFLAGS = "-O -g";
> $OBJS = "main.o frob.o";
> $LIBS = "-lreadline";

> rule "frob", $OBJS, sub {
> system "$CC $CFLAGS $OBJS -o frob $LIBS";
> };

> make;

OK, point to perl. How would you manipulate something like:

event_wait {
{control $door close} {
signal $alarm "Door $door closed"
}
{control $door open} {
signal $alarm "Door $door opened"
}
}

Easy enough, but now you want to add user-defined events to the end of
this structure:

set default_event_list {
{control $door close} {
signal $alarm "Door $door closed"
}
{control $door open} {
signal $alarm "Door $door opened"
}
}
set event_list $default_event_list

Then later

lappend event_list {
{control $door open} {
set last_event [list $door opened]
}
}

event_wait $event_list

Sometimes it's convenient to add stuff at random times, even
algorithmically, within a consistent syntax.

I will readily admit that this example could probably be done other ways,
such as creating a word to build an event table and assembling it by hand.
I'm just curious how Perl would resolve the above example.

> runoff qq{
^^--- could you explain this?

-- 
Peter da Silva                                            `-_-'
Network Management Technology Incorporated                 'U`
1601 Industrial Blvd.     Sugar Land, TX  77478  USA
+1 713 274 5180                       "Hast Du heute schon Deinen Wolf umarmt?"