From: david
Subject: newbie defun problem
Date: 
Message-ID: <pan.2006.03.18.11.30.08.475090@earthlink.net>
hello, i am trying to add a function to the code below as

defun move-mob (mob direction)
    if (find 'direction (directions-mob-can-go david))  ; ???
       (put-mob)
       (format t "you can't go that way")

i tried to use find or member inside the function but if i pass them
direction it needs to be quoted so if i try (move-mob david 'north) i get
(find 'direction list)
instead of (find 'north list)
i think i lack the terminology to express my problem more clearly. any
help appreciated.

this is the code that works so far:

(setf *print-circle* t)            

(defstruct location             
	   (description "default description")
	   (contents nil)
	   (exits nil))

(defstruct mob name location inventory)

(defvar room1 (make-location
           :exits '((north room2)(south room3))))
(defvar room2 (make-location :exits '((south room1))))
(defvar room3 (make-location :exits '((north room1))))

(defvar david (make-mob :name "david"))


(defun mob-can-go (mob)
	    (location-exits (mob-location mob)))

(defun remove-mob (mob)
   "won't work if mob-location isn't set"
	   (setf (location-contents (mob-location mob))
		    (remove mob
                       (location-contents (mob-location mob)))))

(defun put-mob (mob location)
	   (setf (mob-location mob)location)
	   (push mob (location-contents location)))

(defun directions-mob-can-go (mob)
	   (mapcar #'car (mob-can-go mob)))

(put-mob david room1)

From: Ken Tilton
Subject: Re: newbie defun problem
Date: 
Message-ID: <%LTSf.754$3z.594@fe09.lga>
david wrote:
> hello, i am trying to add a function to the code below as
> 
> defun move-mob (mob direction)
>     if (find 'direction (directions-mob-can-go david))  ; ???
>        (put-mob)
>        (format t "you can't go that way")

Where are the missing parentheses? Around the defun and the if.

(defun move-mob ...
    (if ....

...and then add closing parens appropriately. At that point what it 
seems you tried originally:

    (if (find direction ...

...ie, with direction unquoted, will work.

kt
From: david
Subject: Re: newbie defun problem
Date: 
Message-ID: <pan.2006.03.19.13.31.02.376420@earthlink.net>
On Sat, 18 Mar 2006 08:17:47 -0500, Ken Tilton wrote:

> 
> Where are the missing parentheses? Around the defun and the if.
> 
 
sorry, the parentheses were imaginary or assumed.
i will not post code like that anymore :)
From: Pascal Bourguignon
Subject: Re: newbie defun problem
Date: 
Message-ID: <87y7z89bja.fsf@thalassa.informatimago.com>
david <·····@earthlink.net> writes:

> hello, i am trying to add a function to the code below as
>
> defun move-mob (mob direction)
>     if (find 'direction (directions-mob-can-go david))  ; ???
>        (put-mob)
>        (format t "you can't go that way")
>
> i tried to use find or member inside the function but if i pass them
> direction it needs to be quoted so if i try (move-mob david 'north) i get
> (find 'direction list)
> instead of (find 'north list)
> i think i lack the terminology to express my problem more clearly. any
> help appreciated.


What is NORTH?


NORTH is a symbol whose name is "NORTH". ("NORTH" is a string).



What is the value of NORTH?


Since you've not bound NORTH to anything (with DEFCONSTANT, DEFVAR,
DEFPARAMETER, LET or LET*, (plus a few others)), it is UNBOUND, it has no value.

If you try to evaluate a variable that has no value, you get an error:

[250]> NORTH

*** - EVAL: variable NORTH has no value



What is 'NORTH?


It's an abreviation for: (QUOTE NORTH)



What is (QUOTE NORTH)?


It's a list containing two elements:
1- the symbol QUOTE
2- the symbol NORTH



What is the value of (QUOTE NORTH)?


We need to evaluate it.
http://www.lispworks.com/documentation/HyperSpec/Body/03_ab.htm 
(QUOTE NORTH) is a list, so to evaluate it we must look at the first element.
QUOTE is a symbol which names a special operator.  The rules of evaluation of
the argument of this special operator is that the argument IS NOT evaluated,
and returned as is.  So the value of (QUOTE NORTH) is the symbol NORTH.




What is the value of DIRECTION, in the lexical context of the body of
the function MOVE-MOB?


The value of DIRECTION is whatever has been bound to this parameter
when the function MOVE-MOB is called.   
Assuming this function call: (MOVE-MOB (QUOTE NORTH))
the value of DIRECTION is the symbol NORTH.




What is the value of (QUOTE DIRECTION)?



See the value of (QUOTE NORTH) above.  
The value of (QUOTE DIRECTION) is the symbol DIRECTION.



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

HEALTH WARNING: Care should be taken when lifting this product,
since its mass, and thus its weight, is dependent on its velocity
relative to the user.
From: david
Subject: Re: newbie defun problem
Date: 
Message-ID: <pan.2006.03.18.13.31.04.956493@earthlink.net>
thanks! 
i did (defvar north 'north) and everything worked. 
no time to understand it though. off to work.
thanks!
From: Timofei Shatrov
Subject: Re: newbie defun problem
Date: 
Message-ID: <441c1e56.23787945@news.readfreenews.net>
On Sat, 18 Mar 2006 11:30:24 GMT, david <·····@earthlink.net> tried to
confuse everyone with this message:

>hello, i am trying to add a function to the code below as
>
>defun move-mob (mob direction)
>    if (find 'direction (directions-mob-can-go david))  ; ???
>       (put-mob)
>       (format t "you can't go that way")


If you like interactive fiction, you may be interested in LIFP:

http://common-lisp.net/project/lifp/

I would also recommend learning CLOS, because this problem is just
asking for object-oriented approach. Structures are just poor
substitution for objects, and CLOS is not that hard to learn if you read
the right book (hint: Practical Common Lisp is one).
 
-- 
|WAR HAS NEVER SOLVED ANYTHING|,----- Timofei Shatrov aka Grue---------.
|(except for ending slavery,  ||mail: grue at mail.ru ================ |
|   fascism and communism)    ||============= http://grue3.tripod.com  |
|...and Saddam's dictatorship |`----------------------------------[4*72]