[Squeak protocol] Proposal: Interval>>#@

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

[Squeak protocol] Proposal: Interval>>#@

Christoph Thiede
Hi all,

in a recent project, we introduced a shorthand for creating rectangles:



As applying @ on two numbers converts them into a point, I think it would be
somehow analogical to apply @ on two ranges to convert them into a
rectangle. Above all, I experienced enough cases where I personally find it
much more convenient to create a rectangle using
(2 to: 4) @ (3 to: 6)
instead of
2 @ 3 corner: 4 @ 6.

On the other hand, it is a bit weird that [(2 to: 4) @ (3 to: 5)] would
produce a different output than [(2 to: 4) asArray @ (3 to: 5)]. But imho
the rectangle construction would just be more intuitive. In general, are
there any real senders of SequenceableCollection>>#@ which could not just
call [aCollection with: anotherCollection collect: #@]?

Looking forward to your opinions :)

Best,
Christoph



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

Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: [Squeak protocol] Proposal: Interval>>#@

Christoph Thiede

The missing code snippet was


Interval>>@ verticalInterval ^ Rectangle left: self start right: self stop top: verticalInterval start bottom: verticalInterval stop

(I just inserted it into the history)

Other proposals for creating Rectangles:

r := Rectangle horizontal: (2 to: 3) vertical: (4 to: 6).
r horizontalRange; verticalRange.

Illustratively, Rectangle>>#intersects: could answer

(self horizontalRange intersects: aRectangle horizontalRange) and: [self verticalRange intersects: aRectangle verticalRange].

(I do not want to change this optimized implementation, this is only one possible use case for the change.)

Best,
Christoph



Von: Squeak-dev <[hidden email]> im Auftrag von Thiede, Christoph
Gesendet: Freitag, 9. August 2019 21:55 Uhr
An: [hidden email]
Betreff: [squeak-dev] [Squeak protocol] Proposal: Interval>>#@
 
Hi all,

in a recent project, we introduced a shorthand for creating rectangles:

Interval>>@ verticalInterval ^ Rectangle left: self start right: self stop top: verticalInterval start bottom: verticalInterval stop

As applying @ on two numbers converts them into a point, I think it would be
somehow analogical to apply @ on two ranges to convert them into a
rectangle. Above all, I experienced enough cases where I personally find it
much more convenient to create a rectangle using
(2 to: 4) @ (3 to: 6)
instead of
2 @ 3 corner: 4 @ 6.

On the other hand, it is a bit weird that [(2 to: 4) @ (3 to: 5)] would
produce a different output than [(2 to: 4) asArray @ (3 to: 5)]. But imho
the rectangle construction would just be more intuitive. In general, are
there any real senders of SequenceableCollection>>#@ which could not just
call [aCollection with: anotherCollection collect: #@]?

Looking forward to your opinions :)

Best,
Christoph



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





Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: [Squeak protocol] Proposal: Interval>>#@

Levente Uzonyi
In reply to this post by Christoph Thiede
On Fri, 9 Aug 2019, Christoph Thiede wrote:

> Hi all,
>
> in a recent project, we introduced a shorthand for creating rectangles:
>
>
>
> As applying @ on two numbers converts them into a point, I think it would be
> somehow analogical to apply @ on two ranges to convert them into a
> rectangle. Above all, I experienced enough cases where I personally find it
> much more convenient to create a rectangle using
> (2 to: 4) @ (3 to: 6)

@ is not intuitive at all. Why would one expect to get 2 @ 3 corner: 4 @ 6
instead of 2 @ 3 extent: 4 @ 6?

Also, why not just use #rect:? The comment says "This is the most general
infix way to create a rectangle.".

Levente

> instead of
> 2 @ 3 corner: 4 @ 6.
>
> On the other hand, it is a bit weird that [(2 to: 4) @ (3 to: 5)] would
> produce a different output than [(2 to: 4) asArray @ (3 to: 5)]. But imho
> the rectangle construction would just be more intuitive. In general, are
> there any real senders of SequenceableCollection>>#@ which could not just
> call [aCollection with: anotherCollection collect: #@]?
>
> Looking forward to your opinions :)
>
> Best,
> Christoph
>
>
>
> --
> Sent from: http://forum.world.st/Squeak-Dev-f45488.html

Reply | Threaded
Open this post in threaded view
|

