Reinventing the wheel: the fluent interface design pattern
lexandera.com
lexandera.com
The "with" control structure only resembles this in the degenerate case where every expression in the chain evaluates to the exact same object. Not only that, the "with" keyword expects a series of statements (as opposed to expressions), and that is the exact opposite of what the chaining style is about. This is easily seen in the author's own example: each member of the sequence has to end in a semicolon (i.e. is a statement rather than an expression), so you don't have a single composite expression at all, only a slightly more compact procedural script.
mainFrame := JFrame new: 'Hello World';
add: label withAlignment: BorderLayout.CENTER;
addWindowListener: MainFrameListener new;
setDefaultCloseOperation: JFrame.DO_NOTHING_ON_CLOSE;
pack;
setLocationRelativeTo: nil;
setVisible: True;
yourself.
(The result of a chained method expression is the result of the last method call, thus the 'yourself' message at the end so that the object itself is stored into mainFrame.)Sigh...I miss Smalltalk.
Those who do not understand Lisp are doomed to reinvent it, poorly. :-)
Fairly good intro article though.
Edit: here's one, though I remember writing something else with examples. Oh well. http://news.ycombinator.com/item?id=304871
Yet another option might be with a custom method combination, which is overkill :-P
Any other ideas? or am I too off the ball park?