やさしい Lisp の作り方 by Java and by C#を参考に書いてみる。
sub fun {
my ($self, $arguments) = @_;
my $arg1 = $self->eval->eval($arguments->cdr)->car;
my $sym = $arguments->car;
$sym->value($arg1);
$self->env->put($sym,$sym->name);
return $arg1;
}
束縛するものがリストだと、まだうまくいかない。
Moosp> (setq a 5)
5
Moosp> (setq b 2)
2
Moosp> (+ a b)
7
Moosp> (setq c (+ 1 2))
Attribute (value) does not pass the type constraint because: Validation
failed for 'Moosp::Sexp' failed with value Moosp::List=HASH(0xa2a110) at lib/Moosp/Function/Setq.pm line 22
Moosp::Function::Setq::fun('Moosp::Function::Setq=HASH(0xa208a0)',
'Moosp::List=HASH(0xa29a80)') called at lib/Moosp/Eval.pm line 93
Moosp::Eval::eval('Moosp::Eval=HASH(0xa1dcc0)',
'Moosp::List=HASH(0xa29fa0)') called at lib/Moosp.pm line 67
Moosp::run('Moosp=HASH(0x804320)') called at moosp.pl line 7