From 941bd17ac6d1ced4d353f6b6cca16b818cbb6ad1 Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Mon, 5 Apr 2021 03:50:48 +0200 Subject: [PATCH] Add mod function --- lib/Minilisp.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/Minilisp.pm b/lib/Minilisp.pm index bcce925..5f0a6ea 100644 --- a/lib/Minilisp.pm +++ b/lib/Minilisp.pm @@ -271,6 +271,13 @@ my %stdctx = ( } return $v; }, + 'mod' => sub { + my ($number, $divisor) = @_; + $number += $divisor while ( $number < 0 ); + $number -= $divisor while ( $number >= $divisor ); + + return $number; + }, # String comparison 'string=' => sub { my ($a, $b) = @_; return to_lisp_bool($a eq $b); },