[nem-en] Declaring Properties in the constructor - ala Boo

NoiseEHC NoiseEHC at freemail.hu
Fri Sep 29 22:14:21 CEST 2006


LOL, one more thing which makes me like Nemerle better...

In the world of overloading this syntax is the best way to shoot 
yourself into the leg.
I suppose that those initializer parameters are public properties so all 
you need is creating
some "with" macro (or lets just call it "init").

def a = A() init test = "test";

If boo accepted nonpublic fields too then it would be really stupid...


Mark Haniford wrote:
> That's not the same thing.  In Boo, you can have a default constructor 
> (or one with no arguments), and then supply as many property values as 
> you see fit at instantiation.  Your example just shows named 
> parameters, which is nice, but you still have to define your 
> constructor as normal, and at instantiation you still have to supply 
> the same number of arguments.  Notice in my example, that I only 
> defined the constructor with an int being passed in, and the string is 
> an optional property value.  See the link I posted earlier for the Boo 
> example.
>
>
> On 9/29/06, *vc* <vc at rsdn.ru <mailto:vc at rsdn.ru>> wrote:
>
>        > class SomeClass
>        > {
>        >     [Accessor(AnInt, flags=WantSetter)]
>        >     private mutable _an_int : int;
>        >
>        >     [Accessor(AString, flags=WantSetter)]
>        >     private mutable _a_string : string;
>        >
>        >
>        >     public this(i : int) {
>        >         AnInt = i;
>        >     }
>        > }
>        >
>        > sc = SomeClass(3, AString: "hello");
>
>        Nemerle already support this:
>
>        using Nemerle.Utility;
>
>        public class A
>        {
>          public this(test : string)
>          {
>            _test = test;
>          }
>
>          [Accessor] _test : string;
>        }
>
>        def a = A(test = "test");
>        _ = a;
>
>        And mach more! :)
>
>        using Nemerle.Utility;
>
>        [Record]
>        public class A
>        {
>          [Accessor] test : string;
>        }
>
>        def a = A(test = "test");
>        _ = a;
>
>
>     _______________________________________________
>     https://nemerle.org/mailman/listinfo/devel-en
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>   



More information about the devel-en mailing list