( ) Calling classes with arguments ( )

When you have generic classes that just need a tiny piece of information for being operational, it might look somehow clumsy to create a new class, inheriting of that class, and then, again, define a child for that new class, and then call it only once...

This is where this argument concept comes. You can, when you define a class, allow it to take arguments when called, and you can refer to these arguments as if they were regular children (which they actually are, through a kind of subclassing).



When defining the class, you terminate the name of the class with an opening bracket; after that bracket, you put the name of the symbols that will recieve the values the user is providing you, separated by the &, symbol. Terminate the argument sequence with the &) symbol:

&+<path>( @arg1 &, @arg2 &, ... &) (&=.... also possible, of course)


To give arguments to a class, terminate its name with an opening bracket, like when it was defined, and then put the arguments in sequence, separated by the same &, symbol. Terminate the argument sequence with &):

@<path>( &, &, ... &)

You are not required to put the same number of arguments as in the definition; extra arguments will be ignored and missing arguments will trigger no definition

When doing this call, it's like if you did that subclass thing, ie you create an anonymous class subclass of the one you are calling, defining the argument symbols

Having said this, there is an important difference to know between using arguments and subclassing:

calling a class with arguments will make it look the called class has these arguments as children in addition to the children it already has, while a subclass will inherit the definitions of the class (and not the children)

A little example


&=sayHelloTo( @name &)
Hello @name , nice to meet you!


@sayHelloTo( Saya &)
@sayHelloTo( Nadine &) 


Hello Saya , nice to meet you!
Hello Nadine , nice to meet you!

The call is equivalent to:

    &=super @parent.sayHelloTo &&
    &=name Saya &&

    &=super @parent.sayHelloTo &&
    &=name Nadine &&

You can see that the argument-way is much more compact! :-)

This is useful for having kinds of macros, for instance if you want to generate a comment, you could have the following macro:
&=comment( @i &&) /* @i */ &&
And then use it with
@comment( This is a comment &)
which generates:
/* This is a comment */

You will see how calling a class with fewer arguments that it had declared can be useful using pointing classes

Maxime Gamboni <> Last compiled : Wed Apr 23 21:53:44 CEST 2003