Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask YC: Questions about defun and lisp in general
2 points by Novash on Aug 28, 2008 | hide | past | favorite | 2 comments
I know this is not the best place to be asking lisp questions so if someone opposes to it, I make this once the single time I do it.

I've been reading PG's ACL book, and since coders are restless beings, of course I don't want to read the whole book to understand what went wrong with what I did. See, here at page 15 he defines this nice 'SUM-GREATER' function. It takes 3 arguments and returns true if the sum of the first two is greater than the third. Here it goes:

(defun sum-greater (x y z) (> (+ x y) z))

Not that hard. NOW, I know that the + function can accept any ammount of parameters so I was trying to figure out how to pass a list as one of the first two parameters (or both) and do not crash the function. Passing another sum doesn't count as a solution. What I am looking for is more on the lines of a C "..." parameter type.

Now, if I haven't annoyed enough yet, I know there is a mirc channel about lisp somewhere, but on which mirc net? I think I should ask future questions there.



You're right that this is the wrong forum.

Anyway, the syntax you're looking for is &REST

    (defun x (y &REST zs) (...))
Good luck.


Thank you. I looked into &REST and all the other ways I can declare parameters and I didn't think the Lisp defun could be so powerful. It is not a matter of how I can declare a function anymore but a matter of how I can't.

Where would it be the right forum?




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: