0

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!

6
  • When I run your function, I get a different error: the function next-part-of-program is undefined. The symbol new-d1 is not used as a funtion in the above code. Please update your question with the actual code that produces the error. Commented Nov 24, 2013 at 3:24
  • It's possible that you have a next-part-of-program function defined, and that's the place where new-d1 is being called or otherwise used as a function. Commented Nov 24, 2013 at 3:25
  • Thanks; I've added in the next function in my code. Is new-d1 used as a function here or could it be even later in my code, such as in put-on-a-list? Commented Nov 24, 2013 at 3:33
  • You should learn how to use your Lisp debugger to discover where you are in the evaluation (obtain a "backtrace"). This exercise is futile; eventually we will end up with your entire program. Commented Nov 24, 2013 at 3:37
  • possible duplicate of Lisp function call syntax Commented Nov 24, 2013 at 4:23

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

2 Comments

+1; which will reveal another error: Error: The variable B is unbound.
In this case, is variable B referring to a different variable B earlier in my program or one of the params to next-part-of-program?
1

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) #'<))))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.