From af9a6acd53d773bbcf986a58659ac843d2864837 Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Fri, 2 Apr 2021 03:36:26 +0200 Subject: [PATCH] Add functions zerop, min and max --- lib/Minilisp.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/Minilisp.pm b/lib/Minilisp.pm index c724f1a..166a261 100644 --- a/lib/Minilisp.pm +++ b/lib/Minilisp.pm @@ -105,6 +105,7 @@ my %stdctx = ( 'null' => sub { my ($a) = @_; return ! defined $a; }, 'evenp' => sub { my ($a) = @_; return ($a % 2 == 0); }, 'oddp' => sub { my ($a) = @_; return ($a % 2 != 0); }, + 'zerop' => sub { my ($a) = @_; return $a == 0; }, 'eq' => sub { my ($a, $b) = @_; return ($a == $b); }, 'ne' => sub { my ($a, $b) = @_; return ($a != $b); }, @@ -128,6 +129,24 @@ my %stdctx = ( '<' => sub { my ($a,$b) = @_; return ($a < $b); }, '>=' => sub { my ($a,$b) = @_; return ($a >= $b); }, '<=' => sub { my ($a,$b) = @_; return ($a <= $b); }, + 'max' => sub { + die "max: At least 2 parameters" unless scalar(@_) >= 2; + my $v = shift; + foreach (@_) + { + $v = $_ if $v < $_; + } + return $v; + }, + 'min' => sub { + die "min: At least 2 parameters" unless scalar(@_) >= 2; + my $v = shift; + foreach (@_) + { + $v = $_ if $v > $_; + } + return $v; + }, # String comparison 'string=' => sub { my ($a, $b) = @_; return ($a eq $b); },