osdir.com
mailing list archive

Subject: Re: Error calling bless in non-default constructor - msg#00006

List: lang.perl.perl6.compiler

Date: Prev Next Index Thread: Prev Next Index

Thanks for all your help. Interestingly enough the .perl method reports that
the parameter passed to the new method is stored in the object whether it's
defined as an attribute or not:

class MattTest {
has Str $.bar ;
submethod BUILD (:$foo) {
say "passed $foo";
$.bar = 'def' ;
}

}

my $test = MattTest.new(:foo('abc'));

# Check to see the class is the right kind of thing:

say $test.WHAT ;

# Output the class as a readable string

say $test.perl;

D:\Apps\Perl6>pugs ConstructorTest2.p6
passed abc
MattTest
\MattTest.new(("bar" => "def"), ("foo" => "abc"))

David Brunton <dbrunton@xxxxxxxxx> wrote: >I think so (after fixing a couple of
minor typos).
>
>Does this mean that you can only pass defined attributes to a constructor ?
>What if you want to pass parameters that are used during build but don't
>actually need to be stored in the object ?

Hopefully you don't mind my cc'ing the list- that way someone searching the
archives doesn't get stung by my typos ;)

Creating an object should have been:

my MattTest $test .= new(:string<abc>); # TIMTOADY and all that ;)

You can pass objects to BUILD that you don't store in the object:

class MattTest {
submethod BUILD (:$foo) {
say $foo;
}
}

hth,
-db.

my $test = MattTest(:string('abc'));

# Check to see the class is the right kind of thing:

say $test.WHAT

# Output the class as a readable string

say $test.perl;




----- Original Message ----
From: Matthew Keene
To: perl6-compiler@xxxxxxxx
Sent: Tuesday, May 15, 2007 5:02:56 AM
Subject: Error calling bless in non-default constructor

I'm trying to use a non-default constructor for a class under Pugs 6.2.13, like
so

class MattTest {

sub new (Class $class : Str $string) {
say "Passed $string to the constructor for $class" ;
return $class.bless ;
}

}

my $test = MattTest.new('abc') ;

This is failing with the following output:

D:\Apps\Perl6>pugs ConstructorTest.p6
Passed abc to the constructor for MattTest
*** No such method in class MattTest: "&bless"
at ConstructorTest.p6 line 5, column 12-25

Am I doing something wrong, or is bless currently unimplemented in Pugs, or is
something else wrong. I have more or less copied the code for the constructor
from the test in oo/construction.t.


---------------------------------
How would you spend $50,000 to create a more sustainable environment in
Australia? Go to Yahoo!7 Answers and share your idea.





____________________________________________________________________________________Get
the free Yahoo! toolbar and rest assured with the added security of spyware
protection.
http://new.toolbar.yahoo.com/toolbar/features/norton/index.php



---------------------------------
Switch to Yahoo!7 Mail: Transfer all your contacts and emails from Hotmail and
other providers to Yahoo!7 Mail. Switch now





---------------------------------
Get the free Yahoo! toolbar and rest assured with the added security of spyware
protection.


---------------------------------
How would you spend $50,000 to create a more sustainable environment in
Australia? Go to Yahoo!7 Answers and share your idea.
Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Re: Error calling bless in non-default constructor

