About blocks-world:
This package contains the source code of chapter 21, "The Blocks World with Classes and Methods" from Lisp (3rd edition) by Winston
and Horn.
About blocks-world-goals:
This package contains the source code of chapter 22, "Answering Questions about Goals" from Lisp (3rd edition) by Winston
and Horn.
Contents
- Package blocks-world
- Package blocks-world-goals
Package blocks-world
This package contains the source code of chapter 21, "The Blocks World with Classes and Methods" from Lisp (3rd edition) by Winston
and Horn.
A picture of the world
The block objects represent a world that "looks" like this:
/----\ ^ /---------\ ^ | b4 | / \ | | / \ \____/ /_w7_\ | | / \ /----\ /----\ | | / \ /--------\ /^\ | b1 | | b2 | | b3 | / \ | b6 | (l8 ) \____/ \____/ \_________/ /_w5__\ \________/ \./ +-----------------------------------------------------------+ | | +-----------------------------------------------------------+
Example
In the initial configuration, where all blocks have been placed directly on the table (not shown), the blocks-world:put-on method will move
the objects like this:
BLOCKS-WORLD> (put-on b1 b2) Move hand to pick up B1 at location (1 2). Grasp B1. Removing support relations between B1 and TABLE. Move B1 to top of B2 at location (2 2). Adding support relations between B1 and B2. Ungrasp B1. T
The different kinds of blocks
Movable blocks than can be moved onto load supporting blocks. Using multiple
inheritance, there are also blocks that can do both. height
name
position
supported-by
width
support-for
The basic-block class
Class blocks-world:basic-block
Superclasses:
common-lisp:standard-object, common-lisp:t
Documented Subclasses:
Direct Slots:
Slot Access Functions:
Details:
The superclass of all objects in the Blocks World (not including the hand). Subclasses of the blocks-world:basic-block class characterize
different kinds of objects, and have different properties.
They all have a name, given as the name slot and in the examples from the book, a global variable of that name is used to refer to them. Since this chapter is an explanation of CLOS, no specific constructor function is defined, and users may call make-instance directly.
They all have a name, given as the name slot and in the examples from the book, a global variable of that name is used to refer to them. Since this chapter is an explanation of CLOS, no specific constructor function is defined, and users may call make-instance directly.
2025-09-06
Generic Function blocks-world:block-name (instance)
Arguments:
Returns:
The symbol for the name.
Details:
Returns the name of the block.
In the examples from the book, a global variable of this name is used to refer to instance.
See also:
2025-09-06
Generic Function blocks-world:block-position (instance)
Arguments:
Returns:
The list of two integers for the position.
Details:
Returns the position of the block.
The position of a block is specified as a list of its x and y coordinates,
where the first axis runs along the table, and the second axis points upwards
towards the hand.
Together with the block's width and height, the position determines which parts of the world this block occupies. No other objects can be placed to an overlapping position.
Together with the block's width and height, the position determines which parts of the world this block occupies. No other objects can be placed to an overlapping position.
See also:
2025-09-06
Generic Function blocks-world:block-width (instance)
Arguments:
Returns:
The integer for the width.
Details:
Returns the width of the block.
The size of a block is specified as width and height, and determines which
parts of the world this block occupies. No other objects can be placed to an
overlapping position.
See also:
2025-09-06
Generic Function blocks-world:block-height (instance)
Arguments:
Returns:
The integer for the height.
Details:
Returns the height of the block.
The size of a block is specified as width and height, and determines which
parts of the world this block occupies. No other objects can be placed to an
overlapping position.
See also:
2025-09-06
Generic Function blocks-world:block-supported-by (instance)
Arguments:
Returns:
The blocks-world:basic-block instance, or nil.
Details:
Returns the block this instance has been placed onto.
All blocks except for the table sit on top of another block, which supports
them.
See also:
2025-09-06
The load-bearing-block class
Class blocks-world:load-bearing-block
Superclasses:
blocks-world:basic-block, common-lisp:standard-object, common-lisp:t
Documented Subclasses:
Direct Slots:
Slot Access Functions:
Details:
The superclass of objects in the Blocks World that other blocks can be
placed onto.
This class is mixed into most blocks, except for the blocks-world:wedge and the blocks-world:ball.
See also:
2025-09-06
Generic Function blocks-world:block-support-for (instance)
Arguments:
Returns:
The list of blocks-world:load-bearing-block instances for the
blocks.
Details:
Returns the blocks that have been placed onto this instance.
See also:
2025-09-06
The movable-block class
Class blocks-world:movable-block
Superclasses:
blocks-world:basic-block, common-lisp:standard-object, common-lisp:t
Documented Subclasses:
Direct Slots:
None
Details:
The superclass of objects in the Blocks World that can be moved by the
hand. This class is mixed into all blocks except for the blocks-world:table.
See also:
2025-09-06
Concrete block classes
These are the blocks found in our world.
Class blocks-world:table
Superclasses:
blocks-world:load-bearing-block, blocks-world:basic-block, common-lisp:standard-object, common-lisp:t
Documented Subclasses:
None
Direct Slots:
None
Details:
The table supporting the rest of the world.
The entire rest of the world sits on this table. The table itself cannot be
moved. For each world, this class is meant to be a singleton.
See also:
2025-06
Class blocks-world:brick
Superclasses:
blocks-world:movable-block, blocks-world:load-bearing-block, blocks-world:basic-block, common-lisp:standard-object, common-lisp:t
Documented Subclasses:
None
Direct Slots:
None
Details:
A useful movable building block with a flat top.
Because this block has a flat top, it supports other blocks.
See also:
2025-09-06
Class blocks-world:wedge
Superclasses:
blocks-world:movable-block, blocks-world:basic-block, common-lisp:standard-object, common-lisp:t
Documented Subclasses:
None
Direct Slots:
None
Details:
An interesting movable building block.
Because this block doesn't have a flat top, it cannot support other blocks.
See also:
2025-09-06
Class blocks-world:ball
Superclasses:
blocks-world:movable-block, blocks-world:basic-block, common-lisp:standard-object, common-lisp:t
Documented Subclasses:
None
Direct Slots:
None
Details:
The block is a sphere.
Because this block does not have a flat top, it cannot support other blocks.
See also:
2025-09-06
The hand
The hand is movable. It can hold at most one block. grasping
name
position
blocks-world:hand
Class blocks-world:hand
Superclasses:
common-lisp:standard-object, common-lisp:t
Documented Subclasses:
None
Direct Slots:
Slot Access Functions:
Details:
The hand that moves the world. This hand can be used to move every blocks-world:movable-block.
See also:
2025-09-06
Generic Function blocks-world:hand-name (instance)
Arguments:
Returns:
The symbol for the name of instance.
Details:
Returns the name of the hand.
Implementation note:
The hand is always called blocks-world::*hand*.
See also:
2025-09-06
Generic Function blocks-world:hand-position (instance)
Arguments:
Returns:
The list of two integers for the position.
Details:
Returns the position of the hand.
The position of a hand is specified as a list of its x and y coordinates,
where the first axis runs along the table, and the second axis points upwards
towards the hand.
See also:
Generic Function blocks-world:hand-grasping (instance)
Arguments:
Returns:
The movable-block instance, or nil.
Details:
Returns the block the hand is currently holding.
See also:
2025-09-06
Methods for the blocks world
Generic Function blocks-world:put-on (instance support)
Arguments:
Returns:
True on success.
Details:
Move block instance onto block support. Prints the steps taken and returns true or prints an error message and returns false.
See also:
2025-09-06
Generic Function blocks-world:get-space (instance support)
Arguments:
Returns:
Undocumented, but non-nil.
Details:
Find or make space on support for instance.
See also:
2025-09-06
Generic Function blocks-world:make-space (instance support)
Arguments:
Returns:
Undocumented, but non-nil.
Details:
Make space on support for object.
Takes all necessary actions to make space available.
See also:
2025-09-06
Function blocks-world:find-space (instance support)
Arguments:
Returns:
Undocumented or nil.
Details:
Find space on support for instance. Returns nil if no space could be found.
See also:
2025-09-06
Generic Function blocks-world:grasp (instance)
Arguments:
Returns:
The true value.
Details:
Grasps the block using the hand.
Makes sure to ungrasp the block currently grasped by the blocks-world:hand instance, if any.
See also:
2025-09-06
Generic Function blocks-world:ungrasp (instance)
Arguments:
Returns:
True on success.
Details:
Ungrasps the block if hand is holding it. Returns true if successful, or false if the blocks-world:hand instance did not hold this block. blocks-world:grasp
See also:
2025-09-06
Generic Function blocks-world:get-rid-of (instance)
Arguments:
Returns:
Unspecified
Details:
Moves instance onto the blocks-world:table instance.
See also:
2025-09-06
Generic Function blocks-world:clear-top (instance)
Arguments:
Returns:
False
Details:
Make space on top of this instance. Removes all blocks instance is supporting.
See also:
2025-09-06
Generic Function blocks-world:add-support (instance support)
Arguments:
Returns:
True
Details:
Note that instance has been put onto support. This function maintains the supported-by and block-support-for slots.
See also:
2025-09-06
Generic Function blocks-world:remove-support (instance)
Arguments:
Returns:
True
Details:
Note that instance has been taken from support. This function maintains the supported-by and support-for slots.
See also:
2025-09-06
Generic Function blocks-world:move (instance support)
Arguments:
Returns:
True
Details:
Move block instance onto block support. This is a helper function for the blocks-world:put-on function.
See also:
2025-09-06
Package blocks-world-goals
This package contains the source code of chapter 22, "Answering Questions about Goals" from Lisp (3rd edition) by Winston
and Horn.
Lots of undocumented functions
I was too lazy to document this package, which is why all its functions
have a big fat "undocumented" warning. This package's page also looks
rather empty and sad.
Other Functions in blocks-world-goals
Function blocks-world-goals:find-action (given-form &optional node)
No documentation string. Possibly unimplemented or incomplete.
Function blocks-world-goals:show-simple-tree (node &optional indentation)
No documentation string. Possibly unimplemented or incomplete.
Other Macros in blocks-world-goals
Macro blocks-world-goals:define-history-method (name parameters &rest body)
No documentation string. Possibly unimplemented or incomplete.
Macro blocks-world-goals:tell-why (name &rest parameters)
No documentation string. Possibly unimplemented or incomplete.
Other Classes in blocks-world-goals
Class blocks-world-goals:node
Superclasses:
common-lisp:standard-object, common-lisp:t
Documented Subclasses:
None
Direct Slots:
No documentation string. Possibly unimplemented or incomplete.
Other Variables in blocks-world-goals
Variable blocks-world-goals:*current-node*
No documentation string. Possibly unimplemented or incomplete.
Index of Exported Symbols
blocks-world: | add-support, Generic Function |
blocks-world: | ball, Class |
blocks-world: | basic-block, Class |
blocks-world: | block-height, Generic Function |
blocks-world: | block-name, Generic Function |
blocks-world: | block-position, Generic Function |
blocks-world: | block-support-for, Generic Function |
blocks-world: | block-supported-by, Generic Function |
blocks-world: | block-width, Generic Function |
blocks-world: | brick, Class |
blocks-world: | clear-top, Generic Function |
blocks-world: | find-space, Function |
blocks-world: | get-rid-of, Generic Function |
blocks-world: | get-space, Generic Function |
blocks-world-goals: | *current-node*, Variable (undocumented) |
blocks-world-goals: | attach-action, Generic Function (undocumented) |
blocks-world-goals: | attach-parent, Generic Function (undocumented) |
blocks-world-goals: | define-history-method, Macro (undocumented) |
blocks-world-goals: | find-action, Function (undocumented) |
blocks-world-goals: | node, Class (undocumented) |
blocks-world-goals: | node-action, Generic Function (undocumented) |
blocks-world-goals: | node-children, Generic Function (undocumented) |
blocks-world-goals: | node-parent, Generic Function (undocumented) |
blocks-world-goals: | show-simple-tree, Function (undocumented) |
blocks-world-goals: | tell-why, Macro (undocumented) |
blocks-world: | grasp, Generic Function |
blocks-world: | hand, Class |
blocks-world: | hand-grasping, Generic Function |
blocks-world: | hand-name, Generic Function |
blocks-world: | hand-position, Generic Function |
blocks-world: | load-bearing-block, Class |
blocks-world: | make-space, Generic Function |
blocks-world: | movable-block, Class |
blocks-world: | move, Generic Function |
blocks-world: | put-on, Generic Function |
blocks-world: | remove-support, Generic Function |
blocks-world: | table, Class |
blocks-world: | ungrasp, Generic Function |
blocks-world: | wedge, Class |