The Artima Developer Community
Sponsored Link

Agile Buzz Forum
What's a Point to do?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
What's a Point to do? Posted: May 24, 2004 5:14 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: What's a Point to do?
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement
So, now and then again, I find myself in the fun position of wanting to do the classical 2D nested loop. For example:

4 to: 13 do: [:y | 8 to: 12 do: [:x | Transcript show: (x @ y) printString; cr]]

It's common in programs that do big matrix operations: image processing, scientific/engineering, heck mabe the row/table do this kind of stuff sometimes. Do it for a while, and you might find yourself to simplify it. This is Smalltalk after all:

Point  to:  anotherPoint do: aBlock
	self y to: anotherPoint y do: [:yy |
		self x to: anotherPoint x do: [:xx |
			aBlock value: xx@yy]]

One might opt to do a 2 arg block, keeping the x and y arguments split up, but that's semantics. So, go ahead, try it. It's kinda fun. Did you try it? Try it with the Transcript show. Did it work?

You'll find it didn't. It's really fun to try and debug it. You'll find this is quite confusing. What's going on here? A number of people have said that it's OK for a compiler to cheat as long as it doesn't get caught. Well, this is one of those cases where you've caught it. The culprit is found in the Compiler framework's MessageNode class. It has a method called isExpanded. Looking in there we'll see this suspicious looking variable called MacroSelectors. Inspecting him we can see that he's got a to:do: entry, and it turns into a transformToDo. And therein is the code that basically skips your message send, instead replacing it with bytecodes that add 1 each time to the start point. So our to:do: implementation never gets sent.

So you don't get to implement to:do: for Point. It's "special". If you can't beat 'em, join 'em! Now, that we know we can play "let's-try-not-to-get-caught-eeking-a-mere-couple-percentage-in-performance", we can begin to entertain what other selectors we might try this hackery on. This has actually been documented at least once before by Jan Steinman. But that predated Vassili's excellent dynamic implementation of ifNotNil:. We'll leave that for the next blog day I'm short on stuff to write about though. :)

Read: What's a Point to do?

Topic: New Fit-users mailing list Previous Topic   Next Topic Topic: Hotter Sauces

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use