>I think so (after fixing a couple of minor typos). > >Does this mean that you can only pass defined attributes to a constructor ? >What if you want to pass parameters that are used during build but don't >actually need to be stored in the object ? Hopefully you don't mind my cc'ing the list- that way someone searching the archives doesn't get stung by my typos ;) Creating an object should have been: my MattTest $test .= new(:string<abc>); # TIMTOADY and all that ;) You can pass objects to BUILD that you don't store in the object: class MattTest { submethod BUILD (:$foo) { say $foo; } } hth, -db. my $test = MattTest(:string('abc')); # Check to see the class is the right kind of thing: say $test.WHAT # Output the class as a readable string say $test.perl; ----- Original Message ---- From: Matthew Keene To: perl6-compiler@xxxxxxxx Sent: Tuesday, May 15, 2007 5:02:56 AM Subject: Error calling bless in non-default constructor I'm trying to use a non-default constructor for a class under Pugs 6.2.13, like so class MattTest { sub new (Class $class : Str $string) { say "Passed $string to the constructor for $class" ; return $class.bless ; } } my $test = MattTest.new('abc') ; This is failing with the following output: D:\Apps\Perl6>pugs ConstructorTest.p6 Passed abc to the constructor for MattTest *** No such method in class MattTest: "&bless" at ConstructorTest.p6 line 5, column 12-25 Am I doing something wrong, or is bless currently unimplemented in Pugs, or is something else wrong. I have more or less copied the code for the constructor from the test in oo/construction.t. --------------------------------- How would you spend $50,000 to create a more sustainable environment in Australia? Go to Yahoo!7 Answers and share your idea. ____________________________________________________________________________________Get the free Yahoo! toolbar and rest assured with the added security of spyware protection. http://new.toolbar.yahoo.com/toolbar/features/norton/index.php Switch to Yahoo!7 Mail: Transfer all your contacts and emails from Hotmail and other providers to Yahoo!7 Mail. Switch now ____________________________________________________________________________________Need a vacation? Get great deals to amazing places on Yahoo! Travel. http://travel.yahoo.com/

Next Message by Date: click to view message preview

x and xx operators fail when given negatives

"-" x -1 should evaluate to an empty string and 0 xx -1 should evaluate to an empty list. I have hacked pugs/src/Pugs/Prim.hs to correctly handle negatives, but I don't know Haskell very well and am not familiar with the layout of Pugs, so I may have written bad code in a bad place. I have also added tests to pugs/t/operators/repeat.t to test for correct handling of negative and zero values. Hopefully the patch will make it through to the list. replication.patch Description: Text Data

Previous Message by Thread: click to view message preview

Re: Error calling bless in non-default constructor

>I think so (after fixing a couple of minor typos). > >Does this mean that you can only pass defined attributes to a constructor ? >What if you want to pass parameters that are used during build but don't >actually need to be stored in the object ? Hopefully you don't mind my cc'ing the list- that way someone searching the archives doesn't get stung by my typos ;) Creating an object should have been: my MattTest $test .= new(:string<abc>); # TIMTOADY and all that ;) You can pass objects to BUILD that you don't store in the object: class MattTest { submethod BUILD (:$foo) { say $foo; } } hth, -db. my $test = MattTest(:string('abc')); # Check to see the class is the right kind of thing: say $test.WHAT # Output the class as a readable string say $test.perl; ----- Original Message ---- From: Matthew Keene To: perl6-compiler@xxxxxxxx Sent: Tuesday, May 15, 2007 5:02:56 AM Subject: Error calling bless in non-default constructor I'm trying to use a non-default constructor for a class under Pugs 6.2.13, like so class MattTest { sub new (Class $class : Str $string) { say "Passed $string to the constructor for $class" ; return $class.bless ; } } my $test = MattTest.new('abc') ; This is failing with the following output: D:\Apps\Perl6>pugs ConstructorTest.p6 Passed abc to the constructor for MattTest *** No such method in class MattTest: "&bless" at ConstructorTest.p6 line 5, column 12-25 Am I doing something wrong, or is bless currently unimplemented in Pugs, or is something else wrong. I have more or less copied the code for the constructor from the test in oo/construction.t. --------------------------------- How would you spend $50,000 to create a more sustainable environment in Australia? Go to Yahoo!7 Answers and share your idea. ____________________________________________________________________________________Get the free Yahoo! toolbar and rest assured with the added security of spyware protection. http://new.toolbar.yahoo.com/toolbar/features/norton/index.php Switch to Yahoo!7 Mail: Transfer all your contacts and emails from Hotmail and other providers to Yahoo!7 Mail. Switch now ____________________________________________________________________________________Need a vacation? Get great deals to amazing places on Yahoo! Travel. http://travel.yahoo.com/

Next Message by Thread: click to view message preview

x and xx operators fail when given negatives

"-" x -1 should evaluate to an empty string and 0 xx -1 should evaluate to an empty list. I have hacked pugs/src/Pugs/Prim.hs to correctly handle negatives, but I don't know Haskell very well and am not familiar with the layout of Pugs, so I may have written bad code in a bad place. I have also added tests to pugs/t/operators/repeat.t to test for correct handling of negative and zero values. Hopefully the patch will make it through to the list. replication.patch Description: Text Data
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by