From: david
Subject: blocks world
Date: 
Message-ID: <f2cf0645-9d87-4b65-9551-fdf96986b122@w9g2000yqa.googlegroups.com>
hello again lispers,
i attempt to make the blocks world from winston and horn, lisp.

(defclass basic-block ()
  ((name :accessor block-name :initarg :name)
   (width :accessor block-width :initarg :width)
   (height :accessor block-height :initarg :height)
   (position :accessor block-position :initarg :position)
   (supported-by :accessor block-supported-by :initform nil)))

(defclass movable-block (basic-block) ())

(defclass load-bearing-block (basic-block)
  ((support-for :accessor block-support-for :initform nil)))

(defclass brick (movable-block load-bearing-block) ())

(defclass wedge (movable-block) ())

(defclass ball (movable-block) ())

(defclass table (load-bearing-block) ())

(defclass hand ()
  ((name :accessor hand-name :initarg :name)
   (position :accessor hand-position :initarg :position)
   (grasping :accessor hand-grasping :initform nil)))



(defvar *blocks*
  (list
   (make-instance 'table :name 'table :width 20 :height 0 :position
'(0 0))
   (make-instance 'brick :name 'b1  :width 2  :height 2  :position '(0
0))
   (make-instance 'brick :name 'b2 :width  2  :height 2  :position '(2
0))
   (make-instance 'brick :name 'b3 :width  4  :height 4  :position '(4
0))
   (make-instance 'brick :name 'b4 :width  2  :height 2  :position '(8
0))
   (make-instance 'wedge :name 'w5  :width 2  :height 4 :position '(10
0))
   (make-instance 'brick :name 'b6  :width 4  :height 2 :position '(12
0))
   (make-instance 'wedge :name 'w7 :width  2  :height 2 :position '(16
0))
   (make-instance 'ball  :name 'l8 :width  2  :height 2 :position '(18
0))))

now i get to this line of code which does not produce the desired
result

(dolist (l *blocks*) (set (block-name l) l))

i cannot explore blocks world without any blocks.
please help?
thanks, david

From: Tamas K Papp
Subject: Re: blocks world
Date: 
Message-ID: <73i5pkFun0h3U1@mid.individual.net>
On Wed, 01 Apr 2009 14:38:52 -0700, david wrote:

> hello again lispers,
> i attempt to make the blocks world from winston and horn, lisp.
> 
> (defclass basic-block ()
>   ((name :accessor block-name :initarg :name)
>    (width :accessor block-width :initarg :width) (height :accessor
>    block-height :initarg :height) (position :accessor block-position
>    :initarg :position) (supported-by :accessor block-supported-by
>    :initform nil)))
> 
> (defclass movable-block (basic-block) ())
> 
> (defclass load-bearing-block (basic-block)
>   ((support-for :accessor block-support-for :initform nil)))
> 
> (defclass brick (movable-block load-bearing-block) ())
> 
> (defclass wedge (movable-block) ())
> 
> (defclass ball (movable-block) ())
> 
> (defclass table (load-bearing-block) ())
> 
> (defclass hand ()
>   ((name :accessor hand-name :initarg :name)
>    (position :accessor hand-position :initarg :position) (grasping
>    :accessor hand-grasping :initform nil)))
> 
> 
> 
> (defvar *blocks*
>   (list
>    (make-instance 'table :name 'table :width 20 :height 0 :position
> '(0 0))
>    (make-instance 'brick :name 'b1  :width 2  :height 2  :position '(0
> 0))
>    (make-instance 'brick :name 'b2 :width  2  :height 2  :position '(2
> 0))
>    (make-instance 'brick :name 'b3 :width  4  :height 4  :position '(4
> 0))
>    (make-instance 'brick :name 'b4 :width  2  :height 2  :position '(8
> 0))
>    (make-instance 'wedge :name 'w5  :width 2  :height 4 :position '(10
> 0))
>    (make-instance 'brick :name 'b6  :width 4  :height 2 :position '(12
> 0))
>    (make-instance 'wedge :name 'w7 :width  2  :height 2 :position '(16
> 0))
>    (make-instance 'ball  :name 'l8 :width  2  :height 2 :position '(18
> 0))))
> 
> now i get to this line of code which does not produce the desired result
> 
> (dolist (l *blocks*) (set (block-name l) l))
> 
> i cannot explore blocks world without any blocks. please help?
> thanks, david

