From 72141ffde624d4e8061db786abf3c9ffd32185fc Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Fri, 2 Apr 2021 01:02:19 +0200 Subject: [PATCH] Add more std functions --- lib/Minilisp.pm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/Minilisp.pm b/lib/Minilisp.pm index b1886be..7eb2269 100644 --- a/lib/Minilisp.pm +++ b/lib/Minilisp.pm @@ -77,17 +77,27 @@ sub tokenize { } my %stdctx = ( - 'add' => sub { + '+' => sub { my $sum = 0; $sum += $_ foreach (@_); return $sum; }, - 'sub' => sub { + '-' => sub { my $sum = shift; $sum -= $_ foreach (@_); 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; print "$e\n"; return undef;