Re: [Squeak protocol] Proposal: Interval>>#@

Nicolas Cellier
In my images i often use xCollection @ yCollection to create a (proxy) collection of points (for curves).

Le ven. 9 août 2019 à 22:39, Levente Uzonyi <[hidden email]> a écrit :
On Fri, 9 Aug 2019, Christoph Thiede wrote:

> Hi all,
>
> in a recent project, we introduced a shorthand for creating rectangles:
>
>
>
> As applying @ on two numbers converts them into a point, I think it would be
> somehow analogical to apply @ on two ranges to convert them into a
> rectangle. Above all, I experienced enough cases where I personally find it
> much more convenient to create a rectangle using
> (2 to: 4) @ (3 to: 6)

@ is not intuitive at all. Why would one expect to get 2 @ 3 corner: 4 @ 6
instead of 2 @ 3 extent: 4 @ 6?

Also, why not just use #rect:? The comment says "This is the most general
infix way to create a rectangle.".

Levente

> instead of
> 2 @ 3 corner: 4 @ 6.
>
> On the other hand, it is a bit weird that [(2 to: 4) @ (3 to: 5)] would
> produce a different output than [(2 to: 4) asArray @ (3 to: 5)]. But imho
> the rectangle construction would just be more intuitive. In general, are
> there any real senders of SequenceableCollection>>#@ which could not just
> call [aCollection with: anotherCollection collect: #@]?
>
> Looking forward to your opinions :)
>
> Best,
> Christoph
>
>
>
> --
> Sent from: http://forum.world.st/Squeak-Dev-f45488.html



Reply | Threaded
Open this post in threaded view
|

Re: [Squeak protocol] Proposal: Interval>>#@

Christoph Thiede

Thank you for your feedback.


My motivation was a method where x and y coordinates came from different sources, and I didn't found it beautiful to separate and reassemble them. The snippet looks up a cell by the x coordinates of a column header and the y coordinates of a row header:




I now see that Interval>>#@ might be confusing, respecting the implementation in SequenceableCollection ...


@ is not intuitive at all. Why would one expect to get 2 @ 3 corner: 4 @ 6 

> instead of 2 @ 3 extent: 4 @ 6?

In my view, because in the expression 2 to: 4, 4 stands for the absolute end of the interval but not the relative size.

How would you think about the following protocol?

r := Rectangle horizontal: (2 to: 3) vertical: (4 to: 6).
r horizontalRange; verticalRange.


Von: Squeak-dev <[hidden email]> im Auftrag von Nicolas Cellier <[hidden email]>
Gesendet: Samstag, 10. August 2019 23:20:13
An: The general-purpose Squeak developers list
Betreff: Re: [squeak-dev] [Squeak protocol] Proposal: Interval>>#@
 
In my images i often use xCollection @ yCollection to create a (proxy) collection of points (for curves).

Le ven. 9 août 2019 à 22:39, Levente Uzonyi <[hidden email]> a écrit :
On Fri, 9 Aug 2019, Christoph Thiede wrote:

> Hi all,
>
> in a recent project, we introduced a shorthand for creating rectangles:
>
>
>
> As applying @ on two numbers converts them into a point, I think it would be
> somehow analogical to apply @ on two ranges to convert them into a
> rectangle. Above all, I experienced enough cases where I personally find it
> much more convenient to create a rectangle using
> (2 to: 4) @ (3 to: 6)

@ is not intuitive at all. Why would one expect to get 2 @ 3 corner: 4 @ 6
instead of 2 @ 3 extent: 4 @ 6?

Also, why not just use #rect:? The comment says "This is the most general
infix way to create a rectangle.".

Levente

> instead of
> 2 @ 3 corner: 4 @ 6.
>
> On the other hand, it is a bit weird that [(2 to: 4) @ (3 to: 5)] would
> produce a different output than [(2 to: 4) asArray @ (3 to: 5)]. But imho
> the rectangle construction would just be more intuitive. In general, are
> there any real senders of SequenceableCollection>>#@ which could not just
> call [aCollection with: anotherCollection collect: #@]?
>
> Looking forward to your opinions :)
>
> Best,
> Christoph
>
>
>
> --
> Sent from: http://forum.world.st/Squeak-Dev-f45488.html




pastedImage.png (80K) Download Attachment
pastedImage.png (79K) Download Attachment
Carpe Squeak!