newbie help

Discussion of Common Lisp

newbie help

Postby bnor » Sat Mar 28, 2009 12:57 pm


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.
Posts: 2
Joined: Sat Mar 28, 2009 12:51 pm

Re: newbie help

Postby dmitry_vk » Mon Mar 30, 2009 9:34 am

Write it like this:
Code: Select all
(defun it (n &rest values)
     for y in values
     repeat n
     do (print y)))
Posts: 96
Joined: Sat Jun 28, 2008 8:01 am
Location: Russia, Kazan

Re: newbie help

Postby gugamilare » Mon Mar 30, 2009 10:49 am

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.
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil

Return to Common Lisp

Who is online

Users browsing this forum: No registered users and 6 guests