Re: int and Str in sub declaration question

2020-01-12 Thread ToddAndMargo via perl6-users

On 2020-01-12 18:23, ToddAndMargo via perl6-users wrote:

On 2020-01-12 16:05, Joseph Brenner wrote:

This can be done with an explicit, named subset if you like:

   subset StrOrInt where Str | Int;

   sub do_stuff ( StrOrInt $item ) {
   say "$item is a " ~ $item.^name;
   }


Hi Joseph,

I like it.

Now to figure where to put it so it is apparent
when maintaining the code.  I will play
around with placement.

Thank you!

-T



$ p6 'subset StrOrUint where Str | uint32; my StrOrUint $x = -2.14'
Type check failed in assignment to $x; expected StrOrUint but got Rat 
(-2.14)

  in block  at -e line 1


Re: int and Str in sub declaration question

2020-01-12 Thread ToddAndMargo via perl6-users

On 2020-01-09 06:56, ToddAndMargo via perl6-users wrote:

    mailto:perl6-users@perl.org>> wrote:

    Hi All,

    In a sub declaration, is there a way to constrain
    a variable to only an "int32" or a "Str" (I want both)?
    Or do I have to put up with the other types of "Any"?

    Many thanks,
    -T



On Thu, 9 Jan 2020 at 08:13, WFB > wrote:


    Hi, Todd,

    If I understand your question right, then you mean something like 
that:


    sub do-soemthing($value where { .WHAT ~~ Str || .WHAT ~~ Int }) {}

    https://docs.raku.org/type/Signature#index-entry-where_clause

    Regards

    On Thu, 9 Jan 2020 at 03:58, ToddAndMargo via perl6-users



On 2020-01-08 23:14, WFB wrote:

For the sake of readability you might want use a subset:
https://docs.raku.org/language/typesystem#subset



Hi W,

Subset does no seems to be what I am after, but "where"
does.   Thank you!

-T


Hi W,

I might be changing my mind.  It would not be the
first time you have done that to me.

:-)

-T


Re: int and Str in sub declaration question

2020-01-12 Thread ToddAndMargo via perl6-users

On 2020-01-12 16:05, Joseph Brenner wrote:

This can be done with an explicit, named subset if you like:

   subset StrOrInt where Str | Int;

   sub do_stuff ( StrOrInt $item ) {
   say "$item is a " ~ $item.^name;
   }


Hi Joseph,

I like it.

Now to figure where to put it so it is apparent
when maintaining the code.  I will play
around with placement.

Thank you!

-T


Re: int and Str in sub declaration question

2020-01-12 Thread Joseph Brenner
This can be done with an explicit, named subset if you like:

  subset StrOrInt where Str | Int;

  sub do_stuff ( StrOrInt $item ) {
  say "$item is a " ~ $item.^name;
  }



On 1/9/20, ToddAndMargo via perl6-users  wrote:
 mailto:perl6-users@perl.org>> wrote:

 Hi All,

 In a sub declaration, is there a way to constrain
 a variable to only an "int32" or a "Str" (I want both)?
 Or do I have to put up with the other types of "Any"?

 Many thanks,
 -T

>
>>> On Thu, 9 Jan 2020 at 08:13, WFB >> > wrote:
>>>
>>> Hi, Todd,
>>>
>>> If I understand your question right, then you mean something like
>>> that:
>>>
>>> sub do-soemthing($value where { .WHAT ~~ Str || .WHAT ~~ Int }) {}
>>>
>>> https://docs.raku.org/type/Signature#index-entry-where_clause
>>>
>>> Regards
>>>
>>> On Thu, 9 Jan 2020 at 03:58, ToddAndMargo via perl6-users
>
>
> On 2020-01-08 23:14, WFB wrote:
>> For the sake of readability you might want use a subset:
>> https://docs.raku.org/language/typesystem#subset
>>
>
> Hi W,
>
> Subset does no seems to be what I am after, but "where"
> does.   Thank you!
>
> -T
>


Re: int and Str in sub declaration question

2020-01-09 Thread ToddAndMargo via perl6-users

mailto:perl6-users@perl.org>> wrote:

Hi All,

In a sub declaration, is there a way to constrain
a variable to only an "int32" or a "Str" (I want both)?
Or do I have to put up with the other types of "Any"?

Many thanks,
-T



On Thu, 9 Jan 2020 at 08:13, WFB > wrote:


Hi, Todd,

If I understand your question right, then you mean something like that:

sub do-soemthing($value where { .WHAT ~~ Str || .WHAT ~~ Int }) {}

https://docs.raku.org/type/Signature#index-entry-where_clause

Regards

On Thu, 9 Jan 2020 at 03:58, ToddAndMargo via perl6-users



On 2020-01-08 23:14, WFB wrote:

For the sake of readability you might want use a subset:
https://docs.raku.org/language/typesystem#subset



Hi W,

Subset does no seems to be what I am after, but "where"
does.   Thank you!

-T


Re: int and Str in sub declaration question

2020-01-08 Thread WFB
For the sake of readability you might want use a subset:
https://docs.raku.org/language/typesystem#subset

On Thu, 9 Jan 2020 at 08:13, WFB  wrote:

> Hi, Todd,
>
> If I understand your question right, then you mean something like that:
>
> sub do-soemthing($value where { .WHAT ~~ Str || .WHAT ~~ Int }) {}
>
> https://docs.raku.org/type/Signature#index-entry-where_clause
>
> Regards
>
> On Thu, 9 Jan 2020 at 03:58, ToddAndMargo via perl6-users <
> perl6-users@perl.org> wrote:
>
>> Hi All,
>>
>> In a sub declaration, is there a way to constrain
>> a variable to only an "int32" or a "Str" (I want both)?
>> Or do I have to put up with the other types of "Any"?
>>
>> Many thanks,
>> -T
>>
>


Re: int and Str in sub declaration question

2020-01-08 Thread WFB
Hi, Todd,

If I understand your question right, then you mean something like that:

sub do-soemthing($value where { .WHAT ~~ Str || .WHAT ~~ Int }) {}

https://docs.raku.org/type/Signature#index-entry-where_clause

Regards

On Thu, 9 Jan 2020 at 03:58, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> In a sub declaration, is there a way to constrain
> a variable to only an "int32" or a "Str" (I want both)?
> Or do I have to put up with the other types of "Any"?
>
> Many thanks,
> -T
>