William Michels<w...@caa.columbia.edu> wrote: > I went over this with Joe as well, and I was > equally confused.
Part of our trouble was we were playing around with the routine form of comb (rather than the Str method), which had a bug in it with the :match option (which lizmat just fixed). Even when we tried the Right Thing it was still going wrong. But then, like I was saying at the time, I really needed to re-read the material on subroutine signatures-- I wasn't even sure if the ":match" flag was supposed to be positional or not-- a point Yary picked up on. > So if I understand what you're > saying correctly, if we see something like "Bool > :$match" that says we should drop the dollar-sign > ($) and enter ":match" to set "Bool" = True, and > thus return the list of match objects? Something like that. The ":$match" declares a variable named $match for use inside the routine-- it also makes it a little simpler to work with an input variable also named $match. Take this as an example: sub doom_flag (Bool :$flag) { if $flag { # declared by the sub signature, no "my $flag" say "The flag is UP" } else { say "The flag is down." } } doom_flag(); # The flag is down. # All of the following invocations say: # The flag is UP doom_flag( flag => True ); doom_flag( :flag ); my $flag = True; doom_flag( flag => $flag ); doom_flag( :$flag ); That last one is a funny short-cut for entering a Pair that's built-in to Raku: it's pretty common when you're working with named arguments to end up with code that looks redundant, like this: make_connection( ip => $ip, user => $user, pw => $pw ); But you could just use "colon-pair"s and do it like this: make_connection( :$ip, :$user, :$pw ); Does this make more sense? There's a few different idiomatic short-cuts here that I think are supposed to seem similar and suggest each other... On 11/16/19, William Michels <w...@caa.columbia.edu> wrote: > Hi Yary, > > I went over this with Joe as well, and I was equally confused. So if I > understand what you're saying correctly, if we see something like > "Bool :$match" that says we should drop the dollar-sign ($) and enter > ":match" to set "Bool" = True, and thus return the list of match > objects? > > On another note (or possibly the same note), I tried code similar to > Joe's with fair success. I was able to get the REPL to understand a > "True" or "False" parameter, but never in conjunction with a "$limit" > parameter. Is this the correct behaviour, and why? > >> #REPL > Nil >> say comb(/\w/, "a;b;c", False).perl; > ().Seq >> say comb(/\w/, "a;b;c", True).perl; > ("a",).Seq >> say comb(/\w+/, "a;b;c", True).perl; > ("a",).Seq >> say comb(/\w+/, "a;b;c", 2).perl; > ("a", "b").Seq >> say comb(/\w+/, "a;b;c", 3).perl; > ("a", "b", "c").Seq >> say comb(/\w+/, "a;b;c", 4).perl; > ("a", "b", "c").Seq >> say comb(/\w+/, "a;b;c", True).perl; > ("a",).Seq >> say comb(/\w+/, "a;b;c", 2, True).perl; > Too many positionals passed; expected 2 or 3 arguments but got 4 > in block <unit> at <unknown file> line 1 > >> say comb(/\w+/, "a;b;c", 2, :True).perl; > Unexpected named argument 'True' passed > in block <unit> at <unknown file> line 1 > >> $*VM > moar (2019.07.1) > > Any help appreciated, Bill. > > > > > On Mon, Nov 11, 2019 at 9:46 AM yary <not....@gmail.com> wrote: >> >> The syntax is in the declaration you pasted in your email >> >> > multi sub comb(Regex:D $matcher, Str:D $input, $limit = Inf, Bool >> > :$match) >> >> The colon in "Bool :$match" makes it a named argument. Not sure where >> definitive docs are, decent starting point is >> https://docs.perl6.org/type/Signature#Positional_vs._named_arguments >> >> >> -y >> >> >> On Sun, Nov 10, 2019 at 11:18 PM Joseph Brenner <doom...@gmail.com> >> wrote: >>> >>> Thanks, that form does what I want-- >>> >>> I don't see how I could've understood that from the docs, though. >>> For example, I don't see any place where the :match adverb is >>> mentioned for either the method or routine form of comb. >>> >>> >>> >>> On 11/10/19, Elizabeth Mattijsen <l...@dijkmat.nl> wrote: >>> > dd "foobar".comb(/./, :g, :match); >>> > (「f」 「o」 「o」 「b」 「a」 「r」) >>> > >>> >> On 10 Nov 2019, at 23:46, Joseph Brenner <doom...@gmail.com> wrote: >>> >> >>> >> Can someone give me an example of how to use the comb routine to >>> >> return a list of match objects? >>> >> >>> >> The documentation here: >>> >> >>> >> https://docs.perl6.org/type/Str#routine_comb >>> >> >>> >> Mentions a boolean option to get match objects: >>> >> >>> >>> If $matcher is a Regex, each Match object is >>> >>> converted to a Str, unless $match is set. >>> >> >>> >> I gather that I must be reading this signature >>> >> wrong somehow, I can't get it to work: >>> >> >>> >>> multi sub comb(Regex:D $matcher, Str:D $input, $limit = Inf, Bool >>> >>> :$match) >>> >> >>> >> I keep trying variations of things like this: >>> >> >>> >> my @hits = comb(m/$search_pattern/, $chunk, 100, True); >>> > >