Hacker News new | ask | show | jobs
by awwaiid 1981 days ago
There are a TON of experiments and language mash-ups in Raku. Let's see here.... Types can include guard clauses that are evaluated at runtime. Typed multi-dispatch on top of that. In addition to normal "sets" it has "junctions", like some sort of funky quantum superposition or something. In theory those can be made parallel at some point. Stuff like that.

One that is particularly funky is the "whatever-star". This is a "" char that can be used in a few places to mean more or less... whatever. For example:

    <4 5 6 7>.map(-> $x { $x + 7 }) # result: (11 12 13 14)
That stabby inline lambda there can be sugared down in a lot of ways, including with the whatever-star:

    <4 5 6 7>.map(* + 7) # result: (11 12 13 14)
... I've not seen anything quite like that in other languages, not sure if it is a new invention or if only nobody else is crazy enough to try it. And yes, you can use multiplication next to it to make it look crazier:

    <4 5 6 7>.map(* * 7) # result: (28 35 42 49)
(also yes, (
* *) will take two inputs and multiply them.)

I will note though that dwelling on these crazy/fun edge cases is amusing, but programs can look quite a bit more like a basic ruby app (with sigils) if you so desire.

3 comments

Scala has something similar with "placeholder syntax for anonymous functions", where

    _.methodname()
or

    _ + 1
is equivalent to

    x => x.methodname()
or

    x => x + 1
https://www.scala-lang.org/files/archive/spec/2.13/06-expres...
For single placeholders I prefer the look of either the `_` syntax or the alternative some PLs have of `.`.

But otoh, Raku nicely stretches the approach to both zero and multiple placeholders:

* The zero placeholder `.methodname` in Raku is the same as Scala's `_.methodname`

* Any number of placeholders are allowed, so one can write eg `* + *` as an anonymous binary add function.

Note that HN's formatting ate several of the * in the comment above, which makes it much harder to follow.

> (also yes, (* * *) will take two inputs and multiply them.)

That's true, but Raku also supports non-Unicode math operators, so the more idiomatic way to write that would be

  (* × *)
which, in isolation, still isn't that clear. But it usually is in context. And, if it isn't – well, that's why there's more than one way to do it!
XPath has such a thing:

     (4, 5, 6, 7) ! (. + 7)