- #1
kataya
- 23
- 0
I have been messing around with Lisp for a few days now, and I have run into a recurring problem with trying to execute multiple things on given conditions. In all other programming languages I have ever worked with, conditional blocks can always be defined with {} or some other delimiter, such that they can evaluate multiple statements on a given condition. To give a better example of what I mean, here is a simple function that I have been trying to write.
;;Returns the elements in xlist up to a given index
(defun list-part (xlist index)
(if (zerop index)
nil
( (1- index) (cons (list (car xlist)) (list-part (cdr xlist))) )))
This will produce a compiler error saying that (1- index) is not the name of a function. Seeing how this fails, is there some what to execute multiple statements on a given condition? Thanks in advance for your help.
EDIT: There are some fundamental errors in the function, such as calling list-part with only 1 argument. The function can in fact be made with with only 1 evaluation statement. However, is this always the case?
;;Returns the elements in xlist up to a given index
(defun list-part (xlist index)
(if (zerop index)
nil
( (1- index) (cons (list (car xlist)) (list-part (cdr xlist))) )))
This will produce a compiler error saying that (1- index) is not the name of a function. Seeing how this fails, is there some what to execute multiple statements on a given condition? Thanks in advance for your help.
EDIT: There are some fundamental errors in the function, such as calling list-part with only 1 argument. The function can in fact be made with with only 1 evaluation statement. However, is this always the case?
Last edited: