[Xotcl] Mixins in XOTcl

Michael Schlenker schlenk at uni-oldenburg.de
Mon May 24 16:09:08 CEST 2004


Adam Turoff wrote:

> Uwe Zdun wrote:
> 
>>what about just extending the usually interfaces with new
>>arguments, such as:
>>
>>A mixin X
>>A mixin add Z 3
>>A mixin add Y end
>>A mixin delete Y
>>A instmixin add T 1
>>A superclass B
>>A superclass add C
> 
> 
> That's pretty much what I was thinking:
> 
>     A mixin X           ;# current behavior
>     A mixin -set X      ;# A mixin X
>     A mixin -set X Y Z  ;# A mixin {X Y Z}
> 
>     A mixin -add X      ;# A mixinappend X
> 
> Using -set, -add and -delete feels more Tcl-ish.  Also, it
> is somewhat bad style to name a class 'add', but even worse
> style to name it '-add'.  By using options, I can still
> mixin a class 'add' into a definition.  Preventing me from
> mixing in a class '-add' is a good idea, for other reasons.

I wouldn't say an option for an action feels more Tcl-ish. I do not know 
any tcl command that uses options to specifiy an action, its nearly 
always a subcommand and options just specify details.
If you want to prevent things from happening add assertions or make it 
explicit. In Tcl you name variables and procs as you like, even space, 
\n \r or any kind of unicode fancyness is in principle supported and 
there is no need to break this tradition for class names or mixin names.

So:
A mixin set foo bar baz
A mixin add boing
A mixin delete foo

feels quite natural, its verbose but thats usual Tcl style.

Why shouldn't you be able to add an mixin 'add' after the change?

A mixin add add

Syntax would probably be:

obj mixin ?subcmd args? , with subcmds add delete set
or
obj mixin mixinlist

So if the llength is 4 or greater the first behaviour is used, with just 
one extra arg the old behaviour could be used.

Michael





More information about the Xotcl mailing list