user1462294
user1462294

Reputation: 167

Undefined function error in LISP

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:

*** - EVAL: undefined function NEW-D1

I am confused as to why I'd be getting this error because new-d1 isn't a function, it's a variable for the length of the shortest edge of a given box.

Here's the code where new-d1 is first initialized and set:

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

How can I change my code so the interpreter knows new-d1 isn't a function and doesn't treat it as such? Thanks for any help!

Edited to add: Next part of program code:

(defun next-part-of-program(d1 d2 d3)
    (if (> d2 b)
        (put-on-c-list(d1 c-list))
        (if (> d2 a) and (< d2 c)
            (put-on-b-list (d1 b-list))
            (put-on-a-list (d1 a-list)))))

Note: I've initialized a-list, b-list, and c-list earlier as global variables/lists to be added to later.

Thanks again!

Upvotes: 0

Views: 4981

Answers (2)

Rainer Joswig
Rainer Joswig

Reputation: 139261

You can write it a bit shorter:

(defun get-box (&aux (d1 (read)) (d2 (read)) (d3 (read)))
  (if (= d1 -1)
      (exit)
    (apply #'next-part-of-program
           (sort (list d1 d2 d3) #'<))))

Upvotes: 1

Doug Currie
Doug Currie

Reputation: 41180

The last line of get-box should be:

(next-part-of-program new-d1 new-d2 new-d3)))))

You should not have parens around the arguments to next-part-of-program

Upvotes: 3

Related Questions