The Inbox: Collections-mt.812.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: Collections-mt.812.mcz

commits-2
A new version of Collections was added to project The Inbox:
http://source.squeak.org/inbox/Collections-mt.812.mcz

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

Name: Collections-mt.812
Author: mt
Time: 18 December 2018, 11:58:09.289023 am
UUID: 64ff5a45-61b5-5642-aa46-9fbeac0215dd
Ancestors: Collections-eem.811

Adds a small scripting/debugging interface to evaluate code on a heterogeneous collection. Ignore errors on the way.

1. Example: A bunch of morphs whose n-th submorph should be made yellow. Would raise errors for morphs with less than n submorphs.

ActiveWorld submorphs try: [:ea | ea submorphs fifth color: Color yellow].

2. Example: Fetch the selected classes of all code browsers through the submorph interface.

| results |
results := OrderedCollection new.
ActiveWorld submorphs try: [:ea | results add: ea model selectedClass].
results explore.

=============== Diff against Collections-eem.811 ===============

Item was added:
+ ----- Method: Collection>>try: (in category 'enumerating') -----
+ try: aBlock
+ "Evaluate aBlock with each of the receiver's elements as the argument. On error, skip that element and continue."
+
+ ^ self try: aBlock ignore: Error!

Item was added:
+ ----- Method: Collection>>try:ignore: (in category 'enumerating') -----
+ try: aBlock ignore: exceptionOrExceptionSet
+ "Evaluate aBlock with each of the receiver's elements as the argument. On error, skip that element and continue."
+
+ ^ self
+ try: aBlock
+ ignore: exceptionOrExceptionSet
+ logged: false!

Item was added:
+ ----- Method: Collection>>try:ignore:logged: (in category 'enumerating') -----
+ try: aBlock ignore: exceptionOrExceptionSet logged: aBoolean
+ "Evaluate aBlock with each of the receiver's elements as the argument. On error, skip that element and continue."
+
+ ^ self do: [:ea |
+ [aBlock value: ea]
+ on: exceptionOrExceptionSet
+ do: [:err | aBoolean ifTrue: [Transcript showln: err messageText]]]!


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-mt.812.mcz

Chris Muller-3
Hi Marcel,

I've needed something like this before too, but since I also wanted to
work more with the Error's, I simply provided an additional Block for
the inner-layer which took each Error as the argument.  Then my
calling could log to Transcript or add to a separate Collection (since
I prefer to view "object messages" in an Explorer instead of only text
in the Transcript), and nicely avoids the unpleasant dependency on Transcript.

I also think it could just trap Error (or MessageNotUnderstood) since
that is the stated intended usage.  I think if one needed to specify a
custom exceptionOrExceptionSet, then it seems like they'd probably
just write normal error-handling code.

Best,
  Chris






On Tue, Dec 18, 2018 at 4:58 AM <[hidden email]> wrote:

>
> A new version of Collections was added to project The Inbox:
> http://source.squeak.org/inbox/Collections-mt.812.mcz
>
> ==================== Summary ====================
>
> Name: Collections-mt.812
> Author: mt
> Time: 18 December 2018, 11:58:09.289023 am
> UUID: 64ff5a45-61b5-5642-aa46-9fbeac0215dd
> Ancestors: Collections-eem.811
>
> Adds a small scripting/debugging interface to evaluate code on a heterogeneous collection. Ignore errors on the way.
>
> 1. Example: A bunch of morphs whose n-th submorph should be made yellow. Would raise errors for morphs with less than n submorphs.
>
> ActiveWorld submorphs try: [:ea | ea submorphs fifth color: Color yellow].
>
> 2. Example: Fetch the selected classes of all code browsers through the submorph interface.
>
> | results |
> results := OrderedCollection new.
> ActiveWorld submorphs try: [:ea | results add: ea model selectedClass].
> results explore.
>
> =============== Diff against Collections-eem.811 ===============
>
> Item was added:
> + ----- Method: Collection>>try: (in category 'enumerating') -----
> + try: aBlock
> +       "Evaluate aBlock with each of the receiver's elements as the argument. On error, skip that element and continue."
> +
> +       ^ self try: aBlock ignore: Error!
>
> Item was added:
> + ----- Method: Collection>>try:ignore: (in category 'enumerating') -----
> + try: aBlock ignore: exceptionOrExceptionSet
> +       "Evaluate aBlock with each of the receiver's elements as the argument. On error, skip that element and continue."
> +
> +       ^ self
> +               try: aBlock
> +               ignore: exceptionOrExceptionSet
> +               logged: false!
>
> Item was added:
> + ----- Method: Collection>>try:ignore:logged: (in category 'enumerating') -----
> + try: aBlock ignore: exceptionOrExceptionSet logged: aBoolean
> +       "Evaluate aBlock with each of the receiver's elements as the argument. On error, skip that element and continue."
> +
> +       ^ self do: [:ea |
> +               [aBlock value: ea]
> +                       on: exceptionOrExceptionSet
> +                       do: [:err | aBoolean ifTrue: [Transcript showln: err messageText]]]!
>
>

Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-mt.812.mcz

