For Programmers: Free Programming Magazines  


Home > Archive > Smalltalk > March 2005 > result cascade operator









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author result cascade operator
Ralph Boland

2005-03-04, 4:00 am

I use the squeak version of Smalltalk but
I believe this post applies to other versions as well.

Given that the syntax of Smalltalk (Squeak) is well established,
what I propose may not be practical
as it requires changing Smalltalk syntax.
Thus what I propose can be considered a theoretical point
which may become practical when
a new object oriented language is implemented.

What I propose is what I call the "result cascade operator"
for which I will use the symbol "!".

Consider that we wished to create a method "plus:"
having the same semantics as the "+" operator.
Then we could rewrite the code:

"a + b + c + d"

as:

(((a plus: b) plus: c) plus: d)

Note that we have to use a lot of parentheses
to force the correct interpretation of the code.
I propose syntactic operator "!" which forces the
result of the previous message send to be used as the
reciever of the message to follow.
With this operator we could rewrite
the above code more cleanly as:

a plus: b! plus: c! plus: d

I want interested parties to post their opinions (in principle)
on the value of the result cascade operator
in an object oriented language such as Smalltalk.
i.e.

Is the operator useful enough to make part of an OO language?

Note, for the record, that "!" can be used as a binary operator
in Squeak but that in Squeak 3.6 at least it is unused so we could add this
operator to squeak if we wanted and it would probably blow only a small number
of squeak users out of the water.
Hey, mathematically speaking, "!" is a unary operator anyway!


Ralph Boland
Reinout Heeck

2005-03-04, 8:57 am

Ralph Boland wrote:
> I propose syntactic operator "!" which forces the
> result of the previous message send to be used as the
> reciever of the message to follow.
> With this operator we could rewrite
> the above code more cleanly as:
>
> a plus: b! plus: c! plus: d
>



(z between: ((a plus: b) plus: c) and: ((d plus: e) plus: f))
ifTrue: [...].


z between: (a plus: b! plus: c) and: (d plus: e! plus: f)!
ifTrue: [...].



Nah, I prefer the parentheses.

R
-
avi.bryant@gmail.com

2005-03-04, 8:57 pm


Reinout Heeck wrote:

> (z between: ((a plus: b) plus: c) and: ((d plus: e) plus: f))
> ifTrue: [...].
>
>
> z between: (a plus: b! plus: c) and: (d plus: e! plus: f)!
> ifTrue: [...].
>
> Nah, I prefer the parentheses.


What about the Self approach?

z between: (a plus: b plus: c) And: (d plus: e plus: f) ifTrue: [...]

(I think that's right, anyway).

Avi

Mark van Gulik (ghoul)

2005-03-04, 8:57 pm


Ralph Boland wrote:
[...]
> Then we could rewrite the code:
>
> "a + b + c + d"
>
> as:
>
> (((a plus: b) plus: c) plus: d)

[...]
> a plus: b! plus: c! plus: d


Note that SELF (a Smalltalk variant) has an interesting approach. They
had a more severe problem than Smalltalk since they don't have an
assignment operator. Having to invoke a setter means that if the
right-hand-side expression uses a keyword expression than parentheses
would always be needed. As a slight tweak to the Smalltalk syntax,
they required that the firts keyword of a multi-keyword operator must
start with a lower case letter, but subsequent keywords must start with
an upper case letter. For example, instead of at:put: you'd use
at:Put: (upper case P). See:

http://c2.com/cgi/wiki?SelfUsesCapitalizationForSyntax

In my language Avail (google it if you want) I use the type system to
disambiguate nested expressions (well, the type system combined with
optional "anti-precedence" rules). That allows me to have operations
like "_<=_" and "_<=_<=_" without confusion (the underscores stand for
arguments). The expression "1 <= x <= 10" could only be an invocation
of "_<=_<=_", since "_<=_" isn't defined with a boolean argument.


> I want interested parties to post their opinions (in principle)
> on the value of the result cascade operator
> in an object oriented language such as Smalltalk.
> i.e.
>
> Is the operator useful enough to make part of an OO language?
>
> Note, for the record, that "!" can be used as a binary operator
> in Squeak but that in Squeak 3.6 at least it is unused so we could

add this
> operator to squeak if we wanted and it would probably blow only a

small number
> of squeak users out of the water.
> Hey, mathematically speaking, "!" is a unary operator anyway!


Avail defines ! as unary *AND* binary. Its unary form is factorial,
but its binary form is combinatoric (i.e., N!M = N!(N-M!)/M!). <grin>

Reinout Heeck

2005-03-06, 8:57 am

avi.bryant@gmail.com wrote:

>
> Reinout Heeck wrote:
>
>
> What about the Self approach?
>
> z between: (a plus: b plus: c) And: (d plus: e plus: f) ifTrue: [...]
>



I like that more for some reason (more balanced?) but it is still hard to
read for my St oriented mind.

Lemme try that capitalization upside down:

z Between: (a Plus: b Plus: c) and: (d Plus: e Plus: f) IfTrue: [...]


Ah! Better for me at least ;-)


> (I think that's right, anyway).
>
> Avi


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com