4 ms·
Would someone be willing to break this down and explain it?
by btucker 16y ago
Would someone be willing to break this down and explain it?
- masak 16y agoBy all means. my @fib := ...; Bind something to an array variable. Assignment tends to follow infinite lists into the abyss. (But would also work, in this case, since the list is lazily evaluated.) 1, 2, *+* ...^ * >= 100; This is all governed by the `...^` in the middle, which is a lazy list generator. Three components, the seed, the iteration and the end condition, surround it. (Those three are much like a C `for` loop, come to think of it.) The seed is simply `1, 2`. The iteration is star-plus-star (which I can't figure out how to write out explicitly in this markup). This is ultimately syntactic sugar for a lambda with two parameters: `-> $a, $b { $a + $b }`. Or, put differently, this is a curried addition function. The end condition is `* >= 100`. Also curried; we could desugar it as either `-> $c { $c >= 100 }` or simply `{ $_ >= 100}`. It's a block that takes one argument and checks whether it's 100 or greater. The sequence operator `...^` has a little hat on it, meaning we're to discard the item that eventually matches the end condition. This is congruent with the fact that there is a range operator `..^` (note: two dots) which excludes its right endpoint.
- mjs 16y agoThanks for breaking that down, it's all, uh, a little terse. The ..^ operator (including the right endpoint?) doesn't do what I was expecting: > 1, 2, * + * ..^ * >= 100; 1 2 _block298 Also, this seems a little unfortunate: > 1, * + * ...^ * >= 100; ===SORRY!=== Method 'Bridge' not found for invocant of class 'Failure' (I was expecting some warning about the closure expecting two arguments, and only getting one.)
- masak 16y agoFrankly, so was I. I'll get back to you on that.