Add functions zerop, min and max
This commit is contained in:
parent
395c271243
commit
af9a6acd53
1 changed files with 19 additions and 0 deletions
|
@ -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); },
|
||||
|
|
Loading…
Reference in a new issue