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

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), put-on 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.

Class basic-block
Superclasses:
common-lisp:standard-object, sb-pcl::slot-object, common-lisp:t
Documented Subclasses:
Slot Access Functions:
Details:
The superclass of all objects in the Blocks World (not including the hand).

Subclasses of basic-block characterize different kinds of objects, and have different properties.

They all have a name, given as block-name 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.


Class load-bearing-block
Superclasses:
basic-block, common-lisp:standard-object, sb-pcl::slot-object, common-lisp:t
Documented Subclasses:
Slot Access Functions:
Inherited 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 wedge and the ball.

See also:

Class movable-block
Superclasses:
basic-block, common-lisp:standard-object, sb-pcl::slot-object, common-lisp:t
Documented Subclasses:
Inherited Slot Access Functions:
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 table.
See also:

Block properties

Slot readers:

Function block-name (instance)
Arguments:
Returns:
a symbol
Details:
Returns the block's name, a symbol.

In the examples from the book, a global variable of this name is used to refer to instance.
See also:

Function block-position (instance)
Arguments:
Returns:
a list of two integers
Details:
Returns the block's position.

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.

See also:

Function block-width (instance)
Arguments:
Returns:
an integer
Details:
Returns the block's width.

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:

Function block-height (instance)
Arguments:
Returns:
an integer
Details:
Returns the block's height.

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:

Function block-supported-by (instance)
Arguments:
Returns:
nil, or a block
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:

Function block-support-for (instance)
Arguments:
Returns:
a list of blocks
Details:
Returns the blocks that have been placed onto this instance.

See also:

Concrete block classes

These are the blocks found in our world:

Class table
Superclasses:
load-bearing-block, basic-block, common-lisp:standard-object, sb-pcl::slot-object, common-lisp:t
Documented Subclasses:
None
Inherited Slot Access Functions:
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.

Class brick
Superclasses:
movable-block, load-bearing-block, basic-block, common-lisp:standard-object, sb-pcl::slot-object, common-lisp:t
Documented Subclasses:
None
Inherited Slot Access Functions:
Details:
A useful movable building block with a flat top.

Because this block has a flat top, it supports other blocks.

Class wedge
Superclasses:
movable-block, basic-block, common-lisp:standard-object, sb-pcl::slot-object, common-lisp:t
Documented Subclasses:
None
Inherited Slot Access Functions:
Details:
An interesting movable building block.

Because this block doesn't have a flat top, it cannot support other blocks.

Class ball
Superclasses:
movable-block, basic-block, common-lisp:standard-object, sb-pcl::slot-object, common-lisp:t
Documented Subclasses:
None
Inherited Slot Access Functions:
Details:
The block is a sphere.

Because this block doesn't have a flat top, it cannot support other blocks.

The hand

The hand is movable. It can hold at most one block.

Class hand
Superclasses:
common-lisp:standard-object, sb-pcl::slot-object, common-lisp:t
Documented Subclasses:
None
Slot Access Functions:
Details:
The hand that moves the world.

This hand can be used to move every movable-block.

See also:

Function hand-name (instance)
Arguments:
Returns:
a symbol
Details:
Returns the hand's name, a symbol.

The hand is always called blocks-world::*hand*.
See also:

Function hand-position (instance)
Arguments:
Returns:
a list of two integers
Details:
Returns the hand's position.

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:

Function hand-grasping (instance)
Arguments:
Returns:
a movable-block, or nil
Details:
Returns the block the hand is currently holding.
See also:

Other functions in blocks-world

Function add-support (object support)
Arguments:
Returns:
a boolean
Details:
Note that object has been put onto support.

This function maintains the slots block-supported-by and block-support-for.
See also:

Function clear-top (support)
Arguments:
Returns:
nil
Details:
Make space on top of this object.

Removes all blocks support is supporting.

See also:

Function get-rid-of (object)
Arguments:
Returns:
unspecified
Details:
Moves object onto the table.

