On Tue, Sep 11, 2018 at 10:28:27PM -0700, ToddAndMargo wrote: : Okay, foul! : Str:D: Cool:D $needle : why is there not a comma between "Str:D:" and "Cool:D"? : And what is with the extra ":". By chance is the extra ":" : a confusing way of using a comma for a separator?
Well, "confusing" is kind of a value judgement, but yes, that is precisely how the parser is parsing it, as a funny-looking kind of comma. You could write it "Str:D :" with a space and it would still work. You can't just replace any old comma with a colon though. Replacing the comma with a colon is only allowed on the first argument, since we can have only one invocant for the current object. And in fact we MUST have an invocant in a method, so if you accidentally put comma instead of colon, the parser will assume you left the invocant out, and that the first argument is really the second argument. Arguably this is "confusing" if you don't know it's going to happen, but it's a great convenience for the vast majority of methods that don't care about the invocant, and where the user will just refer to the invocant as "self" if they do want to talk about it. : "Cool:D $needle" means that sub string or number you are : looking for. And it is constrained. You must enter a value. : : Foul again! : Int(Cool:D) $pos : Why "Int(Cool:D)"? Why is type Int being redefined : as type "Cool" (number or any type or a string). That is the wrong direction to think about it. Int is not being redefined as Cool:D there. The basic type there is just Int, and when the $pos comes in, it will end up being a simple Int. This syntax is called a "coercion type", and it just says that we can also accept anything that matches Cool:D and turn it into an Int. But the inside of the method knows nothing about the Cool:D part. Think of Int(Cool:D) as the signature matcher automatically applying the normal Int($coolthing) coercer for you to make sure you have an Int, precisely so that you *don't* have to worry about the Cool:D part inside the routine, but know that it simply an Int for any part of the routine after the signature. : $pos is the starting position to check for a match, : start at zero. : : Foul! : $pos is optional. But there is a "D" in its definition : making it constrained and not optional. No, that D is not part of its definition, which is simply Int. The D is part of the coercion type's signature. The coercion is only applied if there actually an argument passed. So Int(Cool:D) is allowed to default to an undefine Int to indicate no value was passed. You'd have to write Int:D(Cool) to mean the other thing, and then yes, it couldn't be optional. : And another foul! : There is no stating what the return value is. It : should be of single value of type Bool. Indeed, the signature should include --> Bool to indicate that. Larry