4 ms·
> (2,4,8...*)[17] 262144 This one genuinely surprised me
by jddj 2y ago
> (2,4,8...*)[17]
262144
This one genuinely surprised me
- quink 2y agoMy brain immediately reached for the word 'horrifying', with phrases 'terrible consequences' and 'halting problem' soon after, but to each their own.
- labster 2y agoI believe that it only tries to DWIM with arithmetic and geometric sequences, and gives up otherwise. Of course there’s nothing keeping you from writing a module that would override infix:... in the local scope with a lookup in OEIS.
- b2gills 2y agoThis has nothing to do with the halting problem. And I have no idea why you think there would be 'terrible consequences'. 2, 4, 8 ... * The `...` operator only deduces arithmetic, or geometric changes for up-to the previous 3 values. Basically the above becomes 2, 4, 8, * × 2 ... * Since each value is just double the previous one, it can figure that out. If ... can't deduce the sequence, it will error out. 2, 4, 9 ... * Unable to deduce arithmetic or geometric sequence from: 2, 4, 9 Did you really mean '..'? in block at ./example.raku line 1 So I really don't understand how you would be horrified.
- jerf 2y agoProgramming is not just a matter of slinging syntax at a problem. Good programmers need to develop a mental model of how a language works. Needing to do geometric sequences as syntax like that is clearly a parlor trick, a marginal use case. What goes through a good programmer's mind, with experience of getting burned by such things over the years, is "If Raku implements this parlor trick, what other ones does it implement? What other numbers will do something I didn't expect when I put them in? What other patterns will it implement?" Yes, you can read the docs, and learn, but we also know this interacts with all sorts of things. I'm not telling you why you should be horrified, I'm explaining why on first glance this is something that looks actually quite unappealing and scary to a certain set of programmers. It actually isn't my opinion either. My opinion isn't so much that this is scary on its own terms, but just demonstrates it is not a language inline with any of my philosophies.
- donaldihunter 2y agoRaku has features that would appeal to mathematicians. It might seem like a parlour trick to you but that doesn't make it so for everyone.
- jerf 2y agoIt's a parlor trick because something like "1, * × 2 ..." is much more sensible. Heck, it isn't even longer, if we're talking about saving keystrokes. It's still more syntax than I'm looking for from a language, but "initial, update rule, continue infinitely" does not give me that immediate "oh wtf, what other magic is going to happen with other values?" reaction I describe from trying to divine update rules from raw numbers. It is also immediately obvious how to use this for other patterns, immediately obvious how to compose it, and just generally experiences all the benefits things get from not being special cases.
- mst 2y agoYou get either a compile time instantiated infinite lazy sequence, or a compilation error. My personal bar for "amount of clever involved" is fairly high when the clever either does exactly what you'd expect or fails, and even higher when it does so at compile time. (personal bars, and personal definitions of "exactly what you'd expect" will of course vary, but I think your brain may have miscalibrated the level of risk before it got as far as applying your preferences in this particular case)
- emmelaich 2y agoThe detecting of increments has been in Perl6 for ages so that's not new. [edit Perl6 not Perl) I guess (apart from the Whatever), the laziness is new since Perl6/Raku.
- JadeNB 2y ago> The detecting of increments has been in Perl for ages so that's not new. But this is detecting that the increment is multiplicative, rather than additive. It might seem like a natural next step, but, for example, I somewhat suspect (and definitely hope) that Raku wouldn't know that `(1, 1, 2...*)` is a (shifted) list of Fibonacci numbers.
- agumonkey 2y agovery cohesive, [7] > (1,3,9...*)[4,5] (81 243) [8] > (1,3,9...*)[(1..3)] (3 9 27) and nestable [0] > (1,2,4...*)[(1,2,4...*)[1,2,3]]
- justinator 2y agoThese are all very clever, but what's the use case? I'm not saying there isn't one, I just don't know what it is! Not to speak of the dead, but Perl was utilitarian: it was built to solve problems. From my point of view, these are solutions to problems I've never had.
- db48x 2y agoHere’s a nice article which uses this feature well (and several others) while computing e <https://blogs.perl.org/users/damian_conway/2019/09/to-compute-a-constant-of-calculusa-treatise-on-multiple-ways.html https://blogs.perl.org/users/damian_conway/2019/09/to-comput...>. An example: #| Dörrie's bounds assess -> \x=(1,10,100...10⁶) { ½ × sum (1 + x⁻¹)**(x), (1 + x⁻¹)**(x+1) }
- justinator 2y agoThat article was a RIDE.
- db48x 2y agoYea, I think he has a knack for that. If you want some more I recommend a talk he gave a few years back called “Three Little Words” <https://www.youtube.com/watch?v=e1T7WbKox6s https://www.youtube.com/watch?v=e1T7WbKox6s>.
- agumonkey 2y agoHa, Conway, once again. His talks during early perl6 days were brilliant.. thanks for sharing