Re: What is the pipe symbol doing to my array?

2025-11-03 Thread ToddAndMargo via perl6-users

On 11/3/25 5:50 PM, Brian Duggan wrote:

The pipe symbol creates a Slip

   [0] > say (|).WHAT
   (Slip)

It is precisely equivalent to

   .Slip

see

https://docs.raku.org/type/Slip

hope this helps

Brian




Hi Brian,

I am writing that down.  Thank you!

-T


Re: What is the pipe symbol doing to my array?

2025-11-03 Thread Brian Duggan
The pipe symbol creates a Slip

  [0] > say (|).WHAT
  (Slip)

It is precisely equivalent to

  .Slip

see

   https://docs.raku.org/type/Slip

hope this helps

Brian



Re: What is the pipe symbol doing to my array?

2025-11-03 Thread ToddAndMargo via perl6-users

On 11/3/25 10:07 AM, ToddAndMargo via perl6-users wrote:

Hi Sean,

Thank you!

My big worry with flattening is when a parameter passed to run has a 
space in it.


     run "a", "b c", "d", ...

that flattening will send it as

     run "a", "b", "c", "d", ...

-T


Hi Sean,

Yary wrote me off line that "run" also flattens what
it get,  which removes my concerns with how parameters
with spaces in them are dealt with.  I have uses
spaces before and it works.

-T


Re: What is the pipe symbol doing to my array?

2025-11-03 Thread ToddAndMargo via perl6-users

On 11/3/25 6:02 AM, Sean McAfee wrote:
On Mon, Nov 3, 2025 at 1:31 PM ToddAndMargo via perl6-users [email protected] > wrote:


I guess I am asking what the flattening does.


It passes the elements of an array as separate parameters to a function, 
rather than passing the array itself as a single parameter.


my @nums = 3, 4, 5;
sub show($x, $y, $z) { say "Got $x, $y, and $z" }
show(1, 2, @nums);  # Got 1, 2, and 3 4 5
show(|@nums); # Got 3, 4, and 5

But a function that takes a slurpy array parameter flattens its 
arguments automatically, making it pointless to explicitly flatten with 
a pipe:


sub show2(*@args) { say "Got @args.join(', ')" }
show2(1, 2, @nums); # Got 1, 2, 3, 4, 5
show2(@nums); # Got 3, 4, 5
show2(|@nums); # Got 3, 4, 5

This is why in my other recent response to you, I was able to say this:

my $p = run , dir(test => *.ends-with('.raku'));

And I didn't need to say this, even though it also works:

my $p = run |, |dir(test => *.ends-with('.raku'));

It's because run takes a slurpy list of arguments.

Why is this proper
      my $proc = run(@x, :err, :out)

and this is not
      my $proc = run(@x, :err, :out)


Well, I mean...those are identical.  But assuming you meant to write |@x 
in the second one, it's not "proper" for the same reason this is improper:


my $y = (+$x) ** (+2) - (+5) * (+$x) + (+1);

...compared to:

my $y = $x ** 2 - 5 * $x + 1;

While functionally equivalent, the first is riddled with pointless 
complications that will leave a human reader scratching their head.





Hi Sean,

Thank you!

My big worry with flattening is when a parameter passed to run has a 
space in it.


run "a", "b c", "d", ...

that flattening will send it as

run "a", "b", "c", "d", ...

-T


Re: What is the pipe symbol doing to my array?

2025-11-03 Thread Sean McAfee
On Mon, Nov 3, 2025 at 1:31 PM ToddAndMargo via perl6-users <
[email protected]> wrote:

> I guess I am asking what the flattening does.
>

It passes the elements of an array as separate parameters to a function,
rather than passing the array itself as a single parameter.

my @nums = 3, 4, 5;
sub show($x, $y, $z) { say "Got $x, $y, and $z" }
show(1, 2, @nums);  # Got 1, 2, and 3 4 5
show(|@nums); # Got 3, 4, and 5

But a function that takes a slurpy array parameter flattens its arguments
automatically, making it pointless to explicitly flatten with a pipe:

