[squeak-dev] Collections/Streams | About enumerating a sequence up to a matching query ...

Marcel Taeumel marcel.taeumel at hpi.de
Tue Mar 9 13:34:21 UTC 2021


> And since the proposed operation would actually be a two-phase operation by concept, I proposed to insert the little adverb "then" to improve consistency  with the existing protocols.


It is not a two-phase operation. It is just a #do: that stops at a certain point. It does not compare to #select:thenCollect:. It just constrains the enumeration part.

> I do like the verbs and the prepositions, just not the order of keywords

Well, there is #withIndexDo:. Maybe #upThrough:do: would work? Here is an example:

Array streamContents: [:result |
   aButton withAllOwners
      upThrough: [:morph| morph isSystemWindow]
      do: [:morph | result nextPut: morph color]].

Best,
Marcel
Am 09.03.2021 14:15:33 schrieb Thiede, Christoph <christoph.thiede at student.hpi.uni-potsdam.de>:
Hi Marcel,

maybe I have expressed myself incorrectly, please let me try to correct this:

> 1. You do not like the name #do:upThrough:.

Partially. :-) I do like the verbs and the prepositions, just not the order of keywords. I would prefer not to end up with a language like SQL where you need to read from the right to the left because the notion order of FROM and SELECT differs from their execution order.
And since the proposed operation would actually be a two-phase operation by concept, I proposed to insert the little adverb "then" to improve consistency with the existing protocols.

> 2. You do not agree with just adding the #do:*-version but would like to go "all in" to also support #select* and #collect* and maybe even adapt the #take* protocol.

No, these were only for a long-term perspective. I would be absolutely fine with adding #selectUpThrough:thenDo: only, today. :-)

> See below Nicolas' comments on #copyUpThrough:

This one?

> My advice would be to stick with those semantics as much as possible to avoid confusion*.

Is this really the way to go? If we always add a new vocabulary when an existing one creates doubts, I fear this could hinder us from designing a simple and consistent language in the end. Rather, we should discuss the existing verbs and unify them if necessary. :-)

Best,
Christoph
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel
Gesendet: Dienstag, 9. März 2021 13:39:17
An: squeak-dev
Betreff: Re: [squeak-dev] Collections/Streams | About enumerating a sequence up to a matching query ...
 
Hi Christoph,

let me try to summarize your thoughts:

1. You do not like the name #do:upThrough:.
2. You do not agree with just adding the #do:*-version but would like to go "all in" to also support #select* and #collect* and maybe even adapt the #take* protocol.

Yeah, I disagree with you on both. :-) See below Nicolas' comments on #copyUpThrough: maybe also my thoughts on "baby steps" ;-) in my previous answer

Best,
Marcel
Am 09.03.2021 13:23:16 schrieb Thiede, Christoph <christoph.thiede at student.hpi.uni-potsdam.de>:
Hi Marcel,

I would pay additional attention to the order of arguments. :-)

#do:upThrough: reads to me as: First do something for every element, then select all elements (which elements? the original elements or a collected copy?) as long as they do not meet a requirement. Which probably would not be the idea of this selector since it would be unnecessarily slow, wouldn't it?
What would (1 to: 10) do: [:ea | self inform: ea] upThrough: [:ea | false] do? Show zero, one, or ten dialogs?
In the following assuming that the right answer is zero ...:

I think #selectUpThrough:thenDo: and #selectUpThrough:thenCollect: might fit better. Or maybe #takeUpThrough:... instead. It communicates the order of block execution more transparently and would be consistent and colocated to the existing #select:then[Do|Collect]: methods.

What do you think? :-)

Best,
Christoph
[http://www.hpi.de/]
Von: Squeak-dev <squeak-dev-bounces at lists.squeakfoundation.org> im Auftrag von Taeumel, Marcel
Gesendet: Dienstag, 9. März 2021 09:40:38
An: squeak-dev
Betreff: Re: [squeak-dev] Collections/Streams | About enumerating a sequence up to a matching query ...
 
Hi all.

I like the use of "upThrough" vs. "upTo" to distinguish inclusive from exclusive. Like the existing #copyUpThrough:. (So, not "until".)

I think that #readStream should not be used in any collection's method (implementation). Instead, we now about #size and sometimes #array, so we should use #do: and similar. Or at least *try* not use it. Yes, I know about #streamContents:, which I think is really valuable.

Even if we would add something like #collect:upThrough: or #collect:upTo:, I would not want to change the implementation of #collect:. Maybe use #collect: to implement the new interface, but not change it. An [:each | false] would just involve too many redundant checks.

Considering the order of predicates, I would just support first-order predicates for now because that's what our most recent use cases would need. :-)

***

All in all, I would suggest to just add #do:upThrough: and #do:upTo: to Sequenceable collection as well as #upThrough: to (Positionable)Stream. Let's not over-engineer this for now but see where such increment leads us.

Then, my example use from the beginning could look like this:

Array streamContents: [:result |
   aButton withAllOwners
      do: [:morph | result nextPut: morph color]
      upThrough: [:morph | morph isSystemWindow]].

Maybe, at a later point, we could evaluate the need for extending #reject:, #select:, #collect:, too. Maybe.

What do you think?

Best,
Marcel
Am 09.03.2021 08:07:23 schrieb Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com>:
Also the question of inclusion will arise as well as the order of predicates...

There could also be symetrical once: [:x | x > 10].

Le lun. 8 mars 2021 à 23:33, Nicolas Cellier <nicolas.cellier.aka.nice at gmail.com [mailto:nicolas.cellier.aka.nice at gmail.com]> a écrit :

I like that, it's beginning to be expressive, even better than clojure. However, i think that clojure offers composable predicates thanks to lazyness... like Xtreams.

Le lun. 8 mars 2021 à 21:38, Jaromir Matas <m at jaromir.net [mailto:m at jaromir.net]> a écrit :

> I am looking for something like #collect:until: or #upToSatisfying:. I do
want the stop element to be included here, not sure about the general case.
>
> aButton withAllOwners
>    collect: [:morph | morph color]
>    until: [:morph | morph isSystemWindow].
>

Hi again, ahh so you're actually looking for a generalized collect for any
SequencableCollection or Stream :) Like this?

(1 to: 100)
        collect: [:x | x squared]
        where: [:x | x even]
        until: [:x | x squared = 2500]


collect: collectBlock where: whereBlock until: untilBlock

        | result supplier |
        supplier := self readStream.
        result := {} writeStream.
        [[supplier atEnd]
            whileFalse: [ | val |
              val := supplier next.
              (whereBlock value: val) ifTrue: [result nextPut: (collectBlock value:
val)].
              (untilBlock value: val) ifTrue: [^result contents]]
        ] value.
        ^result contents

collect: colBlock until: untilBlock

        ^self collect: colBlock where: [:each | true] until: untilBlock

or even:

collect: colBlock

        ^self collect: colBlock until: [:each | true]




-----
^[^ Jaromir
--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html [http://forum.world.st/Squeak-Dev-f45488.html]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20210309/796e2bc9/attachment-0001.html>


More information about the Squeak-dev mailing list