Consecutive calls/evaulations in a form?

Posted by Dave on Stack Overflow See other posts from Stack Overflow or by Dave
Published on 2010-05-20T22:16:51Z Indexed on 2010/05/20 22:20 UTC
Read the original article Hit count: 161

Filed under:
|
|

Hey guys, simple question...

Working with XLISP to write a program, but I've seemed to run into a simple fundamental problem that I can't seem to work around: perhaps someone has a quick fix.

I'm trying to write an if statement who's then-clause evaluates multiple forms and returns the value of the last.

In example:

(setq POSITION 'DINING-ROOM)

(defun LOOK (DIRECTION ROOM) ... )
(defun SETPOS (ROOM) ... )
(defun WHERE () ... )

(defun MOVE (DIRECTION)
(if (not(equal nil (LOOK DIRECTION POSITION))) ; If there is a room in that direction
( ; Then-block: Go to that room. Return where you are.
(SETPOS (LOOK DIRECTION ROOM))
(WHERE)
)
( ; Else-block: Return error
(list 'CANT 'GO 'THERE)
)
)

The logical equivalent intended is:

function Move (Direction)
{

if(Look(Direction, Room) != null)
{
SetPos(Look(Direction,Room));
return Where();
}
else
{
return "Can't go there";
}

}

(Apologies for the poor web-formatting.)

The problem I have is with:

(
(SETPOS (LOOK DIRECTION ROOM))
(WHERE)
)

I simply want to return the evaluation of WHERE, but I need to execute the SETPOS function first. XLISP doesn't like the extra parentheses: if I remove the outer set, my WHERE list becomes my else (I don't want that). If I remove the sets around SETPOS and WHERE, it treats WHERE like an argument for SETPOS; I also don't want that.

So, how do I simply evaluate the first, then the second and then return the values of the last evaluated?

© Stack Overflow or respective owner

Related posts about common-lisp

Related posts about form