Hacker News new | ask | show | jobs
by Joker_vD 588 days ago
PowerShell 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

1 comments

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

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 evaluation of junction elements in an expression but that turned out to be less useful than hoped for in practice.

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 a pretty clear parallel to me. And since the Powershell's behaviour is quite often undesirable, I agreed with the original commenter that perhaps the junctions could also be somewhat annoying to use instead of just working normal lists: after all, "s in ('this', 'that', 'other')" is about just as clear as "$string ~~ “this”|”that”|”other”" but doesn't require support for magical self-destructuring containers in the language.

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.