=============== Summary ===============

Change Set:        whenEvaluateEnoughArguments
Date:            15 August 2023
Author:            Christoph Thiede

Proposal: Tolerates superfluous arguments/missing parameters in Object Events block for #when:evaluate:. As required, implements valueWithEnoughArguments:[otherwise:|startingFrom:] on action sequences, message sends, etc. See Object>>#triggerEvent:withArguments:.

Example:
    Object new
    
when: #plonk evaluate: [Transcript showln: 'griffle'];
    
triggerEvent: #plonk with: 42.

Reasoning:
    Provide optional arguments with object events without forcing all observers to receive them.

=============== Diff ===============

ActionSequence>>valueWithEnoughArguments: {evaluating} · ct 8/15/2023 09:57
+ valueWithEnoughArguments: anArray
+     "Evaluate the elements of the receiver with enough arguments and answer the result of last evaluation."
+
+     ^self inject: nil into:
+         [:previousAnswer :each | each valueWithEnoughArguments: anArray]


BlockClosure>>valueWithEnoughArguments:otherwise: {evaluating} · ct 8/15/2023 09:59
+ valueWithEnoughArguments: anArray otherwise: aBlock
+
+     ^ self valueWithEnoughArguments: anArray


MessageSend>>valueWithEnoughArguments:otherwise: {evaluating} · ct 8/15/2023 09:59
+ valueWithEnoughArguments: anArray otherwise: aBlock
+
+     ^ self valueWithEnoughArguments: anArray


Object>>triggerEvent:withArguments: {*System-Object Events-accessing-triggering} · ct 8/15/2023 09:59 (changed)
triggerEvent: anEventSelector
withArguments: anArgumentList

^(self actionForEvent: anEventSelector)
- valueWithArguments: anArgumentList
+ valueWithEnoughArguments: anArgumentList

Object>>valueWithEnoughArguments: {evaluating} · ct 8/15/2023 10:00
+ valueWithEnoughArguments: aSequenceOfArguments
+
+     ^ self


WeakActionSequence>>valueWithEnoughArguments: {evaluating} · ct 8/15/2023 09:58
+ valueWithEnoughArguments: anArray
+     "Return the last result"
+
+     ^self inject: nil into: [ :previousAnswer :each |
+         each valueWithEnoughArguments: anArray otherwise: [ previousAnswer ]]


WeakActionSequenceTrappingErrors>>valueWithEnoughArguments: {evaluating} · ct 8/15/2023 09:59
+ valueWithEnoughArguments: anArray
+     "Do the same as my parent, but make sure that all actions that do not
+     give errors are evaluated before resignaling the ones that gave errors
+     (giving the chance to clients to handle them)."
+
+     ^self valueWithEnoughArguments: anArray startingFrom: 1


WeakActionSequenceTrappingErrors>>valueWithEnoughArguments:startingFrom: {evaluating} · ct 8/15/2023 09:59
+ valueWithEnoughArguments: anArray startingFrom: startIndex
+     "Do the same as my parent, but make sure that all actions that do not
+     give errors are evaluated before resignaling the ones that gave errors
+     (giving the chance to clients to handle them)."
+
+     "Note: I currently trap Halt,Error so that I am sure to get a Halt event in case of a Halt. This is being fixed in the exception system - when the fix is done it will be enough to capture only Error."
+
+     | each answer |
+     answer := nil.
+     startIndex to: self size do: [:index |
+         each := self at: index.
+         [
+             answer := each valueWithEnoughArguments: anArray otherwise: [ answer ].
+         ]
+             on: Halt , Error
+             do: [:exc |
+                 self valueWithEnoughArguments: anArray startingFrom: index + 1.
+                 exc pass]].
+     ^ answer


WeakMessageSend>>valueWithEnoughArguments:otherwise: {evaluating} · ct 8/15/2023 09:58
+ valueWithEnoughArguments: anArray otherwise: aBlock
+     | argsToUse |
+     
+     "Safe to use, because they are built before ensureing receiver and args..."
+     argsToUse := self collectArguments: anArray.
+     ^ self
+         withEnsuredReceiverAndArgumentsDo: [ :r :a |
+             r
+                 perform: selector
+                 withEnoughArguments: argsToUse ]
+         otherwise: aBlock


---
Sent from Squeak Inbox Talk
["whenEvaluateEnoughArguments.1.cs"]