Page Numbers: Yes First Page: 1
Heading:
October 6, 1977 12:38 AM[IFS]<KRL>code>findClasses.bravo
# # # # # # # # # # # # # # #
[FindAnchor ((self Goal)(message GoalMessage))
(* this is a function for a goal type: goalArgs is whether action, goalDesc the evaluated do form.)
(SELECTQ message
(SETUP
(if self:anchorPath
then (self:immediateResults ←
(if self:goalDesc:bindingType then anchorPath else anchorPath:1))
(GoalDone self ’SUCCEEDED)
else (KHelp "trying to bind anchor without grounding" self)))
((STARTUP NEWDESCRIPTOR AFTERFIRST)
(KHelp "shouldn’t be active" self))
(DESCRIBE (KHelp "can’t describe over a Find" self))
(HELP "bad message to goal function")]
[FindDescriptors ((self Goal)(message GoalMessage))
(* this is a function for a goal type: goalArgs is whether action, goalDesc the evaluated do form.)
(SELECTQ message
(SETUP
(DPROG ((test self:goalDesc:bindingTest))
(for descr descriptorOf datum
when (PassesTest descr test)
do (PUSH self:immediateResults
(if (NOT self:goalDesc:actionType)
then (CopyHandleDescr)
elseif self:anchorPath
then <(CopyHandle descr) ! self:anchorPath)>
else (KHelp "trying to do action to ungrounded descriptor" self))
(CheckCount self))
(if structuralMatch
then (CheckCount self T)))
(STARTUP ’SKIP)
(NEWDESCRIPTOR
(if (SELECTQ testType
(Descriptor
(AND (EQ (TypeD descr) type)
(Align (CopyHandle descr)
test (MatchTable ’SimpleStructuralMatch)))
(Lisp (OR (NULL test)(APPLY* test descr)))
(KHelp "illegal test for descriptor" test))
then (PUSH self:immediateResults
(if (NOT self:goalDesc:actionType)
then (CopyHandleDescr)
elseif self:anchorPath
then <(CopyHandle descr) ! self:anchorPath)>
else (KHelp "trying to do action to ungrounded descriptor" self)))
(CheckCount self)))
(AFTERFIRST NIL)
(DESCRIBE (KHelp "can’t describe over a Find" self))
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[FindElements ((self Goal)(message GoalMessage))
(* this is a function for a goal type -- goalDesc is evaluated bindingForm. immediate results is used for a list of the elements found)
(SELECTQ message
(SETUP
(DPROG((count self:goalDesc:bindingCount)
(test self:goalDesc:bindingTest)
(results NIL LST))
(* datum has already been checked for CouldSatisfy)
(AND (NULL test)
(FIXP count)
(LESSP count 0)
(for anchor fromField elements ofHandle self:datum
as number from count
finally (count ← number)))
(for anchor fromField elements ofHandle self:datum
as number from 1
do (if (EQ (KrlType anchor) ’Ellipsis)
then (if (AND (FIXP count)(GREATERP count 0))
then (RETURN)
else (NCONC1 ’ELLIPSIS results))
elseif (AND (NULL test)(FIXP count)(NEQ number count))
then (NCONC1 ’IRRELEVANT results)
elseif (FMEMB self:goalArgs:2 ’(Element Anchor))
then (NCONC1 (CopyHandle anchor) results)
esle (NCONC1 ’UNKNOWN results)
(SetUpGoal
(CREATE Goal
goalType ← ’FindPost
goalDesc ← self:goalArgs
goalArgs ← number
patternContext ← self:patternContext
datum ← (CopyHandle anchor)
datumContext ← self:datumContext
anchorPath ← NIL
parent ← self
resultType ← ’FindElementForEnumeration)
self)
(AND(NULL test)(FIXP count)(RETURN))
finally (self:immediateResults ← results)
(CheckEnumerationSatisfied self))))
(STARTUP (GoalWaiting self) ’SKIP)
(NEWDESCRIPTOR (KHelp "shouldn’t be active" self))
(AFTERFIRST (KHelp "shouldn’t be active" self))
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[FindEnumeration ((self Goal)(message GoalMessage))
(* this is a function for a goal type. goalDesc is evaluated binding form)
(SELECTQ message
(SETUP
(DPROG ((countSpec self:goalDesc:bindingCount Count))
(for descr descriptorOf datum
do (SELECTQ (CouldSatisfyCount descr count)
(IMPOSSIBLE (GoalDone self ’FAILED))
(POSSIBLE (SetUpGoal
(CREATE Goal
goalType ← ’FindElements
goalDesc ← self:goalDesc
datum ← (CopyHandle descr)
resultType ← ’EquivalentGoal
parent ← self
goalArgs ← self:goalArgs
datumContext ← self:datumContext
links ← self:links)
self))
NIL)))
(STARTUP ’SKIP)
(NEWDESCRIPTOR
(SELECTQ (CouldSatisfyCount descriptor self:goalDesc:bindingCount)
(IMPOSSIBLE (GoalDone self ’FAILED))
(POSSIBLE (SetUpGoal
(CREATE Goal
goalType ← ’FindElements
goalDesc ← self:goalDesc
datum ← (CopyHandle descr)
resultType ← ’EquivalentGoal
parent ← self
goalArgs ← self:goalArgs
datumContext ← self:datumContext
links ← self:links)
self))
NIL))
(AFTERFIRST (OR structuralMatch
(for link in self:links do (TriggerToEnumerate self link)))
(NEWLINK (TriggerToEnumerate self link))
(HELP "bad message to goal function")]
# # # # # # # # # # # # # # #
[FindPost ((self Goal)(message GoalMessage))
(* this is a function for a goal type -- goalDesc is binding spec -- GoalARgs isinteger for elements)
(SELECTQ message
(SETUP
(DPROG ((post NIL Descriptor))
(if (post ← (for descr descriptorOf self:datum
thereis (IsPostDescriptor descr)))
then (self:immediateResults ← (GetPost post selfgoalDesc:bindingType))
(OR self:goalArgs
(DoBinding self self:immediateResults)
(GoalDone self ’SUCCEEDED))
(STARTUP (OR structuralMatch
(for link in self:links do (TriggerToFind self link)))
’OK)
(NEWDESCRIPTOR
(DPROG((triggers NIL LST))
(if (IsPostDescriptor descriptor)
then (DoBinding self (GetPost post self:goalDesc:bindingType))
(GoalDone self ’SUCCEEDED))
elseif (AND (EQ (TypeK descriptor) ’MapDescriptor)
(triggers ←
(GetTriggers
(FetchMem descriptor focusSlot (ConstantHandle))))
then (TriggerToFind self triggers (FindSelfInstance descriptor)))))
(NEWLINK (TriggerToFind self link))
(HELP "bad message to goal function")]