See also:

Function get-space (object support)
Arguments:
Returns:
undocumented, but non-nil
Details:
Find or make space on support for object.

See also:

Function grasp (object)
Arguments:
Returns:
t
Details:
Grasps the block using the hand.

Makes sure to ungrasp the block currently grasped by the hand, if any.

See also:

Function make-space (object support)
Arguments:
Returns:
undocumented, but non-nil
Details:
Make space on support for object.

Takes all necessary actions to make space available.

See also:

Function move (object support)
Arguments:
Returns:
a boolean
Details:
Move block object onto block support.

This is a helper function for put-on.
See also:

Function put-on (object support)
Arguments:
Returns:
a boolean
Details:
Move block object onto block support.

Prints the steps taken and returns T or prints an error message and returns nil.

See also:

Function remove-support (object)
Arguments:
Returns:
a boolean
Details:
Note that object has been taken from support.

This function maintains the slots block-supported-by and block-support-for.
See also:

Function ungrasp (object)
Arguments:
Returns:
a boolean
Details:
Ungrasps the block if hand is holding it.

Returns t if successful, or nil if the hand didn't hold this block.

See also:

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 attach-action (node action)

No documentation string. Possibly unimplemented or incomplete.


Function attach-parent (child parent)

No documentation string. Possibly unimplemented or incomplete.


Function find-action (given-form &optional (node *current-node*))

No documentation string. Possibly unimplemented or incomplete.


Function node-action (object)

No documentation string. Possibly unimplemented or incomplete.


Function node-children (object)

No documentation string. Possibly unimplemented or incomplete.


Function node-parent (object)

No documentation string. Possibly unimplemented or incomplete.


Function show-simple-tree (node &optional (indentation 0))

No documentation string. Possibly unimplemented or incomplete.


Other macros in blocks-world-goals

Macro define-history-method (name parameters &rest body)

No documentation string. Possibly unimplemented or incomplete.


Macro tell-why (name &rest parameters)

No documentation string. Possibly unimplemented or incomplete.


Other classes in blocks-world-goals

Class node
Superclasses:
common-lisp:standard-object, sb-pcl::slot-object, common-lisp:t
Documented Subclasses:
None

No documentation string. Possibly unimplemented or incomplete.


Other variables in blocks-world-goals

Variable *current-node*

No documentation string. Possibly unimplemented or incomplete.


Index of exported symbols

blocks-world-goals:*current-node*, variable  (undocumented)
blocks-world:add-support, function
blocks-world-goals:attach-action, function  (undocumented)
blocks-world-goals:attach-parent, function  (undocumented)
blocks-world:ball, class
blocks-world:basic-block, class
blocks-world:block-height, function
blocks-world:block-name, function
blocks-world:block-position, function
blocks-world:block-support-for, function
blocks-world:block-supported-by, function
blocks-world:block-width, function
blocks-world:brick, class
blocks-world:clear-top, function
blocks-world-goals:define-history-method, macro  (undocumented)
blocks-world-goals:find-action, function  (undocumented)
blocks-world:get-rid-of, function
blocks-world:get-space, function
blocks-world:grasp, function
blocks-world:hand, class
blocks-world:hand-grasping, function
blocks-world:hand-name, function
blocks-world:hand-position, function
blocks-world:load-bearing-block, class
blocks-world:make-space, function
blocks-world:movable-block, class
blocks-world:move, function
blocks-world-goals:node, class  (undocumented)
blocks-world-goals:node-action, function  (undocumented)
blocks-world-goals:node-children, function  (undocumented)
blocks-world-goals:node-parent, function  (undocumented)
blocks-world:put-on, function
blocks-world:remove-support, function
blocks-world-goals:show-simple-tree, function  (undocumented)
blocks-world:table, class
blocks-world-goals:tell-why, macro  (undocumented)
blocks-world:ungrasp, function
blocks-world:wedge, class