sub show2(*@args) { say "Got @args.join(', ')" }
show2(1, 2, @nums); # Got 1, 2, 3, 4, 5
show2(@nums); # Got 3, 4, 5
show2(|@nums); # Got 3, 4, 5

This is why in my other recent response to you, I was able to say this:

my $p = run , dir(test => *.ends-with('.raku'));

And I didn't need to say this, even though it also works:

my $p = run |, |dir(test => *.ends-with('.raku'));

It's because run takes a slurpy list of arguments.

Why is this proper
>  my $proc = run(@x, :err, :out)
>
> and this is not
>  my $proc = run(@x, :err, :out)
>

Well, I mean...those are identical.  But assuming you meant to write |@x in
the second one, it's not "proper" for the same reason this is improper:

my $y = (+$x) ** (+2) - (+5) * (+$x) + (+1);

...compared to:

my $y = $x ** 2 - 5 * $x + 1;

While functionally equivalent, the first is riddled with pointless
complications that will leave a human reader scratching their head.


Re: What is the pipe symbol doing to my array?

2025-11-02 Thread ToddAndMargo via perl6-users

On 11/2/25 8:10 PM, Sean McAfee wrote:
On Mon, Nov 3, 2025 at 5:25 AM ToddAndMargo via perl6-users [email protected] > wrote:


[0] > my @x="a","b","c","d";
[a b c d]

[1] > say @x
[a b c d]


Here you're passing a single argument to say, the array @x, which is 
stringified by calling the gist method on it.  It's the same as if if 
you had said:


say @x.gist;

[1] > say |@x
abcd


Here you're passing four arguments to say, the elements of @x.  It's the 
same as if you had said:


say 'a', 'b', 'c', 'd';

I ask because I want to know its effect is on
      my $proc = run(|@x, :err, :out)


run takes a slurpy list of arguments, as indicated by the *@args 
parameter in its documentation , so 
it doesn't matter if you explicitly flatten @x with a pipe.  It'll work 
the same either way.



I guess I am asking what the flattening does.

Why is this proper
my $proc = run(@x, :err, :out)

and this is not
my $proc = run(@x, :err, :out)




Re: What is the pipe symbol doing to my array?

2025-11-02 Thread Sean McAfee
On Mon, Nov 3, 2025 at 5:25 AM ToddAndMargo via perl6-users <
[email protected]> wrote:

> [0] > my @x="a","b","c","d";
> [a b c d]
>
> [1] > say @x
> [a b c d]
>

Here you're passing a single argument to say, the array @x, which is
stringified by calling the gist method on it.  It's the same as if if you
had said:

say @x.gist;


> [1] > say |@x
> abcd
>

Here you're passing four arguments to say, the elements of @x.  It's the
same as if you had said:

say 'a', 'b', 'c', 'd';


> I ask because I want to know its effect is on
>  my $proc = run(|@x, :err, :out)
>

run takes a slurpy list of arguments, as indicated by the *@args parameter
in its documentation , so it doesn't
matter if you explicitly flatten @x with a pipe.  It'll work the same
either way.


Re: What is the pipe symbol doing to my array?

2025-11-02 Thread ToddAndMargo via perl6-users

On 11/2/25 1:25 PM, ToddAndMargo via perl6-users wrote:

Hi All,

I see what is happening, but exactly what I am not sure:

[0] > my @x="a","b","c","d";
[a b c d]

[1] > say @x
[a b c d]

[1] > say |@x
abcd


I ask because I want to know its effect is on
     my $proc = run(|@x, :err, :out)


Many thanks,
-T



Search.brave.com gave me this back.  Is it correct?
(I fear "AI Slop").

https://search.brave.com/search?q=raku+what+dows+a+pipe+sign+in+front+of+an+array+variable+do%3F&summary=1&conversation=239b87cf62ce8a58a8bd45

If you are referring to the | symbol in the context of array
slicing or flattening, it can be used in list context to
flatten an array into a list of its elements, but this is
not done by placing | directly in front of the variable name.
Instead, it is used in expressions like |@array to flatten
the array into a list.