If you use code tags you can preserve your indentation.
- Code: Select all
(defun move_robot (move '('pr_move x y))
(cond ((eq move 'ML) ('NO_MOVE))
((eq move 'MU) ('NO_MOVE))
((eq move 'MD) ('NO_MOVE))
((eq move 'MR) (cond ((eq pr_move 'ML) (princ ('ML x (+ y 1))))
((eq pr_move 'MR) (princ ('MR x (+ y 1))))
((eq pr_move 'MU) (princ ('MU x (+ y 1))))
((eq pr_move 'MD) (princ ('MD x (+ y 1))))))))
You've got a quoted list of some values sitting in the arguement list. This isn't valid Lisp code, what is it doing there?
Since 'NO_MOVE is not a function, you should not put it in parentheses, because this is how you call functions. You just want to type the symbol itself there. Likewise, in your call to PRINC, you can't type "('ML ...", because 'ML is not a function. If you want to create a list there, use the LIST function to create one.
Also you have a couple of style issues which are not bugs. Lispers usually do not use underscores to separate words in symbols. MOVE-ROBOT, PR-MOVE, and NO-MOVE would be more normal names (I only capitalize these symbols here to make it clear that they are Lisp code. I'm not suggesting that you do so in your program).
While your use of COND is correct, using CASE would result in shorter code.
In your second COND, you're not actually doing anything different depending on the value of PR_MOVE. You can simply interpolate this variable into the list you print/return. What you've done is as silly as (IF 'A 'A).
Check me on this, but I believe the following should do what your function is supposed to do. I don't mind putting it here, since the problems with your code are just syntactic, and you seem to know what you're trying to do.
- Code: Select all
(defun move-robot (move pr-move x y)
(case move
((ML MU MD) 'NO-MOVE)
((MR) (princ (list pr-move x (1+ y))))))