Page Numbers: Yes First Page: 1
Heading:
September 15, 1977 10:33 AM[IVY]<KRL>document>match-full-imp-util
Status: first pass
Utility functions for the KRL-1 matcher
These are functions I generated or found the need for in doing the matcher which seemed of general use to everyone. We may want to make some of them into macros.
# # # # # # # # # # # # # # #
[AddCopyToAnchor (descr anchor meta)
(PROG((spaceNameHandle (ConstantHandle)))
(* this does not copy the metaDescription, but puts in a new one if given)

(newDescr ← (KrlCopyAll descr (SpaceName anchor spaceNameHandle)))
(if meta
then (storeMem newDescr metaAnchor (KrlCopy meta spaceNameHandle))
else (ClearMem descr metaAnchor))
(IncludeHandle newDescr anchor descrs)
(RETURN newDescr]
[AddLispPointerToAnchor (pointer anchor meta)
(* adds a single LispPointer descriptor to the anchor, with contents = pointer)
(HELP "not written"]
[CleanAnchor (anchor)
(* removes all descriptors from the anchor)
(HELP "not written]
[ClearMem (handle field)
(* resets the field to the null handle (all zeroes))
(HELP "Not written"]
[ComparePost (desc1 desc2)
(* takes any two descriptors, checks to see if they give posts, and if so returns
SAME or DIFFERENT returns NIL if one or both weren’t post-determining
descriptors)

(PROG((type1 ← (TypeD desc1))
(tempHandle1 (ConstantHandle))
(tempHandle2 (ConstantHandle)))
(SELECTQ type1
(Coreference (OR (IsPrimaryCoreference desc1) (RETURN NIL))
((KrlPointer CharacterString LispPointer))
(RETURN NIL))
(RETURN
(SELECTQ (TypeD desc2)
(Coreference (if (IsPrimaryCoreference desc2)
then (if (AND (EQ type1 ’Coreference)
(EQH (FetchMem desc1 coref tempHandle1)
(FetchMem desc2 coref tempHandle2)))
then ’SAME else ’DIFFERENT)
else NIL))
(LispPointer
(if (AND (EQ type1 ’LispPointer)
(EQUAL (LispContentsOf desc1)(LispContentsOf desc2)))
then ’SAME else ’DIFFERENT))
(KrlPointer
(if (AND (EQ type1 ’KrlPointer)
(EQH (GetDirectPointer desc1 tempHandle1)
(GetDirectPointer desc2 tempHandle2)))
then ’SAME else ’DIFFERENT))
NIL)]
[ConstantHandle ()
(* always returns a handle, for any calling form, a new handle is generated the
first time it is evaluated, and the same handle returned each subsequent time)
(HELP "Not written"]
[FocusSlot (mapDescriptor oldHandle)
(* returns a handle to the focus slot template anchor. uses oldHandle if given.
error if arg is not a mapDescriptor.)
(HELP "Not written"]
[GetCategories (descriptor)
(* takes any post or map descriptor as input. Returns ??. There are some kind of
standard categories for LISP and KRL objects. for a map descriptor, returns
categories for the focus slot)
(HELP "Not written"]
[GetContingentDescription (descriptor oldHandle)
(* descriptor must be an interpreted map descriptor with functional = During
otherwise error. Returns handle to the second argument using oldHandle if given)
(HELP "Not written"]
[GetDirectPointer (descriptor oldHandle)
(PROG(handle)
(handle ← (if oldHandle
then (FetchMem descriptor handle oldHandle)
else (FetchMem descriptor handle)))
(if (FetchMem descriptor Indirect)
then (handle ← (FetchMem handle namedStructure handle)))
(RETURN handle]
[GetDoFiller (mapDescriptor)
(* mapDescriptor must be based on unit for Do functional, or else error.
value returned is the lisp form which is the argument to Do)
(HELP "Not written"]
[GetInterpretedArg (descriptor oldHandle)
(* descriptor must be an interpreted map descriptor, not During or Using,
otherwise error. Returns handle to the argument using oldHandle if given)
(HELP "Not written"]
[GetMetaDescription (handle oldHandle)
(* handle must be to a descriptor or anchor, else error. Returns NIL if there
is none, uses oldHandle if given)
(HELP "Not written"]
[GetPosition (sequence integer oldHandle)
(* Henry should define this. It should return the handle to the element
in the sequence (i.e. the file position actually in the variable length field)
and should take into account gaps (... forms) and return NIL if
no such position can be found, or ’END if the number is precisely one
greater than the number of elements and there are no gaps)
(HELP "Not defined"]
[GetPost (descriptor oldHandle)
(* this assumes that the caller has already checked to see that a Coreference
is indeed primary, since it needs to be able to pass back NIL as a real
LispContents value. Also note that it passes back the whole KRLPointer
descriptor, as is the convention for posts)

(SELECTQ (TypeD descriptor)
(Coreference (if oldHandle then (FetchMem desc coref oldHandle)
else (FetchMem desc coref)))
(LispPointer (LispContents descriptor))
(KrlPointer descriptor)
(HELP "GetPost -- bad descriptor type"]
[GetTraps (trapName anchorHandle)
(* returns a list of lisp forms)
(HELP "Not written"]
[GetTriggers (triggerName slotAnchorHandle)
(* theis needs to reflect the further specification thing right)
(HELP "Not written"]
[GetWorld (descriptor oldHandle)
(* descriptor must be an interpreted map descriptor with functional = During
otherwise error. Returns handle to the first argument using oldHandle if given)
(HELP "Not written"]
[HasNoDescriptors (anchor)
(* arg must be handle to anchor. Returns T if true)
(HELP "Not written"]
[HasSingleDescriptor (anchor oldHandle)
(* arg must be handle to anchor. Returns handle to the descriptor slot if true,
using oldHandle if given)
(HELP "Not written"]
[HasSlots (mapDescriptor)
(* arg must be handle to map descriptor. Returns T if true)
(HELP "Not written"]
[HasUniqueFocus (mapDescriptor oldHandle)
(* arg must be handle to map descriptor. Returns handle to the focus slot if true,
using oldHandle if given)
(HELP "Not written"]
[IsHandle (arg)
(* returns T for anchor, descriptor, characterString, etc.)
(IsType? arg ’KrlFileHandle]
[IsPrimaryCoreference (descriptor)
(* T if true, error if not a decriptor handle at all)
(HELP "Not written"]
[IsSelfAnchor (anchor)
(* true if it is a labelled anchor with slot name = self. error if not an anchor handle)
(HELP "Not written"]
[KrlCopy (handle space)
(* copies contents of handle down one level (i.e. a single descriptor, anchor, etc.))
(HELP "Not written"]
[KrlCopyAll (handle space)
(* copies contents of handle down all the way, bottoming out at handles to labelled
anchors, lisp PseudoHandles, CharacterString handles, and local name table entries.)
(HELP "Not written"]
[PrototypeName (handle)
(* Returns an atom. handle is a MapDescriptor or InterpretedMapD, otherwise error)
(HELP "Not written"]
[SameCoreference (desc1 desc2)
(* checks to see if desc1 and desc2 are coreferences to the same anchor. This is
used instead of (EQH (FetchMem coref desc1)(FetchMem coref desc2))
because it doesn’t have to generate new handles for the anchors pointed to.
Error if both descriptors aren’t coreferences)
(HELP "Not written"]
[SameFocusSlot (desc1 desc2)
(* like SameCoreference, except checks focus slots of two map descriptors)
(HELP "Not written"]
[TypeD (handle)
(* Error unless handle is to a descriptor. Returns one of the atoms:
(Collection Coreference Ellipsis InterpretedMapD KrlPointer LispPointer
MapDescriptor Reflexive))
(HELP "Not written")]
[TypeI (handle)
(* Error unless handle is to an interpreted MapDescriptor. Returns one of the atoms:
(Always Contains Currently Default During Member Not Or SequenceOf
SetOf Using))
(HELP "Not written")]
[TypeK (arg)
(* Takes any argument. Returns one of the atoms:
(Unit Anchor LocalNamePair Descriptor Lisp CharacterString)
Lisp is returned for anything which isn’t a handle)
(HELP "Not written")]