The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Extending Smalltalk Syntax

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
Extending Smalltalk Syntax Posted: Sep 20, 2004 5:54 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Extending Smalltalk Syntax
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

In the comments to this post, a discussion about extending the syntax of Smalltalk came up. In particular, Rich liked the F-Script array extensions. Peter William Lount has a nice write up on that here.

Here's the thing - in this case (and in most of the things that come up), we don't actually need to change the syntax of Smalltalk. You want to be able to replace:

someCollection collect: [:each | each name]

with this:

someCollection name

Well, all you need to do is add this method to class Collection:


doesNotUnderstand: aMessage
	| selector |
	selector := aMessage selector.
	^[self collect: [:each | each perform: selector]]
		on: MessageNotUnderstood
		do: [:ex | self]

Now, if I do this simple test:


people := OrderedCollection new.
people add: (Person new
	firstname: 'fred';
	lastname: 'flintstone').
people add: (Person new
	firstname: 'barney';
	lastname: 'rubble').
people add: (Person new
	firstname: 'wilma';
	lastname: 'flintstone').
people add: (Person new
	firstname: 'betty';
	lastname: 'rubble').
people firstname.

Then you end up with a collection of the firstnames. Now, there are some obvious issues with this new approach:

  • I can't send messages through if the collection itself understands them (say Person understood #first instead of #firstname, for instance)
  • What if I would rather have the protocol use #select: instead of #collect:

Either way, if this sort of thing is something you want, you can do it yourself without having to modify the syntax of the language. Which is good - because you can also change it easily if you don't like it. Syntax changes are just there, and you have to deal with them whether you like them or not. Which is why the approach taken by Java and C# sucks so much...

Read: Extending Smalltalk Syntax

Topic: Sympathy? Maybe Previous Topic   Next Topic Topic: New Agile Alliance Members benefit

Sponsored Links



Google
  Web Artima.com   

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