Add defun macro

This commit is contained in:
madmaurice 2021-04-02 01:07:17 +02:00
parent 7e7defbb9a
commit bbf6ae9cbd

View file

@ -331,6 +331,23 @@ sub macro_progn {
} }
$macros{progn} = \&macro_progn; $macros{progn} = \&macro_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} = \&macro_defun;
sub compile { sub compile {
my ($term) = @_; my ($term) = @_;
my @tokens = tokenize($term); my @tokens = tokenize($term);