From cd769b36dec34e2ba0329e2c6710088229d9d889 Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Tue, 6 Apr 2021 22:11:52 +0200 Subject: [PATCH] Remove non standard range function Let example define its own range function using do. --- examples/euler1.lisp | 6 ++---- lib/Minilisp.pm | 4 ---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/examples/euler1.lisp b/examples/euler1.lisp index 157e813..bb176af 100644 --- a/examples/euler1.lisp +++ b/examples/euler1.lisp @@ -1,6 +1,4 @@ -;; (defun range (start end) -;; (if (< start end) -;; (cons start (range (+ 1 start) end)) -;; (list))) +(defun range (start end) + (do ((lst (list) (cons i lst)) (i start (+ 1 i))) ((= i end) lst))) (write-line (reduce + (filter (lambda (x) (or (zerop (mod x 3)) (zerop (mod x 5)))) (range 1 1000)))) diff --git a/lib/Minilisp.pm b/lib/Minilisp.pm index 2ed7772..5866270 100644 --- a/lib/Minilisp.pm +++ b/lib/Minilisp.pm @@ -278,10 +278,6 @@ my %stdctx = ( return $number; }, - 'range' => sub { - my ($start, $end) = @_; - return [ $start .. ($end-1) ]; - }, # String comparison 'string=' => sub { my ($a, $b) = @_; return to_lisp_bool($a eq $b); },