praveenvvstgy / crack-language

Automatically exported from code.google.com/p/crack-language
Other
0 stars 0 forks source link

Feature request dart-like language constructor #123

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The dart language support for function-like constructor
such as Circle.fromPoint(1,2)
Circle.fromString("1,2")

that's a delicious feature, so request add into crack-language
such as 

Circle()
{
oper new.fromPoint(int a, int b);
oper new.fromString(String str);

}

Original issue reported on code.google.com by luoyongg...@gmail.com on 3 Sep 2013 at 3:11

GoogleCodeExporter commented 9 years ago
The default constructor turn out to be
Circle()
{
oper new();
}

Original comment by luoyongg...@gmail.com on 3 Sep 2013 at 3:11

GoogleCodeExporter commented 9 years ago
If I understand what you are requesting correctly, you can currently do the 
same thing with a static member function:

class Circle {
    @static fromPoint(int a, int b) { ... }
}

'oper new' fills a slightly different role, it will eventually allow you to 
override object creation prior to allocation, allowing you to implement things 
like shared instances or special memory allocation.

Is there something you were looking for that is not provided by this set of 
features?

Original comment by mmul...@google.com on 3 Sep 2013 at 3:02

GoogleCodeExporter commented 9 years ago
在 2013年9月3日 下午11:02, <crack-language@googlecode.com>写道:

language constructor

the same thing with a static member function:

That two different things, the static function do not make sure that always
calling the heap allocating first. But new.fromPoint did that.

Thay's the same concept with C++ that's accept multiple constructors,
what's I am saying is give those constructors with  a name, so that the
user can choose the proper constructor by the meaning of the name.

to override object creation prior to allocation, allowing you to implement
things like shared instances or special memory allocation.

of features?

Original comment by luoyongg...@gmail.com on 3 Sep 2013 at 3:11

GoogleCodeExporter commented 9 years ago
static member function is different from constructors,
constructor is a member function, so new.fromPoint is also a member function,
and besides it's a constructor, we can call it as "Named constructor"

Original comment by luoyongg...@gmail.com on 4 Sep 2013 at 1:58

GoogleCodeExporter commented 9 years ago
My initial reaction to this was that this is something that could be trivially 
implemented using annotations.  But I've since decided that that's not true.

(I started to write up the reasons for why it's not true, but they're more 
involved than I have the patience to write right now.  Ping me if anybody wants 
the details.)

So, the bottom line is: I'm considering this.  I agree that it would be a 
useful addition to the language and I think it would be a fairly trivial 
addition to the parser.  However, it's not going to happen before 1.0 unless 
somebody else implements it.

Original comment by mind...@gmail.com on 4 Sep 2013 at 1:35