On Jul 30, 2007, at 9:52 PM, Marcel Weiher wrote:
> However, the fact that you need to use #perform: when you want to have
> a variable selector has bothered me for some time, because it is a
> weird asymmetry that, for example, functional programming languages do
> not seem to share: if you get passed a function (function pointer in
> C and the like), you can call it using natural syntax. So what I
> would like to see would be some sort of "selector variable", a
> variable that can be used in a standard message expression but is
> actually variable:
>
> | variableSelector:withArg: |
>
> variableSelector:withArg: := self computeSelector.
> " probably
> need to check arity for compatibility here "
> self variableSelector:'hello' withArg:2.
>
> Not sure this is workable/agreeable in a Smalltalk context, but
> something like it would be really nice. IMHO.
I very occasionally run across situations like this as well, where I
am computing a selector and would like to send it using direct syntax.
Relatedly, I sometimes find myself wanting to do things like
self (aBoolean
ifTrue: [someMethod]
ifFalse: [someOtherMethod])
but need to write
aBoolean
ifTrue: [self someMethod]
ifFalse: [self someOtherMethod]
instead. This makes more of a difference if the receiver is the
result of a more complex expression than "self" - then you have to
either repeat the expression, or assign a variable, or extract a name.
(Of course this is all by analogy with using the value of an "if"
expression - e.g.
^ aBoolean
ifTrue: [5]
ifFalse: [7]
instead of
aBoolean
ifTrue: [^ 5]
ifFalse: [^ 7].)
The same goes
I'm not convinced this wouldn't be awkward in the end - or that the
desire to write expressions like the above isn't really an indication
of underfactoring in my code. In any case, Marcel's idea reminded me
and I thought it might be interesting to mention.
Benjamin Schroeder
_______________________________________________
fonc mailing list
[email protected]
http://vpri.org/mailman/listinfo/fonc