Live data from Hacker News

Unusual Raku Features

buttondown.com

141–150 of 166 posts

Re: Unusual Raku Features

#141

Earlier quoted context omitted.

If you suggest a language here where nothing weird can be done, I bet someone will reply with something weird done in that language.

This is true. I’ve written overly-clever, indecipherably dense code in many different languages. But some languages seem to practically encourage that kind of thing. Compare a random sampling of code from APL, Scala, Haskell, Perl, Clojure, C, and Go. You’ll probably find that average inscrutability varies widely between various language pairs.

Inscrutability to whom? I'm confident someone with 10 years of production Haskell experience will do a better job of reading production Haskell code than a comparable situation with C.

But then again, maybe that was what you were saying.

Re: Unusual Raku Features

#142

Earlier quoted context omitted.

That's a fair reaction to the post if you haven't looked at any normal Raku code. If you look at any of the introductory Raku books, it seems a LOT like Python with a C-like syntax. By that I mean the syntax is more curly-brace oriented, but the ease of use and built-in data structures and OO features are all very high level stuff. I think if you know any other high level scripting language that you would find Raku p…

Sure, but the fact that weird stuff is possible means that someone, at some point, will try to use it in your codebase. This might be prevented if you have a strong code review culture, but if the lead dev in the project wants to use something unusual, chances are no one will stop them. And once you start...

You say like you never looked at any Perl Golf solution.

Re: Unusual Raku Features

#143
post #68

I 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 w…

"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 th…

Why are they called regular expressions if they can parse non-regular languages?

Re: Unusual Raku Features

#144

I don't understand why we want to use some language feature like Junctions, instead of using lists explicitly?

I don't understand why we want to use some language feature like loops, instead of using conditional gotos explicitly.

Sure, we can do the same thing with the goto... but why would we want to use the more difficult/annoying alternative when the convenient one exists?

Re: Unusual Raku Features

#145
post #80

Earlier quoted context omitted.

That article was a RIDE.

Yea, 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 >.

Ha, Conway, once again. His talks during early perl6 days were brilliant.. thanks for sharing

Re: Unusual Raku Features

#146
post #143
post #68

Earlier quoted context omitted.

"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 th…

Why are they called regular expressions if they can parse non-regular languages?

The word 'regular' comes from the mathematical roots of automata and finite state machines.

Re: Unusual Raku Features

#147
post #106

Speed 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.

You'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.

Re: Unusual Raku Features

#148

Earlier quoted context omitted.

Got 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 evalu…

An array in Powershell, when piped to a command, automatically get this command invoked for each of the array's element and the results are combined into a new output array, which can be piped further. A junction in Raku, when given as an argument to a function, automatically applies this function to each of the junction's element and the results are combined into a new junction as a result. I don't know, seems like…

Since I rarely use junctions myself -- and never in the manner of applying non-boolean operations across their values -- the connection to automatic function application wasn't clear to me from your initial comment.

I can see the parallel now, so thank you for clarifying.

EDIT: On further reflection, another reason that the connection escaped me is that even after applying functions across a junction’s values, the junction is never useful (without significant and unnecessary effort) for accessing any individual values that it contains.

Anyway, thanks for sharing your thoughts and bearing with me.

Re: Unusual Raku Features

#149
post #80

Earlier quoted context omitted.

That article was a RIDE.

Yea, 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 >.

Damian is an excellent writer and communicator for sure. But I don't know if it answers the question of what you would use these features in Raku for. If one wanted to compute e to higher precision, I feel like one would use a DSL. But we also don't need to compute e presently.

Re: Unusual Raku Features

#150
post #25

I 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.

Very 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?

Here 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;
            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.)
Post reply on HN