diff --git a/examples/euler1.lisp b/examples/euler1.lisp new file mode 100644 index 0000000..157e813 --- /dev/null +++ b/examples/euler1.lisp @@ -0,0 +1,6 @@ +;; (defun range (start end) +;; (if (< start end) +;; (cons start (range (+ 1 start) end)) +;; (list))) + +(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 5f0a6ea..86b3dfd 100644 --- a/lib/Minilisp.pm +++ b/lib/Minilisp.pm @@ -278,6 +278,10 @@ 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); },