[Pharo-project] Beginner question about "self" in block

Stéphane Ducasse stephane.ducasse at inria.fr
Wed Jan 25 22:24:24 CET 2012


> Hi, I have one begginer question. It is may be simple, but it very baffles me.
> I am reading Pharo by Example (great book btw, thanks!). I'm in chapter two where I'm creating Lights Out game. There is this simple code http://pastebin.com/eQregZ35. What baffles me is line 10. I assign "Block of code" to mouseAction variable of LOCell. In this Block, there is "self", that obviously refers to LOGame object in that time. But when is this Block actualy EVALUATED (when I click on Cell), "self" should be reffering to LOCell object, isn't it? If I inspect one LOCell, inspector shows that it has instance variable "mouseAction", which is BlockClosure, that looks like "[self toggleNeighboursOfCellAt: i at: j]". If "LOCell" is the "owner" of this block and also it is the one that evaluates it, shouldn't "self" refer to LOCell object? How BlockClosure desides where "self" actually points?
> Thanks for explanation.

Here is a draft of a next chapter on block :)
But I should finish it :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Block.pdf
Type: application/pdf
Size: 241200 bytes
Desc: not available
URL: <http://lists.gforge.inria.fr/pipermail/pharo-project/attachments/20120125/ebea89aa/attachment.pdf>
-------------- next part --------------

But I want to add how block are implemented at the bye code level so it take times because not that many people are helping, so I have to learn first.


More information about the Pharo-project mailing list