Lisp: IF function error message ??

Status
Not open for further replies.

shish

Usenet Archive
Joined
Jan 15, 2002
Messages
9
Reaction score
0
This is part of a lisp I am writing. I get an error at this line. Basically it will not allow for me to put more than one than one "then expression" (if (< fa1 fa2) ((setq fxx fa2)(setq fzz fa1)(setq fa2 fzz)(setq fa1 fxx))

)

if i put just one then expression it works fine, why??
eg.
(if
(< fa1 fa2)
(setq fxx fa2) ;<--- does not like more than one item here.

)
 
The (if ...) function can accept only a single "then" clause and, optionally, a single "else" clause. You can't just group functions in extra sets of to form a "then" clause; AutoLISP provides the (progn ...) function for that. The correct syntax is:

(if (< fa1 fa2)
(progn
(setq fxx fa2)
(setq fzz fa1)
(setq fa2 fzz)
(setq fa1 fxx)
) ;; progn
) ;; if

or, more simply:

(if (< fa1 fa2)
(setq xxx fa2
fzz fa1
fa2 fzz
fa1 fxx
) ;; setq
) ;; if
___

"shish" wrote:

This is part of a lisp I am writing. I get an error at this line. Basically it will not allow for me to put more than one than one "then expression" (if (< fa1 fa2) ((setq fxx fa2)(setq fzz fa1)(setq fa2 fzz)(setq fa1 fxx))

)

if i put just one then expression it works fine, why??
eg.
(if
...
 
The 'if' function, as well as many others, are intended to normally evaluate just one expression. You get around that by using 'progn', which allows you to group together multiple expressions. In your case you are just doing 'setq', which you can combine into one statement without a 'progn', as in (setq fxx fa2 fzz fa2 .......)

"shish" wrote:
This is part of a lisp I am writing. I get an error at this line. Basically it will not allow for me to put more than one than one "then expression" (if (< fa1 fa2) ((setq fxx fa2)(setq fzz fa1)(setq fa2 fzz)(setq fa1 fxx))

)

if i put just one then expression it works fine, why??
eg.
(if
...
 
Status
Not open for further replies.

Latest threads

Back
Top