Re: valid values?

2019-05-12 Thread yary
ck at main.p6 line 1* >> >> Which brings up another question- how to coerce $value to Int? These >> don't work, even though IntStr has an Int() method. >> >> sub MAIN(Int(IntStr) $value where $value ∈ (1,2,4,8,16)) {say >> "\$value.perl = ",$value.

Re: valid values?

2019-05-12 Thread yary
line 1* > > Which brings up another question- how to coerce $value to Int? These don't > work, even though IntStr has an Int() method. > > sub MAIN(Int(IntStr) $value where $value ∈ (1,2,4,8,16)) {say > "\$value.perl = ",$value.perl } > sub MAIN(Int() $value where $va

Re: valid values?

2019-05-12 Thread yary
y "\$value.perl = ",$value.perl } -y On Thu, Apr 18, 2019 at 5:31 PM mimosinnet wrote: > El Sunday, 03 de March del 2019 a les 02:09, ToddAndMargo via perl6-users > va escriure: > > >I want to pass an integer to a sub. The only > >valid values of the integer are 1, 2

Re: valid values?

2019-04-18 Thread mimosinnet
El Sunday, 03 de March del 2019 a les 02:09, ToddAndMargo via perl6-users va escriure: I want to pass an integer to a sub. The only valid values of the integer are 1, 2, 4, 8, and 16. Other than using "if" to test their values, is there a way to state that an integer can only ha

Re: valid values?

2019-03-04 Thread Norman Gaywood
On Tue, 5 Mar 2019 at 01:23, Brad Gilbert wrote: > > Somewhere on the Internet I layed out the rules that I think that > should normally be followed, but I am not sure where. > Perhaps: https://stackoverflow.com/questions/54338491/string-matching-in-main-parameters -- Norman Gaywood, Compute

Re: valid values?

2019-03-04 Thread Tom Browder
On Mon, Mar 4, 2019 at 8:22 AM Brad Gilbert wrote: ... > Somewhere on the Internet I layed out the rules that I think that > should normally be followed, but I am not sure where. ... It would be nice to find it and add to the docs. -Tom

Re: valid values?

2019-03-04 Thread Brad Gilbert
> Hi Todd, >> > is this what you're looking for? >> > >> > sub mysub(Int $value where * ~~ 1|2|4|8|16) >> > { >> > say "Got $value" >> > } >> > >> > mysub 2; # Got 2 >> > mysub 3; # Constraint type check fai

Re: valid values?

2019-03-04 Thread Fernando Santagata
t; > > } > > > > mysub 2; # Got 2 > > mysub 3; # Constraint type check failed in binding to parameter > '$value'; expected anonymous constraint to be met but got Int (3) > > > > On Sun, Mar 3, 2019 at 11:09 AM ToddAndMargo via perl6-users < > per

Re: valid values?

2019-03-04 Thread ToddAndMargo via perl6-users
On 3/3/19 8:29 PM, Brad Gilbert wrote: It should be sub mysub(Int $value where 1|2|4|8|16) { say "Got $value" } :-)

Re: valid values?

2019-03-03 Thread Brad Gilbert
dAndMargo via perl6-users > wrote: >> >> Hi All, >> >> I want to pass an integer to a sub. The only >> valid values of the integer are 1, 2, 4, 8, and 16. >> >> Other than using "if" to test their values, is >> there a way to state that a

Re: valid values?

2019-03-03 Thread ToddAndMargo via perl6-users
On 3/3/19 4:09 AM, Fernando Santagata wrote: On Sun, Mar 3, 2019 at 11:41 AM ToddAndMargo via perl6-users mailto:perl6-users@perl.org>> wrote: That way I can catch bad values at compile time and not have to wait and see what it gets fed. The snippet I showed you doesn't intercepts wro

Re: valid values?

2019-03-03 Thread Fernando Santagata
On Sun, Mar 3, 2019 at 11:41 AM ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > That way I can catch bad values at compile time and not have > to wait and see what it gets fed. > The snippet I showed you doesn't intercepts wrong values at compile time, but rather at run time. -- F

Re: valid values?

2019-03-03 Thread ToddAndMargo via perl6-users
> On Sun, Mar 3, 2019 at 11:09 AM ToddAndMargo via perl6-users > mailto:perl6-users@perl.org>> wrote: > > Hi All, > > I want to pass an integer to a sub. The only > valid values of the integer are 1, 2, 4, 8, and 16. > > Other than using "if

Re: valid values?

2019-03-03 Thread Fernando Santagata
, Mar 3, 2019 at 11:09 AM ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > Hi All, > > I want to pass an integer to a sub. The only > valid values of the integer are 1, 2, 4, 8, and 16. > > Other than using "if" to test their values, is > there a way to s

valid values?

2019-03-03 Thread ToddAndMargo via perl6-users
Hi All, I want to pass an integer to a sub. The only valid values of the integer are 1, 2, 4, 8, and 16. Other than using "if" to test their values, is there a way to state that an integer can only have certain predefined values? Many thanks, -T -- ~~~ H