Page Numbers: Yes First Page: 1
Heading:
October 6, 1977 12:14 AM[IFS]<KRL>code>alignAction.bravo
# # # # # # # # # # # # # # #
[AddAction ((parent Goal)
(type LITATOM)
(arg DHandle)
(extraForPath DHandle)
(param1 ANY)
(param2 ANY)
(RETURNS Irrelevant))
(DPROG ((path (OR parent:anchorPath
(MSignal UngroundedAction (SKIP (RETURN))))
(LST OF DHandle))
THEN(action
(Create Action
actionParent ← parent
actionBinding ←
(if extraForPath then <extraForPath ! path> else path))
actionSpec ← (Create ActionForm actionType ← type
actionArg ← arg
actionTest ← param1
actionCount ← param2))
Action))
(if parent:immediateResults
then (for result in parent:immediateResults
do (PUSH result:actions action)
(* this assumes the goal is conjunctive -- needs fixing))
else (PUSH parent:immediateResults (CREATE Result actions ← <action>)]
# # # # # # # # # # # # # # #
[AddProcedure ((path (LISTP OF DHandle))(action Action)(type (MEMQ Changed EnumerationChanged Filled Identified))(arg Descriptor)(RETURNS Irrelevant))
(DECL (triggers LST (BOUNDIN DoAction))
(traps LST (BOUNDIN DoAction)))
(DPROG((template NIL SlotHandle)
(instance NIL Anchor)
(form NIL (ONEOF TriggerForm TrapForm)))
(if (EQ type ’Identified)
then (template ← (FetchMem arg focusSlot (ConstantHandle)))
(if (HasTriggers template ’Identified)
then (PUSH triggers
(CREATE TriggerForm
triggerType ← type
triggerTemplate ← (CopyHandle template)
triggerPrototype ← (FetchMem arg prototype)
triggerInstance ← path:1
triggerActions ← <action>))
else (if (AND path::1
(EQ (TypeD path:2) ’MapDescriptor))
(template ←
(FindCorrespondingTemplate path:2 path:1
(ConstantHandle)))
(HasTriggers template type))
then
(instance ←
(if (EQH (FetchMem path:2 prototype (ConstantHandle))
(FetchMem path:2 focusSlot (ConstantHandle)))
then path:3
else (FindInstance path:2)))
(if (form ←
(for trigger in triggers
thereis (AND (EQ trigger:triggerType type)
(EQH trigger:triggerTemplate template)
(EQH trigger:triggerInstance instance))))
then (PUSH form:triggerActions action)
else (PUSH triggers
(CREATE TriggerForm
triggerType ← type
triggerTemplate ← template
triggerPrototype ← (FetchMem path:2 prototype)
triggerInstance ← instance
triggerActions ← <action>))))
(if (HasTraps path:1 type)
then (if (form ← (for trap in traps
thereis (AND (EQ trap:trapType type)
(EQH trap:trapAnchor path:1))
then (PUSH form:trapActions action)
else (PUSH traps
(CREATE TrapForm
trapType ← type
trapAnchor ← path:1
trapActions ← <action>))))]
# # # # # # # # # # # # # # #
[DoAction ((action Action (USEDIN triggers))(RETURNS Irrelevant))
(DECL (oldActions (LST OF Action)(BOUNDIN DoActions)))
(DPROG((actions <action> (LISTP OF Action) (USEDIN triggers))
(triggers NIL (LST OF TriggerForm) (USEDIN FindDemons))
(traps NIL (LST OF TrapForm) (USEDIN FindDemons)))
(ExpandAction action)
(for act in actions do
(if (FMEMB act:actionSpec:actionType
’(#AddElement #AddDescriptor #ClobberElement
#ClobberDescriptor #ClearAnchor))
then (FindDemons action)))
(for trap in traps do (DoActionTrap trap NIL))
(for trigger in triggers do (DoActionTrigger trigger NIL))
(for action in actions
when action:actionSpec
do (* actions are killed by removing them or clobbering their actionSpec)
(SendMessage action:actionSpec:actionType action ’DO))
(for trap in traps do (DoActionTrap trap T))
(for trigger in triggers do (DoActionTrigger trigger T))
(PUSH oldActions action]
# # # # # # # # # # # # # # #
[DoActions ((result Result)(RETURNS Irrelevant))
(* At any point, it is legal to PUSH new actions onto newActions. They will be treated like the originals except not evaluated )
(DPROG ((newActions result:actions (LST OF Action) (USEDIN triggers))
(oldActions NIL (LST OF Action) (USEDIN triggers))
(action NIL Action))
(DECL ((bindings (LISTP OF Binding) (BOUNDIN FullAlign)))
(alignEnvironment STACKP (BOUNDIN FullAlign))))
(bindings ← result:bindings)
(* the function ValueOf uses the variable bindings freely if not given. )
(for action in newActions
do (if action:actionForm
then (action:actionSpec:actionType ←
(SELECTQ action:actionForm:actionType
(MetaDescribe ’#MetaDescribe)
(Substitute ’#Substitute)
((Describe OverWrite) ’#Describe)
((SubstituteDescriptor AddDescriptor)
’#ChangeDescriptor)
((AddElement AddBefore AddAfter SubstituteElement)
’#ChangeElement)
(MSignal UnknownActionType)))
(action:actionSpec:actionArgs ←
(for arg in action:actionForm:actionArgs
collect (ENVEVAL arg alignEnvironment)))
(while newActions
do (DoAction (POP newActions))]
# # # # # # # # # # # # # # #
[DoActionTraps ((trap TrapForm)(after BOOL)(RETURNS Irrelevant))
(DPROG((ACTIONS (for action in trap:trapActions
when action:actionSpec
collect action)
(LISTP OF Action)))
(OR ACTIONS (RETURN))
(SELECTQ trap:trapType
(Filled (DPROG((FILLER ACTIONS:1:actionSpec:actionArg Descriptor))
(DoTraps (if after then ’WHENFILLED
else ’BEFOREFILLED)
trap:trapAnchor NIL ’EVAL)))
(Changed (DoTraps (if after then ’WHENCHANGED
else ’BEFORECHANGED)
trap:trapAnchor NIL ’EVAL))
(Described
(DPROG((DESCRIPTORS (for action in ACTIONS
collect action:actionSpec:actionArg)
(LISTP OF Descriptor)))
(DoTraps (if after then ’WHENDESCRIBED
else ’BEFOREDESCRIBED)
trap:trapAnchor NIL ’EVAL)))
(EnumerationChanged
(DoTraps (if after then ’WHENENUMERATIONCHANGED
else ’BEFOREENUMERATIONCHANGED)
trap:trapAnchor NIL ’EVAL))
(KHelp "illegal activity"))
# # # # # # # # # # # # # # #
[DoActionTriggers ((trigger TriggerForm)(after BOOL)(RETURNS Irrelevant))
(DPROG((ACTIONS (for action in trigger:triggerActions
when action:actionSpec
collect action)
(LISTP OF Action)))
(OR ACTIONS (RETURN))
(SELECTQ trigger:triggerType
(Filled (DPROG((FILLER ACTIONS:1:actionSpec:actionArg Descriptor))
(DoTriggers (if after then ’WHENFILLED
else ’BEFOREFILLED)
trigger:triggerTemplate
trigger:triggerPrototype
trigger:triggerInstance
NIL ’EVAL)))
(Changed (DoTriggers (if after then ’WHENCHANGED
else ’BEFORECHANGED)
trigger:triggerTemplate
trigger:triggerPrototype
trigger:triggerInstance
NIL ’EVAL)))
(Identified (DoTriggers (if after then ’WHENIDENTIFIED
else ’BEFOREIDENTIFIED)
trigger:triggerTemplate
trigger:triggerPrototype
trigger:triggerInstance
NIL ’EVAL)))
(Described
(DPROG((DESCRIPTORS (for action in ACTIONS
collect action:actionSpec:actionArg)
(LISTP OF Descriptor)))
(DoTriggers (if after then ’WHENDESCRIBED
else ’BEFOREDESCRIBED)
trigger:triggerTemplate
trigger:triggerPrototype
trigger:triggerInstance
NIL ’EVAL)))
(EnumerationChanged
(DoTriggers (if after then ’WHENENUMERATIONCHANGED
else ’BEFOREENUMERATIONCHANGED)
trigger:triggerTemplate
trigger:triggerPrototype
trigger:triggerInstance
NIL ’EVAL)))
(KHelp "illegal activity"))
# # # # # # # # # # # # # # #
[ExpandAction ((action Action)(RETURNS Irrelevant))
(SendMessage action:actionSpec:actionType action ’EXPAND]
# # # # # # # # # # # # # # #
[FindDemons ((action Action)(RETURNS Irrelevant))
(DECL (traps (LST OF TrapForm) (BOUNDIN DoAction))
(triggers (LST OF TriggerForm)(BOUNDIN DoAction)))
(DPROG((spec action:actionSpec ActionForm)
THEN(type spec:actionType ActionType)
THEN(path (if (SELECTQ type
((#ClobberDescriptor #ClobberElement) T)
(#AddElement (FMEMB spec:actionTest
’(AddBefore AddAfter)))
NIL)
then action:actionBindings::1
else action:actionBindings)
(LISTP OF DHandle)))
(if (FMEMB type ’(#AddElement #ClobberElement))
then (AddProcedure path::1 action ’EnumerationChanged path:1)
(path ← path::1)
elseif (FMEMB type ’(#AddDescriptor #ClobberDescriptor))
then (if (IsPostDescriptor spec:actionArg)
then (AddProcedure path action ’Filled spec:actionArg)
elseif (EQ (TypeD spec:actionArg ’MapDescriptor))
then (AddProcedure path action ’Identified spec:actionArg)))
(for place on path by (CDDR path)
do (AddProcedure place action ’Changed)
(* the path is alternating anchors and descriptors)]
# # # # # # # # # # # # # # #
[SubAction ((parent Action)
(type ActionType)
(arg DHandle)
(binding (LISTP OF DHandle))
(otherArg ANY)
(expand BOOL)
(RETURNS Irrelevant))
(DPROG ((action
(CREATE Action
actionSpec ← (CREATE ActionForm
actionType ← type
actionArg ← arg
actionTest ← otherArg)
actionParent ← parent
actionBinding ← binding)
Action))
(PUSH actions action)
(if expand then (SendMessage type action ’EXPAND))
(SendMessage type action ’PROCEDURES]