Eliot Miranda-2
On Tue, Dec 18, 2018 at 1:20 PM Chris Muller <[hidden email]> wrote:
Hi Marcel,

I've needed something like this before too, but since I also wanted to
work more with the Error's, I simply provided an additional Block for
the inner-layer which took each Error as the argument.  Then my
calling could log to Transcript or add to a separate Collection (since
I prefer to view "object messages" in an Explorer instead of only text
in the Transcript), and nicely avoids the unpleasant dependency on Transcript.

I also think it could just trap Error (or MessageNotUnderstood) since
that is the stated intended usage.  I think if one needed to specify a
custom exceptionOrExceptionSet, then it seems like they'd probably
just write normal error-handling code.

+1.  I was going to suggest the same thing.  It's much more flexible to factor the inner two methods as:

 try: aBlock ignore: exceptionOrExceptionSet
       "Evaluate aBlock with each of the receiver's elements as the argument. On error, skip that element and continue."

      ^self try: aBlock ignore: exceptionOrExceptionSet ifException: nil!

try: aBlock ignore: exceptionOrExceptionSet ifException: unaryBlockOrNil
      "Evaluate aBlock with each of the receiver's elements as the argument. On error, skip that element and continue."

      ^ self do: [:ea |
              [aBlock value: ea]
                      on: exceptionOrExceptionSet
                      do: [:err | unaryBlockOrNil ifNotNil: [unaryBlockOrNil value: err]]]!

then

try: aBlock ignore: exceptionOrExceptionSet logged: aBoolean
    ^self try: aBlock ignore: exceptionOrExceptionSet ifException: (aBoolean ifTrue: [[:err| Transcript showln: err messageText]])

_,,,^..^,,,_
best, Eliot


Reply | Threaded
Open this post in threaded view
|

Re: The Inbox: Collections-mt.812.mcz

marcel.taeumel
Hi, there.

I commited this proposal by accident to Trunk when merging the size-check
changes by JH.

I will implement your suggestions. And add some tests. :-)

Best,
Marcel


Eliot Miranda-2 wrote
> On Tue, Dec 18, 2018 at 1:20 PM Chris Muller &lt;

> asqueaker@

> &gt; wrote:
>
>> Hi Marcel,
>>
>> I've needed something like this before too, but since I also wanted to
>> work more with the Error's, I simply provided an additional Block for
>> the inner-layer which took each Error as the argument.  Then my
>> calling could log to Transcript or add to a separate Collection (since
>> I prefer to view "object messages" in an Explorer instead of only text
>> in the Transcript), and nicely avoids the unpleasant dependency on
>> Transcript.
>>
>> I also think it could just trap Error (or MessageNotUnderstood) since
>> that is the stated intended usage.  I think if one needed to specify a
>> custom exceptionOrExceptionSet, then it seems like they'd probably
>> just write normal error-handling code.
>>
>
> +1.  I was going to suggest the same thing.  It's much more flexible to
> factor the inner two methods as:
>
>  try: aBlock ignore: exceptionOrExceptionSet
>        "Evaluate aBlock with each of the receiver's elements as the
> argument. On error, skip that element and continue."
>
>       ^self try: aBlock ignore: exceptionOrExceptionSet ifException: nil!
>
> try: aBlock ignore: exceptionOrExceptionSet ifException: unaryBlockOrNil
>       "Evaluate aBlock with each of the receiver's elements as the
> argument. On error, skip that element and continue."
>
>       ^ self do: [:ea |
>               [aBlock value: ea]
>                       on: exceptionOrExceptionSet
>                       do: [:err | unaryBlockOrNil ifNotNil:
> [unaryBlockOrNil
> value: err]]]!
>
> then
>
> try: aBlock ignore: exceptionOrExceptionSet logged: aBoolean
>     ^self try: aBlock ignore: exceptionOrExceptionSet ifException:
> (aBoolean
> ifTrue: [[:err| Transcript showln: err messageText]])
>
> _,,,^..^,,,_
> best, Eliot





--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html