This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

Very simple lisp, help

3 posts · 1296 views

I have a very simple code problem I trying to find the LCM of few numbers I first created this code which compiles and works..

(defun lcm (&key a b c d e) (lcm a b c d e ))
(lcm :a 3 :b 2 :c 4 :d 7 :e 11)

My instructor informed me that I needed to use &rest. Every time I tried to use the &rest function it has not worked, I am not sure if my syntax is wrong or not. Bellow are the 2 ways I think the code should work but is not working. ANy help or suggestions Thanks much... I

(defun my-lcm (&rest a b c d e) (lcm a b c d e ))
(my-lcm :a 3 :b 2 :c 4 :d 7 :e 11)

Or

(defun my-lcm (&rest 1 2 3 4 5))

Re: Very simple lisp, help

Somehow I doubt that your instructor meant for you to just wrap the standard LCM function. In any case, why are you using keyword arguments? They make no sense in this context. Just use a single &REST argument. This is fairly elementary Common Lisp, you should probably read at least some parts of Practical Common Lisp.

Re: Very simple lisp, help

What you might be trying to do (not tested!):
(defun lcm (&key a b c d e &rest other-keys)
  (list a b c d e (getf other-keys :f)))

(lcm :a 1 :b 2 :c 3 :d 4 :e 5 :f 6) => (1 2 3 4 5 6)