summaryrefslogtreecommitdiff
path: root/gcd.lisp
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2022-11-07 00:04:44 +0200
committerIgor Pashev <pashev.igor@gmail.com>2022-11-07 09:35:20 +0200
commit2d27a4fbe3d9c8386c5477ac67a129ecba2c3ec7 (patch)
tree85651d29a659421167f9dade1113c3b7a1283f37 /gcd.lisp
parent47c813d6aeccc289dca3c34f9b6ea55771573d55 (diff)
downloadgcd-2d27a4fbe3d9c8386c5477ac67a129ecba2c3ec7.tar.gz
lisp: require a number
Diffstat (limited to 'gcd.lisp')
-rw-r--r--gcd.lisp11
1 files changed, 6 insertions, 5 deletions
diff --git a/gcd.lisp b/gcd.lisp
index da24b5e..89ee997 100644
--- a/gcd.lisp
+++ b/gcd.lisp
@@ -9,9 +9,8 @@
a
(gcd2 b (mod a b))))
-(defun gcdn (&rest numbers)
- (reduce #'gcd2 (rest numbers)
- :initial-value (first numbers)))
+(defun gcdn (n &rest ns)
+ (reduce #'gcd2 ns :initial-value n))
(defun program-args ()
(or
@@ -26,6 +25,8 @@
(map 'list (lambda (x) (parse-integer x :junk-allowed t))
(program-args))))
-(write (apply #'gcdn (numbers)))
-(fresh-line)
+(let ((ns (numbers)))
+ (when ns
+ (write (apply #'gcdn ns))
+ (fresh-line)))