Page 1 of 1

newbie help

Posted: Sat Mar 28, 2009 12:57 pm
by bnor
Hello,

I am trying to learn LISP for the first time. What I am trying to do seems basic to me but I am having trouble since I don' t have the experience.

I would like to create a function to accept a list of variable arguments, and then iterate through it, printing the first n values. Here is what I have tried:

Code: Select all

(defun it (n &rest values)
  (loop for y in values
   for n from 1
   do (print(y))
)
I found some tutorials on the web, but cannot get this to work. Probably due to my being familiar with c/c++ and not yet understanding LISP.

Any hints?

Thanks in advance.

Re: newbie help

Posted: Mon Mar 30, 2009 9:34 am
by dmitry_vk
Write it like this:

Code: Select all

(defun it (n &rest values)
  (loop
     for y in values
     repeat n
     do (print y)))

Re: newbie help

Posted: Mon Mar 30, 2009 10:49 am
by gugamilare
Function calls in Lisp are done this way: (f a b) - calls f with a and b as arguments. In C you would write f(a,b), but in Lisp you put the function being called inside the parentesis as well.