Simple scripts without "Smalltalk at: #b put: ..."

Going back and thinking about "what I've learned so far" in the few days I've been typing around on GNU Smalltalk, I noticed that I put something in my previous "example snippets" which wasn't immediately intuitive when I got started.

Motivation: when writing a simple script, or playing around with `gst`, you want to execute some block of code that requires various intermediate results, and get a final result you can inspect, without the pinkie-mangling jibber-jabber that is:

Smalltalk at: #z put: 'some value'!
Smalltalk at: #y put: 'another value'!
Smalltalk at: #x put: (y someMessage: z)!
x inspect!

The first step is to start using a BlockClosure in the 'put' for the variables you don't want around later:

Smalltalk at: #x put: [
  | z y |
  z := 'some value'.
  y := 'another value'.
  y someMessage: z
] value!
x inspect!

But even that is a bit cumbersome, and not likely to very easily be ported to reusable code. What you can do, though, is just start using block syntax immediately:

 | z y x |
   z := 'some value'.
   y := 'another value'.
   x := y someMessage: z.
   x inspect!

You can now put this is a ".st" file and execute it with gst, or type it directly into gst, and execute snippets of code without using "Smalltalk at:" all the time.

User login