advice needed about default arguments for a method
Brian Rice
water at tunes.org
Tue Dec 14 19:27:18 UTC 2004
On Dec 14, 2004, at 9:42 AM, Stéphane Rollandin wrote:
> Brian Rice wrote:
>> Slate uses a language extension called optional keywords for this,
>> where any message-send may pass along a number of &-prefixed keywords
>> (read & as "with") and then ordinary expressions to override any
>> defaults for auxiliary inputs. Each method can then define auxiliary
>> inputs which it responds to and which can have default expressions to
>> initialize them.
>
> looks like lisp syntax...
Well, yeah, Slate was initially implemented as a dynamic compiler to/on
Common Lisp by a couple of long-time Lisp (and Squeak) users, so it
just seemed natural (to us). Also, we made the logical binary messages
/\ and \/ which freed up & and eliminated | ambiguity, so it fit to
re-use &. It actually looks like "messageSend &foo: fooValue &bar:
barValue" to be clear.
>> The auxiliary keywords can be passed in any order or combination. One
>> tiny annoyance is that adding keywords to any message-send raises its
>> arity to keyword-level instead of just binary or unary.
>> It's an idea; don't know if you'll like it. We have gradually
>> incorporated them more and more into the libraries and it has a
>> pleasant effect on the protocols.
>
> it could be exactly what I'm looking for. is this difficult to
> implement in a current Squeak image ?
That's an interesting question for someone else to answer. There's some
silly syntax kluge floating in Croquet code for C-wrapper calls that
uses optionals that might be instructive. Then again, it might be yet
another hack - these syntax extensions always raise grammar issues,
which is why we've been off toying with language ideas in a
from-scratch system.
In squeak, I usually just settle for the one-less-argument wrapper
method which supplies the default value to the original; it's a
reasonable emulation for keyword options <= 2, and in fact you could do
like Avi's multi-dispatch hack and just translate code with the
optional keywords into underlying methods which are what I describe as
emulation.
--
Brian T. Rice
LOGOS Research and Development
http://tunes.org/~water/
More information about the Squeak-dev
mailing list
|