Hi
I'm trying to come to the simplest set of rules to put () around Smalltalk expressions. I'm on the cascade.
is it correct to say that a cascade is - either without () I mean outside of the cascade this happens when there is no message send to the cascaded expressions itself like in x := Set new add: 5 ; yourself
- either there is one message not in the cascade and the cascade should be parenthesised. like in (x := Set new add: 5 ; yourself) class or (Set new add: 5 ; yourself) + 2 or (Set new add: 5 ; yourself) includes: 5
I read the ANSI standard but could not really found a clear description.
Then inside the cascade you need () only if the receiver expression selector is a keyword and that you have keyword in the messages
examples: Set new add: 5 ; add: 5 ; yourself (the formatter of VisualWorks put () around Set new but I guess that this is just to stress the receiver). Set new reset; reset ; reset with binary I do not see what example would not be silly (Set with: 5) add: 6 ; yourself
ducasse ducasse@iam.unibe.ch wrote...
I'm trying to come to the simplest set of rules to put () around Smalltalk expressions. I'm on the cascade.
is it correct to say that a cascade is
- either without () I mean outside of the cascade
this happens when there is no message send to the cascaded expressions itself like in x := Set new add: 5 ; yourself
- either there is one message not in the cascade and the cascade should
be parenthesised. like in (x := Set new add: 5 ; yourself) class or (Set new add: 5 ; yourself) + 2 or (Set new add: 5 ; yourself) includes: 5
I read the ANSI standard but could not really found a clear description.
Then inside the cascade you need () only if the receiver expression selector is a keyword and that you have keyword in the messages
examples: Set new add: 5 ; add: 5 ; yourself (the formatter of VisualWorks put () around Set new but I guess that this is just to stress the receiver). Set new reset; reset ; reset with binary I do not see what example would not be silly (Set with: 5) add: 6 ; yourself
I don't know what ANSI says, but...
A cascade is a series of messages sent to the same receiver. The receiver that is used is the receiver of the (outermost) message that precedes the first semicolon.
Another way of thinking about it is... r m1; m2; m3; m4 is essentially equivalent to x := r. x m1. x m2. x m3 except that this is not an expression (it's a block body), and there's an extra temp needed here.
I suppose the most exactly equivalent form would be r in: [:x | x m1. x m2. x m3] because this scopes its extra temp, and it is an expression.
I couch these all in terms of replacements because I assume (am I right? ;-) that you are experimenting with elimination of cascades.
- Dan
Hi Dan
I'm just writing a pretty printer. I took the Squeak one and made a visitor-based one. I realized that if a node would have a back pointer to its parent node this would make life easier because we could hold directly the context of the node even when recursively treating it.
I think that with this pretty printer we will be able to experiment more deeply with alternate syntax in a plug and play fashion and not patches everywhere. But doing a pretty printer is boring ;)
A cascade is a series of messages sent to the same receiver. The receiver that is used is the receiver of the (outermost) message that precedes the first semicolon.
By outermost do you mean the same as me:
in Set new add: 1; ....
the instance aSet is the receiver In my lecture I say that the messages in the cascade are sent to the receiver of the first one message. the first message being one the left of the first ;
Another way of thinking about it is... r m1; m2; m3; m4 is essentially equivalent to x := r. x m1. x m2. x m3 except that this is not an expression (it's a block body), and there's an extra temp needed here.
I was trying to see if the following expression was parsed by Squeak
Set new add: 5 ; add: 5 ; yourself includes: 5 and in fact the parentheses are needed because a cascade is an expression (in fact the opposite). But I was looking for the real reason and the ; is really defining a different expression.
I suppose the most exactly equivalent form would be r in: [:x | x m1. x m2. x m3] because this scopes its extra temp, and it is an expression.
I like this one.
I couch these all in terms of replacements because I assume (am I right? ;-) that you are experimenting with elimination of cascades.
I'm not always in the mood of eliminating everything ;) My embryonical pretty printer even pretty print {} ;)
- Dan
squeak-dev@lists.squeakfoundation.org