Stephen Compall's blog

:use for GNU Smalltalk

Tagged:

Commonly, when importing a namespace using shared pool dictionaries, you wonder "why can't I just import this once for my entire namespace?" Well, in the upcoming 3.1, you can.

Eval [PackageLoader fileInPackages: #('Parser' 'NetClients')]

Namespace current: Test [
    <import: STInST>

    Object subclass: MyTest [
        test [^RBParser]
    ]

    <import: NetClients>

    MyTest extend [
        test2 [^URIResolver]
    ]
]

Changing the variable search order

Tagged:  •  

GST, and Smalltalk in general, has many more places in which to search for variables than most programming systems. Besides instance variables, in-class and inherited, the compiler has to search a number of pools:

  • All inherited namespaces and their superspaces
  • All inherited class pools
  • All inherited shared pools

Traditionally, GST's search order has been somewhat idiosyncratic. This isn't a problem, of course, until you start making name clashes.

Analyzing Hash Collisions

Tagged:

This is a little debugging helper for analyzing hash functions in GST by looking at collisions in LookupTables. I just copied one of the more-or-less identical #findIndex: implementations and added a counter to it, then a nice method for slicing up a whole table for analysis.

Lexical block return: The language crux

Tagged:

I have been thinking about my favorite programming languages: Smalltalk, Common Lisp, and Scheme. These languages have much in common, and share many features, all the way down to syntax extension. I tend to be working in or studying any of these three when I am not pushing PHP for money.

These languages have an amazing pedigree, and many of their features have been ever so slowly moving into the mainstream. So what keeps this little club so exclusive? Is it my affinity for Lisp macrology? Is it the necessarily corresponding dearth of built-in funny characters? Perhaps, but I also realized they shared lexical, non-local block return in common, an interesting feature that others seem to overlook.

All three languages encourage you to define new control structures procedurally, using higher-order functions. This is especially true of Smalltalk where even retrieving array and dictionary elements has useful¹ associated control structures:

anArray at: 42 ifAbsent: [self defaultAt: 42].
anArray at: 42 ifPresent: [:newElt |
    self defaultAt: 42 put: newElt].

Constructors come short

I've been writing several classes in PHP, and recently became so uncomfortable with the inflexibility of the "constructor" method of describing instance creation that I implemented what I had previously thought of as a Smalltalk hack to handle not having access to instance variables outside instance methods. Names changed to protect the …:

class Foo
{
  static function makeInstances ($args…)
  {
    // code that constructs and calls the initializer here
  }

  function initRawData ($args…)
  {
    // finish munging the data and put it in instvars here
Syndicate content

User login