Add functions zerop, min and max

This commit is contained in:
madmaurice 2021-04-02 03:36:26 +02:00
parent 395c271243
commit af9a6acd53

View file

@ -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); },