"new" method

0 views
Skip to first unread message

Jens Rieks

unread,
Apr 4, 2004, 12:30:09 PM4/4/04
to perl6-i...@perl.org, Leopold Toetsch
Hi,

Chromatic and I are unsure what the best name for a constructor method is.

Leo, is it time-consuming to fix IMCC in order to make it possible to use
"new" as a method name?

Is there something special to consider to avoid problems regarding several
languages? Is BUILD a good name for a non Perl6 constructor method?

jens


Leopold Toetsch

unread,
Apr 4, 2004, 1:17:50 PM4/4/04
to Jens Rieks, perl6-i...@perl.org
Jens Rieks <par...@jensbeimsurfen.de> wrote:
> Hi,

> Chromatic and I are unsure what the best name for a constructor method is.

.sub __init method

is AFAIK the constructor. It gets called automatically for all parent
classes and the class itself and is the best place to put attributes for
objects in place and set these to their default values.

> Leo, is it time-consuming to fix IMCC in order to make it possible to use
> "new" as a method name?

"new" isn't really easy to use. It's a Parrot op and second a keyword in
the lexer (which mightn't be really need anymore though).

> Is there something special to consider to avoid problems regarding several
> languages? Is BUILD a good name for a non Perl6 constructor method?

Well, constructors are class-namespace scoped anyway. So there shouldn't
be a problem.

> jens

leo

Chris

unread,
Apr 4, 2004, 3:46:44 PM4/4/04
to Jens Rieks, perl6-i...@perl.org
How about some variation on "create"?
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.593 / Virus Database: 376 - Release Date: 20/02/2004

Uri Guttman

unread,
Apr 4, 2004, 4:00:24 PM4/4/04
to Chris, Jens Rieks, perl6-i...@perl.org
>>>>> "C" == Chris <cdu...@shaw.ca> writes:

C> How about some variation on "create"?

just please make sure it has the missing 'e'. :)

uri

--
Uri Guttman ------ u...@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org

Chromatic

unread,
Apr 4, 2004, 4:16:33 PM4/4/04
to l...@toetsch.at, perl6-i...@perl.org
On Sun, 2004-04-04 at 10:17, Leopold Toetsch wrote:

> .sub __init method
>
> is AFAIK the constructor. It gets called automatically for all parent
> classes and the class itself and is the best place to put attributes for
> objects in place and set these to their default values.

I personally want to pass arguments to the initializer ("constructor"
really isn't the right term). I expect HLLs will want to do the same.

If we set a convention that the initializer is always called BUILD or
CREAT(E), that's fine. I'd like to set or follow a wise convention now.

-- c

Leopold Toetsch

unread,
Apr 5, 2004, 3:06:52 AM4/5/04
to Chromatic, perl6-i...@perl.org
Chromatic <chro...@wgz.org> wrote:
> On Sun, 2004-04-04 at 10:17, Leopold Toetsch wrote:

>> .sub __init method

> I personally want to pass arguments to the initializer ("constructor"


> really isn't the right term). I expect HLLs will want to do the same.

There isn't yet an official way to achieve this. But if you pass
arguments according to pdd03, the "__init" method get's it passed:

.sub _main
$P0 = newclass "A"
$I0 = find_type "A"
.local pmc obj
$P1 = new PerlString
$P1 = "a\n"
$P2 = new PerlString
$P2 = "b\n"
P5 = $P1
P6 = $P2
obj = new $I0
print "done\n"
end
.end

.namespace ["A"]
.sub __init method
.param pmc one
.param pmc two
print "A init\n"
print one
print two
.end

If you hide that hack in one place it should be easily changable.

> -- c

leo

Dan Sugalski

unread,
Apr 6, 2004, 10:42:55 AM4/6/04
to chromatic, l...@toetsch.at, perl6-i...@perl.org

It's not going to be called either--this'll be one of those things
where there'll be a property on the method marking it as the
constructor.

The current scheme's really inadequate for real new methods--what
we've got is more akin to an allocator rather than a real constructor.
--
Dan

--------------------------------------"it's like this"-------------------
Dan Sugalski even samurai
d...@sidhe.org have teddy bears and even
teddy bears get drunk

Reply all
Reply to author
Forward
0 new messages