Re: Need help with Nil values

2016-02-23 Thread Lloyd Fournier
You could just do:

method new (Str $value?) { ... } # makes value optional

and then not pass anything to .new.

On Tue, Feb 23, 2016 at 1:27 PM TS xx <maringa...@hotmail.com> wrote:

> Thanks Brandon,
>
>
> That was what I was looking for.
>
> I'm trying it already.
>
>
> Regards,
>
> Emiliano
>
>
> --
> *From:* Brandon Allbery <allber...@gmail.com>
> *Sent:* Tuesday, February 23, 2016 2:21 AM
> *To:* TS xx
> *Cc:* perl6-users@perl.org
>
> *Subject:* Re: Need help with Nil values
> On Mon, Feb 22, 2016 at 9:15 PM, TS xx <maringa...@hotmail.com> wrote:
>
>> I expect $.value to hold Strings, but I want to be able to instantiate
>> MyClass whether I have a value already or not, and I also want to be able
>> to tell if $.value has a real String or not. Is this possible?
>
>
> You don't want Nil there; it's not the undefined value, it's a value of a
> special type. You want Str, the type object for Strings, which also serves
> as the undefined value (also true for other types). You can test it with
> `defined`.
>
> $myObject = MyClass.new(Str);
>
> then you can test $!value.defined or whatever.
>
> --
> brandon s allbery kf8nh   sine nomine
> associates
> allber...@gmail.com
> ballb...@sinenomine.net
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>


Re: Need help with Nil values

2016-02-22 Thread TS xx
Thanks,

That was it.
Somtimes I get confused with the way other languages treat undefined/null/nil 
values.

Regards,
Emiliano


From: Timo Paulssen <t...@wakelift.de>
Sent: Tuesday, February 23, 2016 2:20 AM
To: perl6-users@perl.org
Subject: Re: Need help with Nil values

Hello Emiliano,

In this case, I think you may want to use just "Str" instead of "Nil".
"Str" is the "type object" for Str objects, and you can check whether
it's a string like "foo" or just the Str object by checking $!value.defined.

There's a FAQ answer that's about "Any", but it works the same way for
"Str":

 http://doc.perl6.org/language/faq#What_is_%28Any%29%3F

And there's the classtut that talks about this a bit more in depth,
search for "type object":

 http://doc.perl6.org/language/classtut


I hope this'll get you towards your goal. If not, just keep asking :)

Have fun with Perl 6!
   - Timo



Re: Need help with Nil values

2016-02-22 Thread Brandon Allbery
On Mon, Feb 22, 2016 at 9:15 PM, TS xx  wrote:

> I expect $.value to hold Strings, but I want to be able to instantiate
> MyClass whether I have a value already or not, and I also want to be able
> to tell if $.value has a real String or not. Is this possible?


You don't want Nil there; it's not the undefined value, it's a value of a
special type. You want Str, the type object for Strings, which also serves
as the undefined value (also true for other types). You can test it with
`defined`.

$myObject = MyClass.new(Str);

then you can test $!value.defined or whatever.

-- 
brandon s allbery kf8nh   sine nomine associates
allber...@gmail.com  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonadhttp://sinenomine.net


Re: Need help with Nil values

2016-02-22 Thread Timo Paulssen

Hello Emiliano,

In this case, I think you may want to use just "Str" instead of "Nil". 
"Str" is the "type object" for Str objects, and you can check whether 
it's a string like "foo" or just the Str object by checking $!value.defined.


There's a FAQ answer that's about "Any", but it works the same way for 
"Str":


http://doc.perl6.org/language/faq#What_is_%28Any%29%3F

And there's the classtut that talks about this a bit more in depth, 
search for "type object":


http://doc.perl6.org/language/classtut


I hope this'll get you towards your goal. If not, just keep asking :)

Have fun with Perl 6!
  - Timo