Page Numbers: Yes First Page: 1
Heading:
October 6, 1977 12:36 AM[IFS]<KRL>code>alignClasses.bravo
# # # # # # # # # # # # # # #
[GoalClassPrototype ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP (* self is a the goal. value isn’t used)
(STARTUP (* self is the goal. Returns OK if initial descriptors are to be passed
through as NEWDESCRIPTOR, SKIP otherwise))
(NEWDESCRIPTOR
(* self is the goal. descriptor context world and fullContext are bound.
value isn’t used))
(NEWLINK (* self is the goal, link is bound Returns PASS if link is
to be passed down to subgoals, OK if link
is to be added to this goal only, SKIP otherwise))
(AFTERFIRST (* self is the goal))
(DESCRIBE (* self is goal. sent after first try, message is passed downward)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignAnchor ((self Goal)(message GoalMessage))
(* this is a function for a goal type -- goalargs used for map template if anchor is filler)
(SELECTQ message
(SETUP

(DPROG ((goal NIL Goal)
(meta (FetchMem self:goalDesc metaAnchor) (ONEOF Anchor NIL))
(doArg NIL (ONEOF BindingForm ActionForm))
(actions NIL (LISTP OF Action)))
(DECL ((alignEnvironment STACKP (BOUNDIN FullAlign))))

(self:goalType ← ’AlignAnchor)

(for descr fromField descrs ofHandle self:goalDesc
do (if self:suspended
then (RETURN)
else (goal ← (CREATE Goal
goalDesc ← descr
patternContext ← self:patternContext
datum ← self:datum
datumContext ← self:datumContext
parent ← self
resultType ← ’ConjunctiveSubgoal
links ← self:links
anchorPath ← self:anchorPath)
(* goalType will be filled in by SETUP action)
(SetUpGoalForDescriptor goal descr self)))

(if self:suspended then (RETURN))

(if meta
then (for metaDescriptor fromField descrs ofHandle meta
do (if self:suspended
then (RETURN)
elseif (OR (NEQ ’InterpretedMapD (TypeD metaDescriptor))
(NEQ ’Do (TypeI metaDescriptor))
(NOT (doArg ← (GetInterpretedArg metaDescriptor))))
then (MSignal UnknownMetaOnPatternAnchor
(OK (RETURN (* from loop through metadescriptors)))
(PROGN (GoalDone self ’FAILED)
(RETFROM AlignAnchor))))
(if (FMEMB doArg:1 ’(Bind BindElement))
then (goal ← (MakeNewFindGoal self doArg))
(SetUpGoal goal self)
else (PUSH actions (Create Action
actionForm ← doArg
actionBinding ← self:anchorPath))))
(if self:suspended
then (RETURN self)
elseif actions
then (self:immediateResults ←
(OR (for result in self:immediateResults
collect (CREATE Result
actions ← (if result:actions
then <! actions ! result:actions>
else actions)
bindings ← result:bindings))
<(CREATE Result actions ← actions)>)))

(if (NOT self:children)
then (self:results ← self:immediateResults)
(GoalDone self ’SUCCEEDED)))))

(STARTUP ’OK)
(AFTERFIRST ’OK)
(NEWDESCRIPTOR
(if (AND (EQ (TypeD descriptor) ’InterpretedMapD)
(EQ (TypeI descriptor) ’Not))
then (MSignal InvertingNotInDatum
(OK (* invert pattern and datum, and result sense)))))
(NEWLINK ’PASS)
(DESCRIBE (for child in self:children
do (SendMessage child:goalType child ’DESCRIBE)))
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignCoreference ((self Goal)(message GoalMessage))
(* this is a function for a goal type -- for non-POST coreferences )

(SELECTQ message
(SETUP
(for desc descriptorOf self:datum
when (AND (EQ (TypeD desc) ’Coreference)
(SameCoreference desc self:goalDesc))
do (CheckDescriptorMeta self desc)
(GoalDone self ’SUCCEEDED)))
(DESCRIBE
(AddAction self ’#AddToList (KrlCopy self:goalDesc) NIL ’AddDescriptor)
(GoalDone self ’SUCCEEDED)))
(STARTUP
(OR structuralMatch
(MSignal UsingCategoriesForPatternCoreference
(OK (self:patCategories ←
(GetCategories
(FetchMem self:goalDesc coref (ConstantHandle))))))
’OK)
(NEWDESCRIPTOR
(SELECTQ type
(Coreference (if (SameCoreference self:goalDesc descriptor)
then (GoalDone self ’SUCCEEDED)))
(InterpretedMapD
(CheckSimpleNot descriptor type self:goalDesc self))
NIL))
(AFTERFIRST
(if (NOT structuralMatch)
then (TriggerToFind self (CREATE Link
structure ← (FetchMem goal:goalDesc coref)
fullContext ←
(Create FullContext
world ← goal:patternContext:world
context ← NIL)))
(MSignal FollowingCoreferenceInPattern
(OK (DPROG((goal (CREATE Goal
goalType ← ’FindPost
resultType ← ’FindForCoreference
parent ← self
goalDesc ← NIL
datum ← (FetchMem self:goalDesc coref)
datumContext ← self:patternContext))
Goal))
(if (SetUpGoal goal self)
then (StartUpGoal goal))))))
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignContains ((self Goal)(message GoalMessage))
(* this is a function for a goal type -- it shoud be combined with the set and sequence stuff)
(SELECTQ message
(SETUP)
(STARTUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignContingency ((self Goal)(message GoalMessage))
(* this is a function for a goal type. It will never get set up for a structural match)
(SELECTQ message
(SETUP
(DPROG ((desc NIL Descriptor)
(newWorld
(SELECTQ (TypeI self:goalDesc)
(During (GetContingentWorld self:goalDesc
self:patternContext:world))
(KHelp UnknownContingencyType)))
Anchor)
(anchor (GetContingentDescription self:goalDesc) Anchor)
THEN (compatible (CompatibleWorld self:datumContext:world newWorld)
FLAG)
THEN (goal (CREATE Goal
goalType ← ’AlignAnchor
goalDesc ← anchor
patternContext ←
(CREATE FullContext
context ← self:patternContext:context
world ← newWorld)
datum ← (AND compatible self:datum)
datumContext ← self:datumContext
links ← (if (NOT compatible)
then <(CREATE Link
structure ← self:datum
fullContext ← self:datumContext)>)
anchorPath ← (AND compatible self:anchorPath)
parent ← self
resultType ← ’EquivalentGoal)
Goal))
(SetUpGoal goal self)))
(STARTUP ’SKIP)
(AFTERFIRST (self:goalStatus ← ’WAITING))
(NEWDESCRIPTOR (KHelp "Align contingency shouldn’t be ACTIVE" goal))
(NEWLINK ’PASS)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignMapDescMulti ((self Goal)(message GoalMessage))
(* this is a function for a goal type.. GoalArgs is a list of mapdescriptors which have been tried but set up no goal (either quick success or quick failure))
(SELECTQ message
(SETUP
(DPROG((type (TypeD self:goalDesc) (MEMQ MapDescriptor InterpretedMapD))
(patMapd (self:goalDesc) Descriptor))
(* MapDescriptor has already looked for quick reject and quick match if no slots are involved)
(for datDesc descriptorOf self:datum
when (AND (EQ (TypeD datDesc) type)
(SameFocusSlot datDesc patMapD))
do (if self:suspended then (RETURN))
(SetUpOneOf self (CopyHandle datDesc) NIL))
(STARTUP ’OK)
(DESCRIBE
(DPROG ((goal (for child in self:children
thereis (HasNoSlots child:goalArgs:1))
(ONEOF Goal NIL))
(desc NIL MapDescriptor))
(if (NOT goal)
then (desc ← (EmptyMapD self:goalDesc self:datum))
(SetUpOneOf self desc T)
(goal ← self:children:1)
(AddAction self ’#AddToList desc NIL ’AddDescriptor))
(SendMessage ’AlignMapDescOneOf goal ’DESCRIBE)))
(AFTERFIRST
(if (NOT structuralMatch)
then (TriggerToMatch self (AND (OR self:children self:goalArgs) T))))
(NEWDESCRIPTOR
(DPROG((patDesc self:goalDesc Descriptor) (goal NIL Goal))
(if (AND (NOT (KMemb descriptor self:goalArgs))
(EQ (TypeD descriptor) (TypeD patDesc))
(SameFocusSlot descriptor patDesc))
(NOT (for child in self:children
thereis (EQH child:datum descriptor))))
then (SetUpOneOf self descriptor T)
else (CheckSimpleNot descriptor type self:goalDesc self))))
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignMapDescOneOf ((self Goal)(message GoalMessage))
(* this is a function for a goal type -- goalArgs is CONS the specific datum mapD to align
with T if unique focus. anchorPath if present has a mapDescriptor on top)
(SELECTQ message
(SETUP
(DPROG((patMapD self:goalDesc MapDescriptor)
(datMapD self:goalArgs:1 MapDescriptor)
(goal NIL Goal)
THEN(focusSlot (FetchMem patMapD focusSlot (ConstantHandle)) SlotAnchor)
(prototype (FetchMem patMapD prototype) SlotAnchor)
THEN(unique (self:goalArgs::1) BOOL)
(fullContext
(CREATE FullContext
context ←
(CREATE Context
prototype ← prototype
instance ← (if (EQH focusSlot prototype)
then self:datum
else datMapD)
world ← self:datumContext:world)
FullContext))
(for pTemp fromField templateAnchors ofHandle patMapD
as pInst fromField instanceAnchors ofHandle patMapD
when (NOT self:suspended)
do (pTemp ← (CopyHandle pTemp))
(DPROG ((links
<(CREATE Link
structure ← pTemp
fullContext ← fullContext)>
(LST OF Link)
(* this is the link to get stuff from the prototype. also used for triggering)))
(if (EQH pTemp focusSlot)
then (* this is a case like "The x from a Foo with x =")
(PUSH links (CREATE Link
structure ← self:datum
context ← self:datumContext)))
(for dTemp fromField templateAnchors ofHandle datMapD
as dInst fromField instanceAnchors ofHandle datMapD
when (EQH dTemp pTemp)
do (SetUpAnchorGoal self
(CopyHandle pInst)
(CopyHandle dInst)
links
pTemp)
(RETURN (* from loop through datum pairs))
finally (* no pair was found in the datum)
(if canMatch
then (* just ignore this pattern slot and go on)
elseif (OR structuralMatch describe)
then (GoalDone self ’FAILED)
(RETFROM AlignMapDescOneOf)
else (SetUpAnchorGoal self (CopyHandle pInst) NIL links)))
(if (AND (NOT self:suspended) (NOT self:children))
then (self:results ← self:immediateResults)
(CheckDescriptorMeta self datMapD)
(GoalDone self ’SUCCEEDED))))

(STARTUP (if self:goalArgs::1 then ’OK else ’SKIP))
(AFTERFIRST (self:goalStatus ←
(if self:goalArgs::1 then ’ACTIVE else ’WAITING)))
(NEWDESCRIPTOR
(DPROG((path self:anchorPath (LST OF DHandle))
(desc NIL Descriptor))
(if (NOT self:goalArgs::1)
then (KHelp "AlignMapDescOneOf shouldn’t be active" self)
elseif (AND (NOT (EQH descriptor self:goalArgs:1)
(EQ (TypeD descriptor) ’MapDescriptor)
(SameFocusSlot descriptor self:goalArgs:1))
then (path ← (AND path
(FindHandle descriptor path:2 descrs (ConstantHandle))
<descriptor ! path::1>))
(* This goal’s anchor path is set up by the first mapDescriptor found)
(for template fromField templateAnchors ofHandle descriptor
as instance fromField instanceAnchors ofHandle descriptor
do (for child in self:children
when (EQH template child:goalArgs)
do (if child:datum
then (AddLink child (CopyHandle instance)
fullContext)
else (child:datum ← (CopyHandle instance))
(child:datumContext ← fullContext)
(child:anchorPath ←
(AND path <child:datum ! path>))
(if (SetUpGoal child)
then (StartUpGoal child)))
(RETURN (* from loop through children for this slot))))
else (CheckSimpleNot descriptor type self:goalDesc self)))
(DESCRIBE
(DPROG((goal NIL goal) (anchor NIL Anchor)(path NIL (LISTP OF DHandle)))
(for child in self:children
when (NOT child:suspended)
do (if (path ← child:anchorPath)
then (goal ← child)
else (anchor ← (KrlCreate Anchor
(SpaceName self:datum (ConstantHandle))))
(AddAction self ’#AddPair anchor NIL child:goalArgs)
(SetUpAnchorGoal self child:goalDesc anchor NIL)
(goal ← self:children:1)
(GoalDone child ’SUCCEEDED)
(* this is so the conjunction will succeed when the new ones are done))
(SendMessage ’AlignAnchor goal ’DESCRIBE)))
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignMapDescUnique ((self Goal)(message GoalMessage))
(* this is a function for a goal type == GoalArgs is a flag for whether descriptor has no slots
if there it is a handle for the focus slot)
(SELECTQ message
(SETUP
(if (HasNoSlots self:goalDesc)
then (self:goalArgs ← (FetchMem self:goalDesc focusSlot))
else (for descr fromField descrs ofHandle self:datum
when (AND (EQ (TypeD descr) ’MapDescriptor)
(SameFocusSlot descr self:goalDesc))
do (SetUpOneOf self (CopyHandle descr) NIL)
(* do this only for the first one)
(RETURN (* from loop through datum descriptors)))))
(STARTUP ’OK)
(NEWDESCRIPTOR
(if self:goalArgs
then (* pattern has no filler pairs)
(CheckCategoryStatus self self:goalArgs descriptor type T)
elseif (AND (EQ type ’MapDescriptor)
(SameFocusSlot descriptor self:goalDesc)
(NOT self:children))
then (SetUpOneOf self (CopyHandle descriptor) T)
(OR self:suspended (self:goalStatus ← ’WAITING))
(* a MatchMapDescOneOf goal is set up the first time a same-focus descriptor
is found, and it takes care of everything after that)
(DESCRIBE
(DPROG((goal NIL Goal) (desc NIL MapDescriptor)))
(if self:children then (goal ← self:children:1)
else (desc ← (EmptyMapD self:goalDesc self:datum))
(AddAction self ’#AddToList desc)
(SetUpOneOf goal desc T))
(SendMessage ’AlignMapDescOneOf goal ’DESCRIBE)))
(AFTERFIRST
(OR structuralMatch (TriggerToMatch self (AND self:children T)))
(if (AND (NOT self:suspended) self:children)
then (self:goalStatus ← ’WAITING))
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignMemberOf ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignNot ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP
(DPROG ((goal (CREATE Goal
goalType ← AlignAnchor
resultType ← ’InvertedGoal
parent ← self
anchorPath ← NIL
goalDesc ← (GetInterpretedArg self:goalDesc)
patternContext ← self:patternContext
datum ← self:datum
datumContext ← self:datumContext)
Goal))
(SetUpGoal goal self)))
(STARTUP (GoalWaiting self) ’SKIP)
(NEWDESCRIPTOR (KHelp "Shouldn’t be active" self))
(AFTERFIRST (KHelp "Shouldn’t be active" self))
(NEWLINK ’PASS)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignOr ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP
(for anchor fromField elements ofHandle (GetOrSequence self:goalDesc)
when (NOT self:suspended)
do (SetUpGoal (CREATE Goal
goalType ← ’AlignAnchor
goalDesc ← anchor
datum ← self:datum
anchorPath ← self:anchorPath
parent ← self
resultType ← ’DisjunctiveSubgoal
patternContext ← parent:patternContext
datumContext ← parent:datumContext
links ← self:links)
self)
finally (OR self:suspended self:children (GoalDone self ’FAILED))))
(STARTUP (GoalWaiting self) ’SKIP)
(NEWDESCRIPTOR (KHelp "shouldn’t be active" self))
(AFTERFIRST (KHelp "shouldn’t be active" self))
(NEWLINK ’PASS)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignPost ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP
(DPROG ((postDesc NIL Descriptor)
(category (SELECTQ (TypeD self:goalDesc)
((KrlPointer LispPointer)
(GetSystemCategory self:goalDesc))
NIL)
SlotAnchor)))
(for descr descriptorOf datum
do (if (IsPostDescriptor descr)
then (postDesc ← descr)(RETURN)
elseif (EQ (TypeD descr) ’MapDescriptor)
then (CheckCategoryStatus self
category descr ’MapDescriptor NIL)
else (CheckSimpleNot descr NIL self:goalDesc self))
(if postDesc
then (if (ComparePost postDesc self:goalDesc)
then (CheckDescriptorMeta self postDesc)
(GoalDone self ’SUCCEEDED)
elseif (AND describe overWrite)
then (AddAction self ’#ClobberDescriptor
(KrlCopy self:goalDesc) postDesc)
(GoalDone self ’SUCCEEDED)
else (GoalDone self ’FAILED)))
(KHelp))
elseif category
then (self:patCategories ← <category>))))
(STARTUP
(if (EQ (TypeD self:goalDesc) ’Coreference)
then (MSignalC UsingCategoriesForPatternCoreference
(OK (self:patCategories ←
(GetCategories
(FetchMem self:goalDesc coref (ConstantHandle))))
’OK)
’SKIP)))
(NEWDESCRIPTOR
(if (IsPostDescriptor descriptor)
then (if (ComparePost descriptor self:goalDesc)
then (GoalDone self ’SUCCEEDED))
else (GoalDone self ’FAILED))))
(NEWLINK ’OK)
(DESCRIBE (AddAction self ’#AddToList (KrlCopy self:goalDesc))
(GoalDone self ’SUCCEEDED))
(AFTERFIRST
(if (AND (NOT structuralMatch)
(EQ (TypeD self:goalDesc) ’Coreference))
then (TriggerToMatch
self
(CREATE Link
structure ← (FetchMem self:goaldesc coref)
fullContext ← (CREATE Context
world ← self:patternContext:world)))))
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSequenceAny ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(STARTUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSequenceComplete ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSequenceEmpty ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSequenceMultiGap ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSequenceOf ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSequenceSingleGap ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSequenceSingleton ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSetAny ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSetComplete ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSetIncomplete ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSetNull ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSetOf ((self Goal)(message GoalMessage))
(* this is a function for a goal type -- goalArg = the argument)
(SELECTQ message
(NEW (self:goalArg ← (GetInterpretedArg self:goalDesc))
(NEWDESCRIPTOR
(SELECTQ type
(InterpretedMapD
(if (EQ ’SetOf (TypeI descriptor))
then (NewSubgoal goal ’AlignAnchor self:goalArg ’DisjunctiveSubgoal)))
(Set (* need stuff here which does enumerate and test))
NIL))
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignSetSingleton ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[AlignUsing ((self Goal)(message GoalMessage))
(* this is a function for a goal type)
(SELECTQ message
(SETUP)
(NEWDESCRIPTOR)
(AFTERFIRST)
(NEWLINK ’OK)
(HELP "bad message to goal function")]