Re: .contains question
On 12/11/23 14:47, Andy Bach wrote: I have found that when using `say` for debugging, it has been known to print out the previous value of a variable and not the current value. `print` does not do this. That would certainly be a surprise to me. I'd think I was misunderstanding my program, rather than a bug in say. Hi Andy, 1) I can not duplicate the issue in a small program 2) I did a `say ($x)` on top of a `print "$x\n"` and got two different answers. The `say` was the previous value of the variable. (It about drove me crazy trying to figure out what was going on.) I have had this happen several times in my large programs. This makes me think it is an issue in the code optimizer. And it may very well be fixed now. In my Modula 2 days, I had to turn off the code optimizer as these issues were crazy making. So I did recognize the problem. So far, the only instance of optimizer problems I have found in Raku has been with `say`. And it is easily worked around. Raku itself is very well done and is fun to program in. If you have read any of my code, you know I have written print modules to write out in color and to write out to the STDERR: black, blue, green, red. I have been thinking of writing a `println`, but it would not be all that useful as I am always up to something at the end of the line. -T
Re: .contains question
> I have found that when using `say` for debugging, it has been known to print > out the > previous value of a variable and not the current value. `print` does not do > this. That would certainly be a surprise to me. I'd think I was misunderstanding my program, rather than a bug in say. From: ToddAndMargo via perl6-users Sent: Monday, December 11, 2023 3:24 PM To: perl6-users@perl.org Subject: Re: .contains question CAUTION - EXTERNAL: > "so" will collapse the junction into a Bool. > "say" will append a \n for you, so you don't have to. > >> On 11 Dec 2023, at 01:52, ToddAndMargo via perl6-users >> wrote: >> >>>> On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users >>>> wrote: >>>> >>>> Hi All, >>>> >>>> my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" ) { print >>>> "True\n"; } else { print "False\n" }; >>>> True >>>> >>>> Is there a way to tell .contains that you want to know >>>> if any of a sequence characters is in a string other that >>>> repeating || over and over. Any [a..z] or [0..9] option? >>>> >>>> Many thanks, >>>> -T >> >> On 12/10/23 15:24, Elizabeth Mattijsen wrote: >>> my @letters = ; >>> if $x.contains(any @letters) { >> >> >> Hi Elizabeth, >> >> Very interesting. Problem: I was looking for one answer, not many >> >>> my $x="abc45def";my @y=; print >>> $x.contains(any @y) ~ "\n"; >> True >> True >> True >> True >> True >> True >> False >> False >> False >> False >> False >> False >> False >> True >> True On 12/11/23 01:11, Elizabeth Mattijsen wrote: > my $x="abc45def"; > my @y=; say so $x.contains(any @y); Hi Elizabeth, Awesome! Thank you! I usually stay away from `say` as in my longer programs, I have found that when using `say` for debugging, it has been known to print out the previous value of a variable and not the current value. `print` does not do this. This is why you see me using `print` so often. And I can type, so the extra finger motions do not bother me. Capitol letter also do not for the same reason. Some tests! my $x="abc45def"; my @y=; say so $x.contains(any @y); True my $x="abc45def"; my @y=; say so $x.contains(any @y); False my $x="abc45def"; my @y=; say so $x.contains(any @y); True my $x="abc45def"; my @y=; say so $x.contains(any @y); False Oh now I am really pushing it with these (note the `all` in the second one)! my $x="abc45def"; say so $x.contains(any ); my $x="abc45def"; say so $x.contains(all ); False my $x="abc45def"; say so $x.contains(any ); True -T CAUTION - EXTERNAL EMAIL: This email originated outside the Judiciary. Exercise caution when opening attachments or clicking on links.
Re: .contains question
"so" will collapse the junction into a Bool. "say" will append a \n for you, so you don't have to. On 11 Dec 2023, at 01:52, ToddAndMargo via perl6-users wrote: On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users wrote: Hi All, my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" ) { print "True\n"; } else { print "False\n" }; True Is there a way to tell .contains that you want to know if any of a sequence characters is in a string other that repeating || over and over. Any [a..z] or [0..9] option? Many thanks, -T On 12/10/23 15:24, Elizabeth Mattijsen wrote: my @letters = ; if $x.contains(any @letters) { Hi Elizabeth, Very interesting. Problem: I was looking for one answer, not many my $x="abc45def";my @y=; print $x.contains(any @y) ~ "\n"; True True True True True True False False False False False False False True True On 12/11/23 01:11, Elizabeth Mattijsen wrote: > my $x="abc45def"; > my @y=; say so $x.contains(any @y); Hi Elizabeth, Awesome! Thank you! I usually stay away from `say` as in my longer programs, I have found that when using `say` for debugging, it has been known to print out the previous value of a variable and not the current value. `print` does not do this. This is why you see me using `print` so often. And I can type, so the extra finger motions do not bother me. Capitol letter also do not for the same reason. Some tests! my $x="abc45def"; my @y=; say so $x.contains(any @y); True my $x="abc45def"; my @y=; say so $x.contains(any @y); False my $x="abc45def"; my @y=; say so $x.contains(any @y); True my $x="abc45def"; my @y=; say so $x.contains(any @y); False Oh now I am really pushing it with these (note the `all` in the second one)! my $x="abc45def"; say so $x.contains(any ); my $x="abc45def"; say so $x.contains(all ); False my $x="abc45def"; say so $x.contains(any ); True -T
Re: .contains question
my $x="abc45def"; my @y=; say so $x.contains(any @y); "so" will collapse the junction into a Bool. "say" will append a \n for you, so you don't have to. > On 11 Dec 2023, at 01:52, ToddAndMargo via perl6-users > wrote: > >>> On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users >>> wrote: >>> >>> Hi All, >>> >>> my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" ) { print >>> "True\n"; } else { print "False\n" }; >>> True >>> >>> Is there a way to tell .contains that you want to know >>> if any of a sequence characters is in a string other that >>> repeating || over and over. Any [a..z] or [0..9] option? >>> >>> Many thanks, >>> -T > > On 12/10/23 15:24, Elizabeth Mattijsen wrote: > > my @letters = ; > > if $x.contains(any @letters) { > > > Hi Elizabeth, > > Very interesting. Problem: I was looking for one answer, not many > > > my $x="abc45def";my @y=; print > > $x.contains(any @y) ~ "\n"; > True > True > True > True > True > True > False > False > False > False > False > False > False > True > True > > > Many thanks, > -T > > -- > ~~ > Computers are like air conditioners. > They malfunction when you open windows > ~~ >
Re: .contains question
On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users wrote: Hi All, my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" ) { print "True\n"; } else { print "False\n" }; True Is there a way to tell .contains that you want to know if any of a sequence characters is in a string other that repeating || over and over. Any [a..z] or [0..9] option? Many thanks, -T On 12/10/23 15:24, Elizabeth Mattijsen wrote: > my @letters = ; > if $x.contains(any @letters) { Hi Elizabeth, Very interesting. Problem: I was looking for one answer, not many > my $x="abc45def";my @y=; print $x.contains(any @y) ~ "\n"; True True True True True True False False False False False False False True True Many thanks, -T -- ~~ Computers are like air conditioners. They malfunction when you open windows ~~
Re: .contains question
my @letters = ; if $x.contains(any @letters) { ... > On 10 Dec 2023, at 21:36, ToddAndMargo via perl6-users > wrote: > > Hi All, > > my Str $x="abc3defg"; if $x.contains( "a" || "b" || "3" ) { print "True\n"; > } else { print "False\n" }; > True > > Is there a way to tell .contains that you want to know > if any of a sequence characters is in a string other that > repeating || over and over. Any [a..z] or [0..9] option? > > Many thanks, > -T
Re: contains question
Yup, you can use it as a method call like this: perl6 -e '"foobar".&[~~](/foo/).say' 「foo」 HTH - Timo
Re: contains question
On Mon, Jun 12, 2017 at 4:07 PM, Elizabeth Mattijsenwrote: >> On 12 Jun 2017, at 22:04, Will Coleda wrote: >> On Mon, Jun 12, 2017 at 5:17 AM, Francesco Rivetti wrote: >>> if you can: >>> >>> $s ~~ "foo" >>> $s ~~ /foo/ >>> >>> then wouldn't be good to have also: >>> >>> $s.contains("foo"); >>> $s.contains(/foo/); >> >> The latter is currently available as: >> >>> "foobar".match(/'foo'/); >> 「foo」 > > That’s not entirely true, as .contains returns a Bool:D, not a Match object. > It *could* be interesting to not have to build the entire Match object > somehow and just return a Bool:D in case of contains. > > > Liz Sorry, you're right, it's: ?"foobar".match(/'foo'/); -- Will "Coke" Coleda
Re: contains question
On Mon, Jun 12, 2017 at 5:17 AM, Francesco Rivettiwrote: > if you can: > > $s ~~ "foo" > $s ~~ /foo/ > > then wouldn't be good to have also: > > $s.contains("foo"); > $s.contains(/foo/); The latter is currently available as: > "foobar".match(/'foo'/); 「foo」 > IOW, overload .contains() with Str and Regex > > F > > > On 06/12/2017 10:42 AM, Elizabeth Mattijsen wrote: >> >> >>> On 12 Jun 2017, at 01:27, ToddAndMargo wrote: >>> perl6 -e 'my $x = "\t"; if $x !~~ /<[A..Z a..z 0..9]>/ {say "out"} else >>> {say "in"}' >>> >>> Would this be easier to do with $x.contains? Or would it >>> be too worky? >> >> >> .contains only takes a *single string* to look up. So it is only useful >> for checking whether “foo” exists in “foo bar”: >> >>say “foo bar”.contains(“foo”) >> >> >> >> Liz >> > -- Will "Coke" Coleda
Re: contains question
On 06/12/2017 01:42 AM, Elizabeth Mattijsen wrote: On 12 Jun 2017, at 01:27, ToddAndMargowrote: perl6 -e 'my $x = "\t"; if $x !~~ /<[A..Z a..z 0..9]>/ {say "out"} else {say "in"}' Would this be easier to do with $x.contains? Or would it be too worky? .contains only takes a *single string* to look up. So it is only useful for checking whether “foo” exists in “foo bar”: say “foo bar”.contains(“foo”) Liz Thank you Liz! -- ~ When we ask for advice, we are usually looking for an accomplice. -- Charles Varlet de La Grange ~
Re: contains question
Thinking about this... > On 12 Jun 2017, at 11:17, Francesco Rivettiwrote: > > if you can: > > $s ~~ "foo" > $s ~~ /foo/ > > then wouldn't be good to have also: > > $s.contains("foo"); > $s.contains(/foo/); > > IOW, overload .contains() with Str and Regex > > F > > On 06/12/2017 10:42 AM, Elizabeth Mattijsen wrote: >>> On 12 Jun 2017, at 01:27, ToddAndMargo wrote: >>> perl6 -e 'my $x = "\t"; if $x !~~ /<[A..Z a..z 0..9]>/ {say "out"} else >>> {say "in"}' >>> >>> Would this be easier to do with $x.contains? Or would it >>> be too worky? >> .contains only takes a *single string* to look up. So it is only useful for >> checking whether “foo” exists in “foo bar”: >> say “foo bar”.contains(“foo”) >> Liz
Re: contains question
if you can: $s ~~ "foo" $s ~~ /foo/ then wouldn't be good to have also: $s.contains("foo"); $s.contains(/foo/); IOW, overload .contains() with Str and Regex F On 06/12/2017 10:42 AM, Elizabeth Mattijsen wrote: On 12 Jun 2017, at 01:27, ToddAndMargowrote: perl6 -e 'my $x = "\t"; if $x !~~ /<[A..Z a..z 0..9]>/ {say "out"} else {say "in"}' Would this be easier to do with $x.contains? Or would it be too worky? .contains only takes a *single string* to look up. So it is only useful for checking whether “foo” exists in “foo bar”: say “foo bar”.contains(“foo”) Liz
Re: contains question
> On 12 Jun 2017, at 01:27, ToddAndMargowrote: > perl6 -e 'my $x = "\t"; if $x !~~ /<[A..Z a..z 0..9]>/ {say "out"} else {say > "in"}' > > Would this be easier to do with $x.contains? Or would it > be too worky? .contains only takes a *single string* to look up. So it is only useful for checking whether “foo” exists in “foo bar”: say “foo bar”.contains(“foo”) Liz