Hello Timo, and thank you for taking the time to explain how "comb" routine signatures work. I have no doubt your description is the correct way to use comb routine(s) in Raku/Perl6.
First of all, I should preface my remarks by saying that I'm using Rakudo (moar) 2019.07.1, with the Linenoise module to run the Raku/Perl6 REPL. It has been suggested to me that my install might somehow be broken, because I tried to 'roll-my-own' Rakudo-Star release (basically I copied over pre-installed modules from my Rakudo 2019.03 install, and ran 'zef update'). In any case, I haven't been able to get the code you posted to work. I checked all six examples in the REPL, and the last example I checked at the command line as well. I'm hoping someone on the list running Rakudo (moar) 2019.07.1 can confirm/refute my results: > #Timo Nil > comb(/\w/, "a;b;c", match => True); Unexpected named argument 'match' passed in block <unit> at <unknown file> line 1 > comb(/\w/, "a;b;c", :match); Unexpected named argument 'match' passed in block <unit> at <unknown file> line 1 > comb(/\w/, "a;b;c", :match(True)); Unexpected named argument 'match' passed in block <unit> at <unknown file> line 1 > comb(/\w/, "a;b;c", :!match); Unexpected named argument 'match' passed in block <unit> at <unknown file> line 1 > comb(/\w/, "a;b;c", :match(False)); Unexpected named argument 'match' passed in block <unit> at <unknown file> line 1 > comb(/\w/, "a;b;c", 2, :match); Unexpected named argument 'match' passed in block <unit> at <unknown file> line 1 > $*VM moar (2019.07.1) > > exit mbook:~ homedir$ perl6 -e 'comb(/\w/, "a;b;c", 2, :match);' Unexpected named argument 'match' passed in block <unit> at -e line 1 mbook:~ homedir$ As for what's going on, I'm wondering if there might be an issue with "comb" signatures in general. There exists both a '(Str) routine comb' and a '(Cool) routine comb'. Maybe these two routines are somehow interfering with each other? Thank you, and any further help appreciated, Bill. On Sat, Nov 16, 2019 at 6:34 AM Timo Paulssen <t...@wakelift.de> wrote: > > Hi Bill, > > In your repl examples you're actually passing the True or False as a > positional parameter, which makes it go into the slot for $limit, not the > slot for :$match. > > In order to pass true or false for the "match" named parameter you have > different syntactical options: > > comb(/\w/, "a;b;c", match => True) # maybe the simplest is using a pair > > comb(/\w/, "a;b;c", :match) # using "colon pair" syntax; it's syntax that > puts a colon at the beginning and makes a pair > > comb(/\w/, "a;b;c", :match(True)) # :match is short for match => True, and > :match(True) is long for match => True > > comb(/\w/, "a;b;c", :!match) # putting a ! after the : negates the pair, > i.e. it's now match => False > > comb(/\w/, "a;b;c", :match(False)) # same value > > And on top of that, you can add the third positional parameter to pass a > value for $limit > > comb(/\w/, "a;b;c", 2, :match) # output up to two results, as match objects > > Here's a few comments on the examples you pasted: > > > > 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? > The surprise here comes from Bool actually being derived from Int, and > therefore being totally acceptable values to pass for $limit. > >> #REPL > Nil >> say comb(/\w/, "a;b;c", False).perl; > ().Seq You can see > >> here that it gave no results; that's because it interpreted the False as 0 > >> in the $limit parameter. > > >> say comb(/\w/, "a;b;c", True).perl; > ("a",).Seq > Here the True is interpreted as 1 for $limit, giving you just "a", and it's a > string because the match named parameter wasn't given and defaulted to False. > >> say comb(/\w+/, "a;b;c", True).perl; > ("a",).Seq > The difference between \w and \w+ isn't noticeable here, as the source string > only ever has single word character in a row, but you can try with "ab;cd;ef" > for example with both \w and \w+. > > >> 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 > Same as above; True being interpreted as 1 > > >> 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 > There's no syntax here that distinguishes 2, a positional parameter, from > True, also a positional parameter. > > >> say comb(/\w+/, "a;b;c", 2, :True).perl; > Unexpected named argument > >> 'True' passed in block <unit> at <unknown > file> line 1 > The issue here is that :True is short for True => True, i.e. passing the > value True to the named parameter called "True", easy to get confused by the > error message here! > > Any help appreciated, Bill. > > I hope the explanations make sense! > - Timo