Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 3f48554d58
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 37 lines (28 sloc) 1.432 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#!/usr/bin/perl -w
use Test::More tests => 5;
use LCore::Level2;
use LCore::Parameter;
use Data::Dumper;$Data::Dumper::Deparse=1;
use LCore::Procedure;
use Test::Exception;
my $l = LCore->new( env => LCore::Level2->new );
$l->env->set_symbol('*' => LCore::Primitive->new
                        ( body => sub {
                              return $_[0] * $_[1];
                          },
                          parameters => [ LCore::Parameter->new({ name => 'a', type => 'Num' }),
                                          LCore::Parameter->new({ name => 'b', type => 'Num' }) ],
                          return_type => 'Num',
                      ));

my $proc = LCore::Procedure->new( { env => $l->env,
                                    body => $l->analyze_it(q{(* n n)}),
                                    parameters => [LCore::Parameter->new({ name => 'n', type => 'Num' } )] } );

is($proc->return_type, 'Num', "return type derived");

$l->env->set_symbol('square' => $proc);

my $proc2 = LCore::Procedure->new( { env => $l->env,
                                     body => $l->analyze_it(q{(map square (list 5 (* 1 6) 7))}),
                                     parameters => [] } );

like $proc2->return_type, qr/^ArrayRef/;

is_deeply($proc2->apply(), [25, 36, 49]);

is_deeply($l->analyze_it(q{(map square 5 6 7))})->($l->env), [25, 36, 49]);

is_deeply($l->analyze_it(q{(map square 5))})->($l->env), [25]);
Something went wrong with that request. Please try again.