PackageDescription: SymbolValue

Symbol Value

Last published: September 11, 2008 by 'mlucassmith'

Defines 0 Classes
Extends 2 Classes

SymbolValue is perhaps my dearest add-in package. Especially if judged on a how much bang for how little code added scale. It adds the method value: to Symbol. It is written as:

Symbol>>value: anObject
^anObject perform: self

With that in place we can replace cases where there is a block with a single arg that gets sent a unary message. Such as:

'Hello world' reject: [:each | each isSepararator]

can be rewritten as:

'Hello world' reject: #isSeparator.

There is almost no performance loss for using this form.

In 7.6 and going forward, the ifNotNil: method is implemented using cull:. By having this, we can also add cull: to this package as an extension for Symbol. It allows cases like:

'Hello world' ifNotNil: [:string | string size]

to be written simply as:

'Hello world' ifNotNil: #size

This form is actually faster than the longer version.

I have used it for years to simplify and tersify code. And blogged about it:

I was told of the technique by Don Roberts who claimed to have gotten it from Ward Cunningham.