Search code examples
if-statementfunctional-programminglispcommon-lispclisp

Error in LISP - SYSTEM::%EXPAND-FORM: invalid form (40)


I am working on a Lisp program that contains code to read in the dimensions of boxes and then sort them from shortest to longest lengths (and set each of these new lengths as new variables).

When I attempt to load my file into the interpreter, I get the following error:

 - SYSTEM::%EXPAND-FORM: invalid form (40)

Assuming this error is stemming from line 40 of my code, here are lines 34-45:

(defun get-box ()
    (let ((d1) (d2) (d3))
        (setf d1 (read))
        (setf d2 (read))
        (setf d3 (read))
        (list d1 d2 d3))
        (if (= -1 d1)
            (exit)
            (setf new-d1 (first (sort (d1 d2 d3)) #'<))
            (setf new-d2 (second (sort (d1 d2 d3)) #'<))
            (setf new-d3 (third (sort (d1 d2 d3)) #'<))
            (next-part-of-program (new-d1, new-d2, new-d3)))

Is there anything inherently wrong syntactically or semantically with my if statement in this code snippet? What does the EXPAND-FORM error come from/mean in Lisp?

Any help is greatly appreciated. Thanks!


Solution

  • When you see a message mentioning symbols in the "SYS" package (also known as "SI" and "SYSTEM" in different implementations), especially when the symbols are internal (prefixed with two colons), and, moreover, their names contain non-alphanumeric characters (e.g., % or $), chances are this message is implementation-specific, and you will help us help you by mentioning which implementation you are using.

    That said, I think you are using CLISP, in which case this 40 does not name a line in your file.

    You either have a literal 40 in an inappropriate place in your file, or you have a variable with the value of 40 which you evaluate during macroexpansion with a misplaced comma.