[Pharo-project] Optimisation / Simplification ...

4 views
Skip to first unread message

James Ladd

unread,
Jan 9, 2012, 7:52:41 PM1/9/12
to pharo-...@lists.gforge.inria.fr

While implementing Redline Smalltalk it occurred to me that methods and blocks
are the same things, making the use of blocks to represent methods a possible
optimisation or simplification to the internal of any Smalltalk implementation.

For example,

at: key put: value
  <statements here>

Is not that different to:

at:put: [ :key :value | <statements here> ]

Just saying.

Milan Mimica

unread,
Jan 10, 2012, 7:20:19 AM1/10/12
to Pharo-...@lists.gforge.inria.fr
I think we all noticed that :) With the exception that blocks return the value of the last statement, and methods return self by default. I would love if you could make an explicit local return from a block too.
--
Milan Mimica
http://sparklet.sf.net

Johan Brichau

unread,
Jan 12, 2012, 8:23:32 AM1/12/12
to Pharo-...@lists.gforge.inria.fr
Hi,

With the exception of any return statement in <statements here>, which should do a non-local return instead of returning from the block.
I just read an interesting post on why functions (or methods) are not blocks: http://yehudakatz.com/2012/01/10/javascript-needs-blocks/

best,
Johan

Frank Shearar

unread,
Jan 12, 2012, 8:54:51 AM1/12/12
to Pharo-...@lists.gforge.inria.fr
And a method closes over the instvars of the object.

Even if you said that

at: key put: value
<statements here>

was equivalent to

[:self :key :value | <statements here>]

you'd still need to qualify that <statements here> has privileged
access to the interior of self. So the equivalent block is more like

[:self :key :value <insert all of the object's instvars> | <statements here>]

(modulo non-local returns, of course)

frank

Dennis Schetinin

unread,
Jan 12, 2012, 10:00:56 AM1/12/12
to Pharo-...@lists.gforge.inria.fr
Reply all
Reply to author
Forward
0 new messages