The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Variant Method lookup in VW

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
Variant Method lookup in VW Posted: Sep 12, 2006 6:15 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Variant Method lookup in VW
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Cincom Smalltalk Blog - Smalltalk with Rants

Advertisement

This is interesting - apparently, you can execute a "super super" (starting as far up the chain as you like) in VisualWorks. Eliot Miranda posted this in comp.lang.smalltalk:

 

perform: selector withArguments: anArray startingAbove: aBehavior
     "Send the receiver the message indicated by the arguments, starting
      the lookup in the superclass of aBehavior. The argument selector is
      the selector of the message. The arguments of the message are the
      elements of anArray.  Invoke messageNotUnderstood: if the selector
      is not understood by the receiver.  Fail the primitive if aBehavior
      is not the class of anObject or any of its superclasses, or if
      anArray is not an Array with the same number of elements as the
      number of arguments expected by the looked-up method."

        
        ^self primitiveFailed 


So to test that out, I defined a small hierarchy:

 

Object
	Grandpa
	       Dad
	           Son


Each implements a method #foo, which prints to Transcript, telling me who got executed. So, I ran these in a workspace:

 
son := Son new.
son foo

son  perform: #foo withArguments: #() startingAbove: Son.
son  perform: #foo withArguments: #() startingAbove: Dad


As expected, the first prints the result from class Son. The second executes the one from class Dad, while the last line executes the one from class Grandpa. Kind of neat, but this is definitely a dangerous hack to rely on - especially if your runtime can have new classes inserted into a hierarchy via dynamic updates.

Technorati Tags:

Read: Variant Method lookup in VW

Topic: 16 Rules to Live By Previous Topic   Next Topic Topic: Funny but good advice

Sponsored Links



Google
  Web Artima.com   

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