Skip to content

@masak /evaluate.p6 secret
Last active

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple evaluator in Perl 6
multi ev(Pair ( :$key where 'number', :value($n) )) { $n }
multi ev(Pair ( :$key where 'add', :$value [$l, $r] )) { ev($l) + ev($r) }
multi ev(Pair ( :$key where 'multiply', :$value [$l, $r] )) { ev($l) * ev($r) }
multi ev(Pair ( :$key where 'variable', :value($name) )) { %*env{$name} }
my %*env = a => 3, b => 4, c => 5;
my $tree = :add[:variable<a>, :multiply[:number(2), :variable<b>]];
say ev($tree);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.