9 ms·
Unusual Raku Features
- 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
- quink 2y agoI’m not sure this page loaded properly for me, half of it is arbitrary punctuation characters assembled in bizarre nonsensical ways.
- deleted 2y ago[deleted]
- trescenzi 2y agohttps://imgur.com/uMuoeuC https://imgur.com/uMuoeuC
- yen223 2y agoThat's an interesting way to describe the English language.
- b2gills 2y agoI've often thought of Raku as being a lot like the English language. It borrows heavily from other languages. Of course since Raku has the benefit of an actual designer, it is more cohesive than English.
- sbierwagen 2y agoThe greatest trick the Devil ever played was renaming Perl 6 to Raku.
- 0xpgm 2y agoThis is a very funny comment given the context. https://github.com/Raku/problem-solving/pull/89#pullrequestreview-300789072 https://github.com/Raku/problem-solving/pull/89#pullrequestr... A quote from the Christian Bible Luke 5:36,37
- cutler 2y agoAgreed. The "Perl 6 is a different language" meme was so overdone. To anyone who actually used Perl 5 the continuity was obvious.
- broodbucket 2y agoIt is absolutely mindbending to me that all of this language development has happened on top of Perl, of all things.
- JadeNB 2y ago> It is absolutely mindbending to me that all of this language development has happened on top of Perl, of all things. Why "of all things?" The Perl philosophy of TIMTOWTDI, and Wall's interest in human-language constructs and the ways that they could influence programming-language constructs, seem to make its successor an obvious home for experiments like this.
- emmelaich 2y agoIndeed! There's lots of magic even in Perl4, some of it obscure.
- rjh29 2y agoIt has the same whimsy and DWIM of perl, look at Promise having a status of 'kept' or 'broken' which is more fun than 'fulfilled' or 'rejected'. Brings to mind Perl 5's use of bless, calling the filter function 'grep' and local/global variables created with 'my' and 'our'.
- JadeNB 2y agoDon't forget `tainted` (https://perldoc.perl.org/perlsec#Laundering-and-Detecting-Tainted-Data https://perldoc.perl.org/perlsec#Laundering-and-Detecting-Ta...)!
- dragonwriter 2y agoWasn’t Raku/Perl6 basically a ground-up reconception more than a building-on-top of existing Perl5?
- mst 2y agoYes, though perl5 is also an incredibly bendable language syntax wise - you can add keywords and operators to the compiler via CPAN modules (our async/await syntax is provided simply by doing 'use Future::AsyncAwait' for example).
- emmelaich 2y ago> (2, 30, 4, 50).map(* + *) returns (32, 45) Should it be `returns (32, 54)` ? i.e. 4+50 for the 2nd term. Maybe this is a consequence (head translation) of some countries saying e.g. vierenvijftig (four and fifty) instead of the English fifty-four.
- agumonkey 2y agochecked in rakudo, it does return (32 54), author fingers slipped
- fuzztester 2y ago[flagged]
- fuzztester 2y ago[flagged]
- christophilus 2y agoWow. Sign me up for leaving the industry before I ever have to maintain a Raku codebase.
- agumonkey 2y agoFunny, cause reading that blog post made me want to quit my job and find a raku team to work with. Maybe I'm still too naive :)
- fuzztester 2y agoyeah, you're right. your entire comment is syntactically valid raku, or can be made so, because raku syntax is so powerful and flexible. raku grammars ftw! https://docs.raku.org/language/grammars https://docs.raku.org/language/grammars https://docs.raku.org/language/grammar_tutorial https://docs.raku.org/language/grammar_tutorial ;) even that last little fella above, is or can be made syntactically valid.
- TOGoS 2y agoSame. And it's a bit funny because I'm usually against unnecessary complexity, and here's a language that seems to have embraced it and become a giant castle of language features that I could spend weeks studying. Maybe it's because Raku's features were actually well thought-out, unlike the incidental "doesn't actually buy me anything, just makes the code hard to deal with" complexity I have to deal at work day in and day out. Maybe if Java had a few of these features back in the day people wouldn't've felt the need to construct these monstrous annotation soup frameworks in it.
- redrobein 2y agoI think it has to do more with familiarity than complexity. You could have a good understanding of features like the ones showcased in the blogpost, but it could take you a minute of staring at a line to parse it if someone uses it in a way you're unfamiliar with. Doing that for potentially hours on end would be a pain. It's definitely something I'd write for fun/personal projects but can't imagine working with other people in. On a side note, I believe this is where go's philosophy of having a dead simple single way of doing things is effective for working with large teams.
- jimberlage 2y agoSo I guess Perl is a gateway drug for the APL family of languages now?
- riffraff 2y agoyes, and the post didn't even touch on metaoperators e.g. # use the reduce metaoperator [ ] with infix + to do "sum all" [+] 1, 2, 3
- b2gills 2y agoThat's nothing, use it to calculate the sum of range of values say [+] 1..10000000000000000000000000000000000000000000 Which will result in you getting this back in a fraction of a second 50000000000000000000000000000000000000000005000000000000000000000000000000000000000000 (It actually cheats because that particular operator gets substituted for `sum` which knows how to calculate the sum of a Range object.)
- tail_exchange 2y ago# Does weird things with nested lists too > [1, [2, 3], 4, 5] <<+>> [10, 20] [11 [22 23] 14 25] This article makes me feel like I'm watching a Nao Geo/Animal Planet documentary. Beautiful and interesting to see these creatures in the wild? Absolutely. Do I want to keep my distance? As far away as possible.
- fuzztester 2y agoNational Geographic for the uninitiated. https://en.m.wikipedia.org/wiki/National_Geographic https://en.m.wikipedia.org/wiki/National_Geographic https://www.nationalgeographic.com/magazine https://www.nationalgeographic.com/magazine
- klibertp 2y agoYou're making a mistake if you're thinking like that. Applying an operation that generally works on single values over a list of values automatically is an incredibly powerful technique. If you have ever used Numpy, you will appreciate not needing it in many cases where Raku's built-ins suffice.
- tail_exchange 2y agoYou're right. It makes way more sense when you compare it to Numpy.
- JadeNB 2y ago> You're making a mistake if you're thinking like that. Applying an operation that generally works on single values over a list of values automatically is an incredibly powerful technique. Indeed, the defining technique of array programming!
- ekidd 2y agoMy fundamental objection here it that it is recursive. The non-recursive hyperoperators all have nice clean mathematical definitions. The recursive ones are just weird and ad hoc, at least from the perpective of the underlying mathematical structures.
- lmm 2y agoSome of these are halfway familiar. Hyper sounds like a more ad-hoc version of something from recursion-schemes, and * as presented is somewhat similar to Scala _ (which I love for lambdas and think every language should adopt something similar).
- mempko 2y agoI use Raku in production. It's the best language to deal with text because building parsers so so damn nice. I'm shocked this isn't the top language to create an LLM text pipeline.
- antononcube 2y agoDo you use any of Raku's LLM packages? If yes, which ones?
- mempko 2y agoI have not used any. What are some good ones to look at?
- bloopernova 2y agoVery late to the thread, but I was wondering if you knew of a good example of Raku calling an API over https, polling the API until it returns a specific value?
- antononcube 2y agoHere is one way: use HTTP::UserAgent; use JSON::Fast; my $url = 'https://api.coindesk.com/v1/bpi/currentprice.json'; my $ua = HTTP::UserAgent.new; my $total-time = 0; loop { my $response = $ua.get($url); if $response.is-success { my $data = from-json $response.content; my $rate = $data<chartName>; say "Current chart name: $rate"; #last if $rate eq 'Bitcoin'; last if $total-time ≥ 16; } else { say "Failed to fetch data: {$response.status-line}"; } sleep 3; # Poll every 3 seconds $total-time += 3; } (Tweak / uncomment / rename the $rate variable assignments and checks.)
- bloopernova 2y agoWow, huge thanks, that's super helpful :)
- James_K 2y agoShocking that they stopped at five.
- b2gills 2y agoI'm sure that there has been more changes from Perl 5.8 to Perl 5.40 than there is between Python 2.0 to Python 3.x (Whatever version it is up to at the moment.) What's more is that every change from Python 2 to Python 3 that I've heard of, resembles a change that Perl5 has had to do over the years. Only Perl did it without breaking everything. (And thus didn't need a major version bump.)
- agnishom 2y agoI don't understand why we want to use some language feature like Junctions, instead of using lists explicitly?
- Joker_vD 2y agoPowerShell does something similar with their pipelines, see e.g. the answer [0] and the question it answers. Something similar happens in Bash: $x refers not to the string $x, but to the list of the strings that you get by splitting the original string by IFS. And yes, this feature is annoying and arguably is a mis-feature: containers shall not explode when you touch them. [0] https://stackoverflow.com/a/56977142 https://stackoverflow.com/a/56977142
- ab5tract 2y agoI’m not sure that I see the connection that you are making here. Can you elaborate? Also note that in contrast to Bash, Junction is a type. Regarding their utility, at their most useful level (in my experience), junctions provide for things like: $string ~~ “this”|”that”|”other” This is the same as writing $string eq “this” || $string eq “that” || $string eq “other” They have many other uses but that’s the most common one that I tend to see in practice.
- Joker_vD 2y ago> I’m not sure that I see the connection that you are making here. Can you elaborate? Back when I had to write PowerShell scripts, I constantly found that piping an array to some command would almost always make that command to be invoked once for every item in array, instead of being invoked once and given the whole array as a single input. Sometimes it's the latter that you need, so the workaround is to make a new, single-element array with the original array as its only element, and pipe this into the command.
- ab5tract 2y agoGot it, that makes sense based on the link. In Raku, the equivalent would be: my @a = [1,2],; The connection to junctions is still not very clear to me, however. A junction doesn’t really have any correlation to a single element version of a list. As a super-position of potential values, it doesn’t have many correlaries in other languages. For example, part of the original concept of junctions involved parallel evaluation of junction elements in an expression but that turned out to be less useful than hoped for in practice.
- the_arun 2y agoI got the title confused for "Roku".
- the_arun 2y agoSomeone downvoted this message. If downvoting also comes with reason, it will be helpful.
- b2gills 2y agoI didn't downvote, but this is by far not the first time something like that was stated (Raku being similar to Roku). I know I'm tired of seeing it, I'm sure others are as well.
- mkl 2y agoThe reason is that no one cares about your failure to read correctly. It adds nothing to the conversation. (I didn't downvote.)
- tolmasky 2y agoI implemented something similar to the compositional regular expressions feature described here for JavaScript a while ago (independently, so semantics may not be the same), and it is one of the libraries I find myself most often bringing into other projects years later. It gets you a tiny bit closer to feeling like you have a first-class parser in the language. Here is an example of implementing media type parsing with regexes using it: https://runkit.com/tolmasky/media-type-parsing-with-templated-regular-expressions https://runkit.com/tolmasky/media-type-parsing-with-template... "templated-regular-expression" on npm, GitHub: https://github.com/tolmasky/templated-regular-expression https://github.com/tolmasky/templated-regular-expression To be clear, programming languages should just have actual parsers and you shouldn't use regular expressions for parsers. But if you ARE going to use a regular expression, man is it nice to break it up into smaller pieces.
- b2gills 2y ago"Actual parsers" aren't powerful enough to be used to parse Raku. Raku regular expressions combined with grammars are far more powerful, and if written well, easier to understand than any "actual parser". In order to parse Raku with an "actual parser" it would have to allow you to add and remove things from it as it is parsing. Raku's "parser" does this by subclassing the current grammar adding or removing them in the subclass, and then reverting back to the previous grammar at the end of the current lexical scope. In Raku, a regular expression is another syntax for writing code. It just has a slightly different default syntax and behavior. It can have both parameters and variables. If the regular expression syntax isn't a good fit for what you are trying to do, you can embed regular Raku syntax to do whatever you need to do and return right back to regular expression syntax. It also has a much better syntax for doing advanced things, as it was completely redesigned from first principles. The following is an example of how to match at least one `A` followed by exactly that number of `B`s and exactly that number of `C`s. (Note that bare square brackets [] are for grouping, not for character classes.) my $string = 'AAABBBCCC'; say $string ~~ / ^ # match at least one A # store the result in a named sub-entry $<A> = [ A+ ] {} # update result object # create a lexical var named $repetition :my $repetition = $<A>.chars(); # <- embedded Raku syntax # match B and then C exactly $repetition times $<B> = [ B ** {$repetition} ] $<C> = [ C ** {$repetition} ] $ /; Result: 「AAABBBCCC」 A => 「AAA」 B => 「BBB」 C => 「CCC」 The result is actually a very extensive object that has many ways to interrogate it. What you see above is just a built-in human readable view of it. In most regular expression syntaxes to match equal amounts of `A`s and `B`s you would need to recurse in-between `A` and `B`. That of course wouldn't allow you to also do that for `C`. That also wouldn't be anywhere as easy to follow as the above. The above should run fairly fast because it never has to backtrack, or recurse. When you combine them into a grammar, you will get a full parse-tree. (Actually you can do that without a grammar, it is just easier with one.) To see an actual parser I often recommend people look at JSON::TINY::Grammar https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Grammar.pm https://github.com/moritz/json/blob/master/lib/JSON/Tiny/Gra... Frankly from my perspective much of the design of "actual parsers" are a byproduct of limited RAM on early computers. The reason there is a separate tokenization stage was to reduce the amount of RAM used for the source code so that further stages had enough RAM to do any of the semantic analysis, and eventual compiling of the code. It doesn't really do that much to simplify any of the further stages in my view. The JSON::Tiny module from above creates the native Raku data structure using an actions class, as the grammar is parsing. Meaning it is parsing and compiling as it goes.
- binary132 2y agoI’ve followed this project for years, and while it’s interesting, I think it’s really a shame that Perl 6 seemed to have been so badly waylaid by this sojourn into the looking-glass.
- childintime 2y agoI wonder how (and what) Patrick Michaud is doing?
- deleted 2y ago[deleted]
- Uptrenda 2y agoIt has expressions that seem like they could lead to much shorter code. I suspect it would take some time to get used to though...
- postepowanieadm 2y agoAhh, perl operators! My favorite was goatse operator: =()= that assigned(no pun intended) length of an array if I recall correctly.
- ab5tract 2y agoI dream of a day where one can post a Raku article on HNN and not encounter a comments section full of digressions into discussing Perl. There is some sense to it by means of comparison, but the constant conflation of the two becomes tiresome. But in that spirit, let's compare: The =()= "operator" is really a combination of Perl syntax[^1] that achieves the goal of converting list context to scalar context. This isn't necessary to determine the length of an array (`my $elems = @array` or, in favor of being more explicity, `my $elems = 0+@array`). It is, however, useful in Perl for the counting of more complex list contexts on the RHS. Let's use some examples from it's documentation to compare to Raku. Perl: my $n =()= "abababab" =~ /a/g; # $n == 4 Raku: my $n = +("abababab" ~~ m:g/'a'/); # $n == 4 # Alternatively... my $n = ("abababab" ~~ m:g/'a'/).elems; That's it. `+` / `.elems` are literally all you ever need to know for gathering a count of elements. The quotes around 'a' in the regex are optional but I always use them because I appreciate denoting which characters are literal in regexes (Note also that the regex uses the pair syntax mentioned in OP via `m:g`. Additional flags are provided as pairs, eg `m:g:i`). Another example. Perl: my $count =()= split /:/, "ab:ab:ab"; # $count == 3 Raku: my $count = +"ab:ab:ab".split(':'); # $count == 3 While precedence can at times be a conceptual hindrance, it's also nice to save some parentheses where it is possible and legible to do so. Opinions differ on these points, of course. Note also that `Str.split` can take string literals as well as regexes. [1]: See https://github.com/book/perlsecret/blob/master/lib/perlsecret.pod#goatse https://github.com/book/perlsecret/blob/master/lib/perlsecre...
- samatman 2y ago> digressions into discussing Perl Changing the name to Raku doesn't obliterate Perl 6's history as Larry Wall's successor to Perl 5. I don't know why you would expect people to pretend that they're unrelated. They aren't.
- antononcube 2y agoInteresting set of Raku features to focus on... The most important Raku features are Command Line Interface (CLI) and grammars. CLI support is a _usual_ feature -- see "docopt" implementations (and adoption), for example. But CLI is built-in in Raku and nice to use. As for the grammars -- it is _unusual_ a programming language to have grammars as "first class citizens" and to give the ability to create (compose) grammars using Object-Oriented Programming.
- cutler 2y agoSpeed is still a major issue with Raku. Parsing a log file with a regex is Perl's forte but the latest Raku still takes 6.5 times as long as Python 3.13 excluding startup time.
- donaldihunter 2y agoYou'd need to qualify that with an example. In my experience some things are faster in Raku and some are slower, so declaring that "Raku takes 6.5 times as long as Python 3.13" is pretty meaningless without seeing what it's slower at.
- cutler 2y agoI specified the use case so why "meaningless"? Here's the code: Raku for 'logs1.txt'.IO.lines -> $_ { .say if $_ ~~ /<<\w ** 15>>/; } Python from re import search with open('logs1.txt', 'r') as fh: for line in fh: if search(r'\b\w{15}\b', line): print(line, end='')
- KelvinFineBoy69 2y ago[dead]