1

So I have an error:

EVAL: undefined function P1

Below is my code so far.

(defun andexp (a b) (list 'and a b))
(defun orexp (a b) (list 'or a b))
(defun notexp (a) (list 'not a))

(defun evalexp (main-list bind-list)
;first change the bind-list to work with sublis
(setq new-bind-list (list (car bind-list).(cdr bind-list)))
;here will go the looping to check matching variable names
(sublis main-list new-bind-list)

);end of evalexp function

Here I am creating an expression:

(setq p1 (andexp 1 (orexp 'a 'b)))

Which evaluates to this:

(and 1 (or a b))

when I run the code below, I get the error I mentioned above.

(evalexp ( p1 '( (a 0) (b 1))))

p1 should contain a list, so I assumed it would work. This leads to my question of, how am I suppose to send lists as parameters into a function? Am I doing it wrong, or is it something else?

8
  • Learn backquote, by the way. Instead of (list 'add a b), you can write `(add ,a ,b). Commented Mar 6, 2012 at 7:20
  • 1
    This is no good: (setq new-bind-list (list (car bind-list).(cdr bind-list))) . Your list form uses dotted notation: (list (car bind-list) . (cdr bind-list))). REmember that (a . (b)) means (a b). So this is the same as (list (car bind-list) cdr bind-list) !!! Are you sure you want that dot there? Commented Mar 6, 2012 at 7:22
  • To transform the pair-based list into an assoc list used by sublis, you need something else entirely. Firstly, for a single binding like (a 0), car and cdr are not the right accessors to get a and 0. Rather (car binding) and (car (cdr binding)). It's better to just write (first binding) (second binding)! Secondly, you have to march over all of the bindings and transform the whole list, mapping the list-pair binding to a cons-pair binding. I wrote that in the other question: a loop form. How about mapcar instead? (mapcar (lambda (entry) (cons (first entry) (second entry))) bindings). Commented Mar 6, 2012 at 7:24
  • I'm going to be honest and say that I do not know enough about lisp to understand exactly how to access the (a 0) correctly. Why wouldn't (car binding) work for getting a and (cdr(car binding)) work for 0? It points to it doesn't it? Commented Mar 6, 2012 at 17:58
  • The reason why I put the dot there was to make it compatible with sublis. I did not know that (a . (b)) was the same as (a b), which in my case, it build back down to the expression without the dot making it incompatible with sublis' parameter. Commented Mar 6, 2012 at 18:01

1 Answer 1

2

note the erroneous extra parens:

(evalexp ( p1 '( (a 0) (b 1))))

should be

(evalexp p1 '((a 0) (b 1)))
Sign up to request clarification or add additional context in comments.

2 Comments

Those parens are annoying! I am new to lisp, I really appreciate it.
You are probably doing the "arguments have parens around them" that I vaguely remember when I learned lisp (after Pascal and C exposure). Instead of fn(a,b) it's (fn a b).

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.