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.

newbie help

3 posts · 2168 views

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:

(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

Write it like this:
(defun it (n &rest values)
  (loop
     for y in values
     repeat n
     do (print y)))

Re: newbie help

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.