From 395c2712437d772df811f6429142ac18b13000f3 Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Fri, 2 Apr 2021 03:35:59 +0200 Subject: [PATCH] Add logical operations --- lib/Minilisp.pm | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/Minilisp.pm b/lib/Minilisp.pm index 8e635c5..c724f1a 100644 --- a/lib/Minilisp.pm +++ b/lib/Minilisp.pm @@ -107,7 +107,19 @@ my %stdctx = ( 'oddp' => sub { my ($a) = @_; return ($a % 2 != 0); }, 'eq' => sub { my ($a, $b) = @_; return ($a == $b); }, 'ne' => sub { my ($a, $b) = @_; return ($a != $b); }, + + # Logical operators 'not' => sub { my ($a) = @_; return !$a; }, + 'and' => sub { + my $v = 1; + $v &&= $_ foreach (@_); + return $v; + }, + 'or' => sub { + my $v = 0; + $v ||= $_ foreach(@_); + return $v; + }, # Numeric comparison '=' => sub { my ($a, $b) = @_; return ($a == $b); },