Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Block reversed

0 views
Skip to first unread message

Howard Oh

unread,
Jun 9, 2006, 4:58:21 PM6/9/06
to
Block is one of the reasons that makes Smalltalk so lovable. But
sometimes, block can make expressions very hard to read, because we
human read parameter object first and then read inside the block just
like Smalltalk runtime would do. This makes our reading cursor jump to
right end and then back to left.

A guick example that can depict this point can be...

[:x| x sqrt ] value: ([:x| x + 5 ] value: ([:x| x * x ] value: 2))

An idea came up to me a few minutes ago,

Define a method for Object

------------------------------------------------------------------------------------
Object>>--> aBlock

^aBlock value: self
------------------------------------------------------------------------------------

This new method can transform the example expression to...

2 --> [:x| x * x ] --> [:x| x + 5 ] --> [:x| x sqrt ]

Have a good one
Howard

Chris Uppal

unread,
Jun 10, 2006, 7:00:55 AM6/10/06
to
Howard,

> [:x| x sqrt ] value: ([:x| x + 5 ] value: ([:x| x * x ] value: 2))
>

> This new method can transform the example expression to...
>
> 2 --> [:x| x * x ] --> [:x| x + 5 ] --> [:x| x sqrt ]

I like that. Very nice :)

-- chris


Wolfgang Eder

unread,
Jul 5, 2006, 9:44:17 AM7/5/06
to
Howard,
I agree that the --> is easier to read.
However, I am not sure why you want to use
blocks this way in the first place?

| x y z |
x := 2.
y := x * x.
z := y + 5.
z sqrt

or even:

| x |
x := 2.
x := x * x.
x := x + 5.
x sqrt

Cheers,
Wolfgang

0 new messages