Re: User defined operators

Mariano Montone <[email protected]> Fri, 15 Jul 2005 12:21:20 -0300
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
Thaks for the tip Daniel.

Cheers, Marian


Daniel Bonniot escribi=F3:

>> I'm new to Nice I like the language (I think it is far better than=20
>> Java).
>
>
> Welcome ;-)
>
>> =BFIs it possible to define new (maybe oveloaded) operators at the use=
r=20
>> level?
>
>
> Yes, for those operators that are recognized by the parser, that is=20
> all logical and arithmetic operators.
>
>> I mean, suppose I have two objects such that I can write:
>>
>> objA.equals(objB.plus(objC));
>>
>> Is it possible to define the operators '+' and '=3D' such that the=20
>> following is valid?
>>
>> objA =3D objB + objC;
>
>
> =3D is special, it always denotes assignment, so it's not possible to=20
> overload it. I'm not sure if it would be a good idea to allow that, as=20
> it's nice to have some certitude about what =3D means in any context.=20
> But you can overload +. Suppose your objects are of class A:
>
> A `+`(A a1, A s2) ... // normal method declaration
>
> All operators are as normal methods, they just have special names,=20
> which requires that you use ``. The standard operators are actually=20
> defined like this in nice.lang (although many have a special body that=20
> generates bytecode directly).
>
>> What's more, I may want to add an operator '<<' such that I can write:
>>
>> mycol << objA;
>>
>> instead of:
>>
>> mycol.add(objA);
>
>
> Same thing, you should be able to define a method with name `<<`.
>
> Cheers,
>
> Daniel
>
>
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id=16492&op=3Dclick
> _______________________________________________
> Nice-info mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/nice-info
>


=09

=09
	=09
___________________________________________________________=20
1GB gratis, Antivirus y Antispam=20
Correo Yahoo!, el mejor correo web del mundo=20
http://correo.yahoo.com.ar=20




-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=3D7477&alloc_id=3D16492&op=3Dclic=
k