Monday, April 04, 2005

Can Your Language Do This?

I've been an avid Squeaker for awhile. I use the Method Finder all of the time to find methods, but never used the advanced features despite Steve Wessels' rants about just how cool it really is. Well, I started to goofing with it tonight and nothing is going to be the same. OK, it's a simple method finder with a twist. I can type in partial names of selectors, but what if I don't know the selector. What if the only thing I know is the arguments and the answer? Well, it can find the answer! For example, say I want to find a degrees to radians conversion. So, I type the following: 180. 3.1415926.. Separate everything with periods and the last thing is the answer you desire. The method finder found the following method: Number>>degreesToRadians and Float>>degreesToRadians. WOW! How cool is that?! I spent half the night typing in arguments and the results to see what it would found. I was surprised! Squeak never ceases to amaze me. Click the Method Finder link to go to the Swiki page for more examples. SQUEAK ON!

5 comments:

Alastair Patrick said...

Hi there!

A few weekends ago I spent some time trying to learn some new languages, specifically Ruby, Lua and Smalltalk. I found Ruby and Lua extremely easy to pick up and use. After a couple of hours, I had written small but useful programs in both Ruby and Lua.

My experience of Smalltalk was completely different. I downloaded both Sqeak and Visual Works. I spent 4 hours just trying to write "Hello, world" in Smalltalk and got nowhere. I don't think the syntax of Smalltalk was the problem. It's different to what I'm used to (Java, C# and C++) but it seems well thought out. Rather, I think I got lost on the development environments of Sqeak and Visual Works.

I don't want to give up on Smalltalk just yet. I spend a lot of time doing "OO" and I want to understand where it came from.

My question is, what is the easiest way to write a simple program like "Hello, world" in Smalltalk?

Blaine said...

The simplest is to do the following step in Squeak:
1. Open>>Worskpace (or Alt-K)
2. Open>>Transcript (or Alt-T)
3. Type the following in the workspace: Transcript cr; show: 'Hello World'.
4. Highlight what you just typed and select do it from the menu (or Alt-D)
5. Check out the transcript!

This might seem like a lot of steps, but normally you have one workspace open at all times in Smalltalk to try out code. Remember the Smalltalk environment is a running system that you can interegate and inspect. If you have any questions or problems, feel free to email me. I would love to chat...=)

Serge Stinckwich said...

Hi Patrick,
i think to found a Smalltalker for a demo. It's more easier with a demo in under to understand how to use the tools.

For the example with the Method Finder, i don't know how it works, seems to be magic for me ;-)
It's a bit strange when i try the example in a 3.8 image, the method finder, also found Integer>>factorial Maybe there is a bug here ?

Blaine said...

Why Smalltalk just posted an excellent tutorial on Smalltalk called A Wee Blather About Smalltalk that contains a hello world example. ENJOY!

Blaine said...

Method Finder bug...Yeah, I saw the factorial method appear too. I tried a few other examples and got some weird results. I think it might be in the comparisons to the answer. It tried to find a close match. Anyway, it's fun to play with to see what it comes up with and generally finds methods that I might not have been thinking of, but match what I want to do! Another way to find how to do something in one method instead of five...=)

Amazon