The Revised Maclisp ManualThe PitmanualPage A-13
Published by HyperMeta Inc.
 
Prev | Index | Next
[Blue Marble]
Climate Change
Is incremental change enough?


Hunks


HunkConceptComposite Data Object

[PDP-10 Only] A hunk is a first class, composite data object similar in many ways to a cons-cell. Where conses can only hold two objects (a car and cdr), however, hunks can generally hold more.

Hunks come in a variety of types: HUNK2, HUNK4, HUNK8, HUNK16, HUNK32, HUNK64, HUNK128, HUNK256, and HUNK512. Although a hunk of any size up to 512 may be created, it will always be built out of one of these standard types. As might be expected, a HUNK2 takes exactly 1 word of storage, a HUNK4 takes exactly 2, and so on.

The number of active slots in a hunk is called the hunksize of a hunk. No primitives are provided for adjusting the hunksize of an already-consed hunk. A 5-length hunk would be created in HUNK8 space, taking exactly 4 words of storage. The HUNKSIZE primitive on such a hunk will return 5, even though its datatype (as returned by TYPEP) is HUNK8. A 6 or 7-length hunk would also be allocated storage in HUNK8 space and would take up the same amount of room. The unused slots in an odd-length hunk go to waste.

There is a special predicate, HUNKP, which responds T for objects whose datatype is one of the hunk types.

A slot in a hunk is called a cxr (pronounced “COOK-sir”). A particular cxr of a hunk is addressed by a single fixnum index.

Hunks also have a read/print syntax similar to that of lists. A hunk is displayed with parentheses bounding it and a dot after every element. e.g., (A .), (A . B .), (A . B . C .) are valid printed representations. The order of display of hunk slots is historical in nature. For better or worse, the elements of a hunk display in order except that the 0th element is last, not first. e.g., for a hunk of a length n+1, (cxr1 . cxr2 . ... . cxrn . cxr0 .). Whether or not this syntax is accepted by the reader is controlled by the variable MAKHUNK -- by default it is accepted by the reader. The functions CAR and CDR are defined on hunks, though the meaning of such operations may be less than intuitive. In particular, (CAR hunk) is the same as (CXR 1 hunk). (CDR hunk) is the same as (CXR 0 hunk). The remaining elements of a hunk, those not addressable by CAR and CDR, are sometimes called the middle of the hunk, because they appear in the middle of the printed representation. Note also that CAR extracts the leftmost element of a hunk, just as it addresses the leftmost element of a cons. Similarly, CDR extracts the rightmost element of hunks and conses.

The cdr of a hunk can also be its plist. Since all hunks have a cxr-0 slot, all hunks have a plist. (Note that the operation CAR is undefined on hunk-1's, but CDR is not.) This means that if you want to make a plist for a hunk of your own, you can use its cdr as a hunk; it does not mean that you can blindly assume that any hunk wants its CDR treated that way. The exact use of the slots of a hunk is up to the creator; it's a good idea to mark your hunks (e.g., by placing a distinctive object in their cxr-1 slot) so that you can tell them from hunks created by other programs.

Like lists, hunks may be inhomogeneous collections of data. Any hunk slot may contain an object of any datatype.

Certain hunks can be made to be treated specially by various aspects of the Maclisp system in order to implement the extended datatypes. This section deals only with general information about hunks. Magic incantations for making hunks behave like extended datatypes will be discussed elsewhere.

Switches Controlling Hunks


MAKHUNKValueT

[PDP-10 Only] If this switch is NIL, the reader syntax for hunks is disabled. This is for people who never use the hunk input syntax and want to get a "DOT CONTEXT ERROR" message when they misplace dots.

Also, if this switch is NIL, HUNK2's will not be generated --- conses will be used instead.

It is recommended that this switch not be reset in production quality programming environments since some major system libraries may be broken if HUNK of 1 or 2 args returns cons cells instead of HUNK2's.


HUNKPValueT

[PDP-10 Only] If the value of HUNKP is not NIL, hunks should be treated differently than lists by the system. This affects things like EQUAL, SUBST, PURCOPY, etc. --- even PRINT.

This switch is for compatibility with very old code which wanted to allow hunks to masquerade as lists.

Hunk Creation/Manipulation


HUNKFunction(HUNK q1 q2 q3 ... qn q0)

[PDP-10 Only] Creates a hunk big enough to hold all the given slot values. If no values are given, NIL is returned.

Note that the 0th slot is taken as the last object (and displayed as the last element). All other slots are displayed in order (1-n) preceding that slot. (For more information about this, see `concept' documentation on HUNK.)

Examples:

(HUNK)		=>	NIL
(HUNK 'A)	=>	(A .)
(HUNK 'A 'B 'C)	=>	(A . B . C .)

MAKHUNKFunction(MAKHUNK i)

[PDP-10 Only] The argument, i, should be fixnum. Returns a hunk of that size. All i slots of the resulting hunk will contain NIL's. If size is 0, NIL is returned.

Examples:

(MAKHUNK 0)	=>	NIL
(MAKHUNK 1)	=>	(NIL .)
(MAKHUNK 5)	=>	(NIL . NIL . NIL . NIL . NIL .)

HUNKPFunction(HUNKP q)

[PDP-10 Only] Predicate returns T if q is a hunk, and NIL otherwise.

Examples:

(HUNKP '(A . B . C . D . E.))				=> T
(HUNKP (HUNK 'A 'B 'C))					=> T
(HUNKP 3.)						=> NIL
(HUNKP NIL)						=> NIL
(HUNKP '(A B C))					=> NIL
(HUNKP (LET ((MAKHUNK NIL)) (HUNK 'A)))			=> NIL
(HUNKP (LET ((MAKHUNK NIL)) (HUNK 'A 'B)))		=> NIL
(HUNKP (LET ((MAKHUNK NIL)) (HUNKP (HUNK 'A 'B 'C))))	=> T

HUNKSIZEFunction(HUNKSIZE hunk)

[PDP-10 Only] Returns number of slots in a hunk (not to be confused with amount of space required to store the hunk).

Note: This information is not stored in the hunk, so HUNKSIZE must count the number of active slots.

Examples:

(HUNKSIZE '(A .))	=>	1
(TYPEP '(A .))		=>	HUNK2
(HUNKSIZE '(A))		=>	error! ;(A) NOT A HUNK - HUNKSIZE
(HUNKSIZE (MAKHUNK 5))	=>	5

CXRFunction(CXR i h)

[PDP-10 Only] Retrieves the ith slot of a given hunk, h. i must be a non-negative fixnum less than the hunksize of h.

Examples:

(CXR 0 '(A . B . C .))	=>	C
(CXR 1 '(A . B . C .))	=>	A
(CXR 2 '(A . B . C .))	=>	B
(CXR 3 '(A . B . C .))	=>	error! ;3 BAD HUNK INDEX

RPLACXFunction(RPLACX i h object)

[PDP-10 Only] Changes CXR i of h to be object. Returns the changed hunk. i must be a non-negative fixnum less than the hunksize of h.

Examples:

(SETQ A (MAKHUNK 3))	=>	(NIL . NIL . NIL .)
(RPLACX 0 A 'FOO)	=>	(NIL . NIL . FOO .)
(RPLACX 2 A 'BAR)	=>	(NIL . BAR . FOO .)

[Blue Marble]
Climate Change
How does Climate Change affect the spread of disease?

The Revised Maclisp Manual (Sunday Morning Edition)
Published Sunday, December 16, 2007 06:17am EST, and updated Sunday, July 6, 2008.
Prev | Index | Next