You are setting the block's name to the blocks themselves.  I
understand that this is not the desired result, but what do you want
to do then?  Also, I guess you want to use setf instead of set.

Forgive me if I am wrong, but it appears that you just typed in some
code without understanding what it does.  Perhaps a Lisp primer (PCL,
or Graham's ANSI Common Lisp comes to mind) would help.

Tamas
From: david
Subject: Re: blocks world
Date: 
Message-ID: <5e7dbcac-07c1-4032-8a62-7c02b78fa445@w40g2000yqd.googlegroups.com>
On Apr 1, 4:48 pm, Tamas K Papp <······@gmail.com> wrote:

>
> You are setting the block's name to the blocks themselves.  I
> understand that this is not the desired result, but what do you want
> to do then?  Also, I guess you want to use setf instead of set.
>
> Forgive me if I am wrong, but it appears that you just typed in some
> code without understanding what it does.  Perhaps a Lisp primer (PCL,
> or Graham's ANSI Common Lisp comes to mind) would help.
>
> Tamas

i think i understand this paragraph:
at this point, the only way to get at instances of the classes is
through
the list assigned to *blocks*. we assign each instance to the symbol
found in its name slot. we do this using set, which is like setf,
except
that set evaluates both its arguments, the first of which must
evaluate
to the name of a special variable.
(dolist (l *blocks*) (set (block-name l) l))
there is a symbol for each block and the value of that symbol is the
appropriate block-describing instance.

so i think i know what i want to happen. also i know that set is
deprecated. also i know that substituting setf or setq will not
work. also i know i could work around this by assigning each instance
individually. i was hoping for some way of avoiding this.
thanks, david
From: Pascal J. Bourguignon
Subject: Re: blocks world
Date: 
Message-ID: <87k5646lon.fsf@galatea.local>
david <······@gmail.com> writes:

> On Apr 1, 4:48�pm, Tamas K Papp <······@gmail.com> wrote:
>
>>
>> You are setting the block's name to the blocks themselves. �I
>> understand that this is not the desired result, but what do you want
>> to do then? �Also, I guess you want to use setf instead of set.
>>
>> Forgive me if I am wrong, but it appears that you just typed in some
>> code without understanding what it does. �Perhaps a Lisp primer (PCL,
>> or Graham's ANSI Common Lisp comes to mind) would help.
>>
>> Tamas
>
> i think i understand this paragraph:
> at this point, the only way to get at instances of the classes is
> through
> the list assigned to *blocks*. we assign each instance to the symbol
> found in its name slot. we do this using set, which is like setf,
> except
> that set evaluates both its arguments, the first of which must
> evaluate
> to the name of a special variable.
> (dolist (l *blocks*) (set (block-name l) l))
> there is a symbol for each block and the value of that symbol is the
> appropriate block-describing instance.
>
> so i think i know what i want to happen. also i know that set is
> deprecated. also i know that substituting setf or setq will not
> work. also i know i could work around this by assigning each instance
> individually. i was hoping for some way of avoiding this.
> thanks, david

If you want to avoid SET, you can use SETF instead.

  (dolist (l *blocks*) (setf (symbol-value (block-name l)) l))

But I would advise you to implement rather an accessor:

(defun bloc (name) (find name *blocks* :key (function block-name)))
;; block is already an operator in CL.

C/BLOCKS[64]> (bloc 'w7)
#<WEDGE #x1A1B24C9>
C/BLOCKS[65]> (bloc 'b2)
#<BRICK #x1A1B2401>


-- 
__Pascal Bourguignon__
From: Pascal J. Bourguignon
Subject: Re: blocks world
Date: 
Message-ID: <87zlf06ngf.fsf@galatea.local>
david <······@gmail.com> writes:

> hello again lispers,
> i attempt to make the blocks world from winston and horn, lisp.
> [...]
> (defvar *blocks*
>   (list
>    (make-instance 'table :name 'table :width 20 :height 0 :position '(0 0))
>    (make-instance 'brick :name 'b1  :width 2  :height 2  :position '(0 0))
>    (make-instance 'brick :name 'b2 :width  2  :height 2  :position '(2 0))
>    (make-instance 'brick :name 'b3 :width  4  :height 4  :position '(4 0))
>    (make-instance 'brick :name 'b4 :width  2  :height 2  :position '(8 0))
>    (make-instance 'wedge :name 'w5  :width 2  :height 4 :position '(10 0))
>    (make-instance 'brick :name 'b6  :width 4  :height 2 :position '(12 0))
>    (make-instance 'wedge :name 'w7 :width  2  :height 2 :position '(16 0))
>    (make-instance 'ball  :name 'l8 :width  2  :height 2 :position '(18 0))))
>
> now i get to this line of code which does not produce the desired
> result
>
> (dolist (l *blocks*) (set (block-name l) l))

What do you expect?  This code does exactly what it must do.


C/BLOCKS[42]> (dolist (l *blocks*) (set (block-name l) l))
NIL
C/BLOCKS[43]> w7
#<WEDGE #x1A26A629>
C/BLOCKS[44]> b2
#<BRICK #x1A26A489>


> i cannot explore blocks world without any blocks.

Indeed, and empty world doesn't offer many exploration opportunities...

> please help?

What help do you need?

-- 
__Pascal Bourguignon__
From: david
Subject: Re: blocks world
Date: 
Message-ID: <95cbcf6a-6925-4ff8-95e4-9ccb85a66827@c36g2000yqn.googlegroups.com>
On Apr 1, 5:03 pm, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> david <······@gmail.com> writes:
> > hello again lispers,
> > i attempt to make the blocks world from winston and horn, lisp.
> > [...]
> > (defvar *blocks*
> >   (list
> >    (make-instance 'table :name 'table :width 20 :height 0 :position '(0 0))
> >    (make-instance 'brick :name 'b1  :width 2  :height 2  :position '(0 0))
> >    (make-instance 'brick :name 'b2 :width  2  :height 2  :position '(2 0))
> >    (make-instance 'brick :name 'b3 :width  4  :height 4  :position '(4 0))
> >    (make-instance 'brick :name 'b4 :width  2  :height 2  :position '(8 0))
> >    (make-instance 'wedge :name 'w5  :width 2  :height 4 :position '(10 0))
> >    (make-instance 'brick :name 'b6  :width 4  :height 2 :position '(12 0))
> >    (make-instance 'wedge :name 'w7 :width  2  :height 2 :position '(16 0))
> >    (make-instance 'ball  :name 'l8 :width  2  :height 2 :position '(18 0))))
>
> > now i get to this line of code which does not produce the desired
> > result
>
> > (dolist (l *blocks*) (set (block-name l) l))
>
> What do you expect?  This code does exactly what it must do.
>
> C/BLOCKS[42]> (dolist (l *blocks*) (set (block-name l) l))
> NIL
> C/BLOCKS[43]> w7
> #<WEDGE #x1A26A629>
> C/BLOCKS[44]> b2
> #<BRICK #x1A26A489>
>
> > i cannot explore blocks world without any blocks.
>
> Indeed, and empty world doesn't offer many exploration opportunities...
>
> > please help?
>
> What help do you need?
>
> --
> __Pascal Bourguignon__

well, now it is working. it was working all last night too. it just
hadn't
been working all day. was telling me b1 has no value.
also now setf works. i still get these warnings:

;; Compiling file /home/david/blocks.lisp ...
WARNING in #:|42 44 (DOLIST (L #) (PUSH L #) ...)-11| in lines
42..44 :
TABLE is neither declared nor bound,
it will be treated as if it were declared SPECIAL.
WARNING in #:|42 44 (DOLIST (L #) (PUSH L #) ...)-11| in lines
42..44 :
TABLE is neither declared nor bound,
it will be treated as if it were declared SPECIAL.
WARNING in #:|42 44 (DOLIST (L #) (PUSH L #) ...)-11| in lines
42..44 :
TABLE is neither declared nor bound,
it will be treated as if it were declared SPECIAL.
;; Wrote file /home/david/blocks.fas
The following special variables were not defined:
 TABLE
0 errors, 3 warnings

but i think it is supposed to be a special variable.
anyway i can't fix a problem i can't reproduce.
thanks, david
From: Pascal J. Bourguignon
Subject: Re: blocks world
Date: 
Message-ID: <87bprf7c8d.fsf@galatea.local>
david <······@gmail.com> writes:
> well, now it is working. it was working all last night too. it just
> hadn't
> been working all day. was telling me b1 has no value.
> also now setf works. i still get these warnings:
>
> ;; Compiling file /home/david/blocks.lisp ...
> WARNING in #:|42 44 (DOLIST (L #) (PUSH L #) ...)-11| in lines
> 42..44 :
> TABLE is neither declared nor bound,
> it will be treated as if it were declared SPECIAL.
> WARNING in #:|42 44 (DOLIST (L #) (PUSH L #) ...)-11| in lines
> 42..44 :
> TABLE is neither declared nor bound,
> it will be treated as if it were declared SPECIAL.
> WARNING in #:|42 44 (DOLIST (L #) (PUSH L #) ...)-11| in lines
> 42..44 :
> TABLE is neither declared nor bound,
> it will be treated as if it were declared SPECIAL.
> ;; Wrote file /home/david/blocks.fas
> The following special variables were not defined:
>  TABLE
> 0 errors, 3 warnings
>
> but i think it is supposed to be a special variable.
> anyway i can't fix a problem i can't reproduce.
> thanks, david

This is the reason why I advised in my other answer to use an accessor
function (bloc 'b7) instead of using these variables.

First, special variables should be named with earmuffs to avoid
collision with lexical variables. Otherwise strange consequences may
occur.

Next, special variables should be declared, otherwise assigning
directly to them as you do may have undefined effects. You're lucky if
your implementation just issues a warning.

So either use (bloc 'b7), or define your variables:
    (defparameter *b7* (make-block :name '*b7* ...))
    ...
    (defparameter *blocks* (list *b7* ...))


-- 
__Pascal Bourguignon__
From: david
Subject: Re: blocks world
Date: 
Message-ID: <00db32e7-cda4-48f2-ae6a-00db89711c73@o6g2000yql.googlegroups.com>
On Apr 2, 2:20 am, ····@informatimago.com (Pascal J. Bourguignon)
wrote:
> david <······@gmail.com> writes:
> > well, now it is working. it was working all last night too. it just
> > hadn't
> > been working all day. was telling me b1 has no value.
> > also now setf works. i still get these warnings:
>
> > ;; Compiling file /home/david/blocks.lisp ...
> > WARNING in #:|42 44 (DOLIST (L #) (PUSH L #) ...)-11| in lines
> > 42..44 :
> > TABLE is neither declared nor bound,
> > it will be treated as if it were declared SPECIAL.
> > WARNING in #:|42 44 (DOLIST (L #) (PUSH L #) ...)-11| in lines
> > 42..44 :
> > TABLE is neither declared nor bound,
> > it will be treated as if it were declared SPECIAL.
> > WARNING in #:|42 44 (DOLIST (L #) (PUSH L #) ...)-11| in lines
> > 42..44 :
> > TABLE is neither declared nor bound,
> > it will be treated as if it were declared SPECIAL.
> > ;; Wrote file /home/david/blocks.fas
> > The following special variables were not defined:
> >  TABLE
> > 0 errors, 3 warnings
>
> > but i think it is supposed to be a special variable.
> > anyway i can't fix a problem i can't reproduce.
> > thanks, david
>
> This is the reason why I advised in my other answer to use an accessor
> function (bloc 'b7) instead of using these variables.
>
> First, special variables should be named with earmuffs to avoid
> collision with lexical variables. Otherwise strange consequences may
> occur.
>
> Next, special variables should be declared, otherwise assigning
> directly to them as you do may have undefined effects. You're lucky if
> your implementation just issues a warning.
>
> So either use (bloc 'b7), or define your variables:
>     (defparameter *b7* (make-block :name '*b7* ...))
>     ...
>     (defparameter *blocks* (list *b7* ...))
>
> --
> __Pascal Bourguignon__

thanks. blocks world is up and running now.