Add defun macro
This commit is contained in:
parent
7e7defbb9a
commit
bbf6ae9cbd
1 changed files with 17 additions and 0 deletions
|
@ -331,6 +331,23 @@ sub macro_progn {
|
||||||
}
|
}
|
||||||
$macros{progn} = \¯o_progn;
|
$macros{progn} = \¯o_progn;
|
||||||
|
|
||||||
|
sub macro_defun {
|
||||||
|
my $ts = shift;
|
||||||
|
|
||||||
|
my $ident = shift @$ts;
|
||||||
|
die "Expected identifier in defun" unless $ident->{type} == IDENT;
|
||||||
|
|
||||||
|
my $body = macro_lambda($ts);
|
||||||
|
|
||||||
|
return sub {
|
||||||
|
my $ctx = shift;
|
||||||
|
my $fn = $body->($ctx);
|
||||||
|
$ctx->{$ident->{value}} = $fn;
|
||||||
|
return $fn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$macros{defun} = \¯o_defun;
|
||||||
|
|
||||||
sub compile {
|
sub compile {
|
||||||
my ($term) = @_;
|
my ($term) = @_;
|
||||||
my @tokens = tokenize($term);
|
my @tokens = tokenize($term);
|
||||||
|
|
Loading…
Reference in a new issue