Add more std functions

This commit is contained in:
madmaurice 2021-04-02 01:02:19 +02:00
parent b6eea1138e
commit 72141ffde6

View file

@ -77,17 +77,27 @@ sub tokenize {
} }
my %stdctx = ( my %stdctx = (
'add' => sub { '+' => sub {
my $sum = 0; my $sum = 0;
$sum += $_ foreach (@_); $sum += $_ foreach (@_);
return $sum; return $sum;
}, },
'sub' => sub { '-' => sub {
my $sum = shift; my $sum = shift;
$sum -= $_ foreach (@_); $sum -= $_ foreach (@_);
return $sum; return $sum;
}, },
'print' => sub { '*' => sub {
my $prod = 1;
$prod *= $_ foreach(@_);
return $prod;
},
'/' => sub {
my $quot = shift;
$quot /= $_ foreach(@_);
return $quot;
},
'write-line' => sub {
my $e = shift; my $e = shift;
print "$e\n"; print "$e\n";
return undef; return undef;