Raku Programming Language

(raku.org)

58 points | by tosh 4 days ago ago

25 comments

  • jjice a day ago

    They show it on the landing page, but having first class support for CTF grammars is such an interesting niche for a language. Perl (Rake was originally Perl 6 if I recall) always had solid tooling for dealing with text manipulation, but adding context free grammars in directly is another level. I have to imagine it ends up being seldom used for a lot of applications, but I wonder if you end up with a "see nails when you have a hammer" situation (and not necessarily in a bad way).

    I personally have never used a context free grammar outside of writing a programming language parser.

    • giraffe_lady a day ago

      I first came across something like this in janet, which includes a PEG system in the standard library. It definitely changed how I think about text processing. Very much of the time what I find myself doing with regex is defining a grammar, but I didn't realize that. I wish more languages included the tools for it, it's a core operation of practical programming.

      https://janet-lang.org

    • etyp a day ago

      Yeah, I've never really considered using a grammar like that for string processing like they suggest. And it's the first thing they show. Maybe I'm missing out and I just haven't had the tooling.

  • bloopernova a day ago

    In https://rosettacode.org/wiki/FizzBuzz there's a nice Raku implementation, with ever-more-compact varieties following.

    It seems like a really nice language but which niche should it occupy?

    Edited to add, now that I'm at a computer:

      for 1 .. 100 {
        when $_ %% (3 & 5) { say 'FizzBuzz'; }
        when $_ %% 3       { say 'Fizz'; }
        when $_ %% 5       { say 'Buzz'; }
        default            { .say; }
      }
    
    The multi sub version is interesting. I'm not quite sure what multi subs are, they seem to be performing a pre-function-call validation to choose which sub to use?

      multi sub fizzbuzz(Int $ where * %% 15) { 'FizzBuzz' }
      multi sub fizzbuzz(Int $ where * %%  5) { 'Buzz' }
      multi sub fizzbuzz(Int $ where * %%  3) { 'Fizz' }
      multi sub fizzbuzz(Int $number        ) { $number }
      (1 .. 100)».&fizzbuzz.say;
    • klibertp a day ago

      Non-interactive shell scripting. It's actually the best language in this niche, outclassing Perl and Tcl in terms of features and Python/JS in terms of expressivity.

      General purpose scripting. Orders of magnitude fewer packages and batteries than in Python or Ruby, but it does have a package manager and a bunch of libs for typical tasks. It's also capable of calling Python code almost seamlessly. For small (1 file) scripts, the expressivity of Raku means often half the lines of equivalent Python code, unless you hit a package that Python has and Raku doesn't.

      Everything related to text processing. The grammars parsed by Grammars don't have to be context-free. Parsing just about anything is a joy. Also, light data mangling - if it fits in RAM, you might not need any other tool (like R/Pandas).

      It's also a general-purpose, gradually typed, JIT-compiled, multiparadigm (OO, FP, procedural, array) language, so you can use just about anywhere you want. It's less great for mission-critical things (error handling is peculiar) and shell one-liners (the JIT takes a toll on startup time). It has a REPL, instead.

      • bloopernova a day ago

        Fantastic answer, actually made me enthusiastic for Raku!

        Now I want to go mess with it to see what it can do with some of my standard use cases. (DevOps infrastructure code, various AWS Lambdas, lots of build pipelines)

        • klibertp a day ago

          If you want a quick overview of what you can do with Raku (as opposed to what it is/how it works), I found this book to be nice: https://leanpub.com/raku-oneliners

          Also, make sure to hop on Freenode (or Discord bridge to it), the community is very welcoming :)

          • lizmat 3 hours ago

            Freenode is actually dead: the Raku IRC channels are on libera.chat!

          • bloopernova a day ago

            Thanks for the recommendation, I immediately bought that book. I'm a huge fan of people publishing on leanpub or similar :)

    • zokier a day ago

      To me Raku represents small-scale data mangling/processing and glue language for small scripting. Hacker oriented, personal and individualistic, not something you'd push in corporate. In many ways similar role what Python had decade ago, and Perl had two decades ago.

    • klibertp a day ago

      multi subs allow you to declare multiple overloaded versions of a function (subroutine, sub). Dispatch between sub bodies happens based on either the type(s) of arguments or based on a truth value of a "guard" - a boolean expression or boolean function placed after `where` in sub declaration head.

      `%%` is a `modulo == 0` operator, which is surprisingly commonly needed.

      `fizzbuzz(Int $ where * %% 15)` can also be written `fizzbuzz(Int $x where $x %% 15)` - the difference is that you don't have to name the argument just for the check. When `fizzbuzz` is called, all known definitions' guards are checked to see which will be entered.

      The `*` in `* %% 15` is "whatever star", you can think of it as a short syntax for creating lambdas. There are multiple ways of constructing anonymous functions and blocks, you can get the same effect with `{ $_ %% 15 }`, `-> $a { $a %% 15 }`.

      `»` is a "hyper operator"; the next method-call will be performed on all elements of a collection on the left. Groovy uses `*.` for this I think. You could use a `.map` method instead, `(1..100).map(&fizzbuzz)` or `.map({ .&fizzbuzz })` (`{ .meth }` is equivalent to `-> $x { $x.meth }`)

      `.&` is a "call as method" operator: `fizzbuzz` is a function, so you can't call `1.fizzbuzz`, however, you can call `1.&fizzbuzz`.

      Also, in the first solution, `(3 & 5)` is a Junction. This is an important concept that introduces a degree of nondeterminism to the language - well worth reading about! :)

    • agumonkey a day ago

      They're nearing apl density :)

      • lizmat 3 hours ago

        You can program with APL density of you want. However, you don't have to!

        • agumonkey 10 minutes ago

          it is true, but i wasn't complaining ;)

  • liveoneggs a day ago

    Raku is like the everything language. Reading its docs is a wild ride.

    https://docs.raku.org/language/operators

    • klibertp a day ago

      Not my experience with it: the language is indeed rich, but not overly so. The number of concepts you need to learn is comparable to (modern) Python or less. Raku is also very consistent, choosing to apply already existing concepts rather than invent a new one (when designers are forced to choose) most of the time. While you still have many ways of accomplishing each task, no language elements are dedicated to a single task.

      As for operators - most of them are simply aliases for method names, you don't have to use them. However, some operators are representations of concepts that are not available through other means (e.g., `...`[1], circumfix `[]`, infix `Z`) The page you linked to makes no distinction and dumps everything that is syntactically an operator on a single page, resulting in a very long list. In practice, you don't need to remember more than a small fraction of them.

      [1] https://docs.raku.org/language/operators#infix_%2E%2E%2E

  • Pet_Ant a day ago

    For those who didn't know and read comments first:

    Raku was originally known as Perl 6.

    https://en.wikipedia.org/wiki/Raku_(programming_language)#Hi...

    The main implementation is called Rakudo: https://en.wikipedia.org/wiki/Rakudo

    "Raku" is Japanese for "camel" which is named after the O'Reilly book cover.

  • xbar a day ago

    I've doing some text processing in Raku for the past two weeks. It has been a pleasant and efficient experience.

  • a day ago
    [deleted]
  • mempko a day ago

    I use Raku for production. It's great for orchestration, or writing a quick server. Text manipulation and processing is amazing. I'm shocked it hasn't gotten more adoption in the LLM space. You would think someone would make a really great library to create AI Agents using Raku.

    • klibertp a day ago

      The community is tiny. The fact that it was called "Perl6" for 20 years (Raku is from after 2019 I think) absolutely doesn't help in anything, the least in adoption. The historical churn in terms of VM (experimental in Haskell, dead Parrot, JVM, current MoarVM), the lack of planned features (macros!) for long years, and the slow death of Perl over a similar time frame - all that (and more) means not many people use it, even if they happen to know about it.

      On the other hand, there's a similarly tiny - or smaller - community around Glamorous Toolkit (a Smalltalk distribution) that managed to produce one of the most hackable and rich LLM clients out there: https://github.com/feenkcom/gt4llm https://gtoolkit.com/ Here, though, LLMs are so close a match for the community interests that it just had to happen...

  • systems a day ago

    is larry wall at all engaged with raku?

    • lizmat 2 hours ago

      Not actively, not anymore.

      Very occasionally (maybe once a year) he will post a comment on an issue. But that's about it.

      In other words: (hopefully happily) enjoying his retirement.

    • klibertp a day ago

      Not sure; he was involved in the design in the 2000s, but I haven't seen him while I was active in the community. Some other prominent Perl community members are there (the kinder ones, I'm told).

  • a day ago
    [deleted]