Re: sub default question

[email protected] (Peter Pentchev) Wed, 19 Nov 2025 12:33:20 +0200
Newsgroups perl.perl6.users
Message-ID <[email protected]>
--sEaf4ecvdLHjKNK6
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Nov 19, 2025 at 02:19:43AM -0800, ToddAndMargo via perl6-users wrot=
e:
> On 11/19/25 1:38 AM, Peter Pentchev wrote:
> > On Wed, Nov 19, 2025 at 01:13:23AM -0800, ToddAndMargo via perl6-users =
wrote:
> > > Hi All,
> > >=20
> > > https://github.com/rakudo/rakudo/blob/main/src/core.c/Proc.rakumod
> > > 232: multi sub run(*@args where .so, :$in =3D '-', :$out =3D '-', :$e=
rr =3D '-',
> > >=20
> > > Here is my confusion.  The above sets
> > >     :$in =3D '-', :$out =3D '-', :$err =3D '-',
> > > to "-" as the default.
> > >=20
> > > But if you leave
> > >     :$out  and :$err
> > > off the run line, STDOUT and STDERR do not
> > > get captured and are sent to the console.
> >=20
> > ...that's exactly what "-" means.
> >=20
> > G'luck,
> > Peter
> >=20
>=20
>=20
> If :out and "err are left off the run line, they are
> not used and the STDOUT and STDERR go to the console.

>=20
> If :out and :err are included, the STDOUT and STDERR
> are captured and your Proc variable are populated
> with their file handles.
>=20
> So why leaving them out, does not the default shown
> on line 232 apply?

If :out and :err are left off the run line, then Raku invokes
the run function just as if you specified the default values,
which in this case are "-" for both. The part you refer to
in your other message about `:out` being equivalent to
`:out(True)` does not apply in this case, since you do NOT
specify `:out` in the run invocation, you leave `:out` out
completely, so Raku uses the default value, which is "-".

Some more clarification may be in order here. As a Unix convention,
tools such as `cat`, `sort`, `wc` that process text files may
accept the special value "-" (a single minus sign) as an argument
that means "now read from the standard input stream and process that".
This allows you to do stuff like:

  #!/bin/sh

  cat /usr/share/wrap/prologue.txt - /usr/share/wrap/epilogue.txt

=2E..and when you invoke that script, it will "surround" whatever you pass
on its standard input stream with the contents of those two files.
It also allows you to do funny stuff like:

  echo 'roam:x:1000:1000:/home/roam:My account' | sort -k 3,3n -k 4,4n /etc=
/passwd -

=2E..to produce something like a passwd file that contains an additional li=
ne.

Similarly, "-" used where the path to an output file should be specified
also traditionally means "just use the standard output stream, do not
write to a file":

  tar cf - myprog-0.1.0/ | gzip -n9 > myprog-0.1.0.tar.gz

=2E..will make `tar` write the archive contents to its standard output stre=
am,
which is then piped to `gzip`.

This is why the special value "-" (a string that consists of a single
"ASCII minus" character) may be passed to run for the :in, :out, and :err
parameters. If :in is "-", the new process will read from your process's st=
andard
input stream. If :out is "-", the new process will write stuff to your proc=
ess's
standard output stream. If :err is "-", the new process will report errors =
to
your process's standard error stream. If none of these have been redirected,
then yes, everything will go "to the console", as you said.

And "-" is also the default for those parameters, so if you do:

  run("date")

=2E..then the `date` program will output stuff on the console, or rather, on
your own process's standard output stream - that's because Raku sees that
you did not specify a value for :out, so it uses the default value "-", and
run treats "-" as "go to the standard output stream".

--=20
Peter Pentchev  [email protected] [email protected] [email protected]
PGP key:        https://www.ringlet.net/roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13

--sEaf4ecvdLHjKNK6
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEELuenpRf8EkzxFcNUZR7vsCUn3xMFAmkdnOsACgkQZR7vsCUn
3xMMchAAoSPIfIeBM3+2c0UxQfzzxMNsa3qTM36m/5HLIHelHZgnZrwCSirJ+Vq/
WAqXRf+kcxRnUaqof+aXBVVEC9lVTG+2/q1NhWjtvjCIPQ9gRrh/emAVAtfMIsXW
Y87Cs51ztiqStku1QnD9Q+qzwhaQsULS9O+i3Ci0tL3EQ+tF9lISY739K9xAwgqr
YLmC+xsFy9VjlM7CNSEdsQlu/o3GnIFN9y8aKb3XhTYjfwxHLsEPwiBq0mpLibsx
o1nMhUGGjUC8oaJlg+2LvUTHDdVm9rDikA6ZVlARyNV3mcXMTbHD9G8KFD3IxBso
50DhCinQ3ScLD6Ek8Qe9vIhjmOwHYHMrtRbmKVEo5rZaK14OiJhceZszt2Dcpqtn
/WZVg97SBosa/W633/F2LHYL71PhTiTN3Q4i8JmJislGwcqurpBJtnAwoBF1oDMD
CoH2o3USU4YgzpmEusbuZi4KM+7metwuhgatt5CxVd4upiJSs0rjPQiLy5+t3FtI
Bsdxoe2srRr9+9xcokPmPuGy0x4wEWfyEZPWg1cUVuyZvZ+bcxYhVo3R6W0qxD0s
oxniyKkIa6ESDxohYhoqeO7mN3m8b5aWhI+DCZKyPC7wQzYvRHVUHNqWDqkL8K9t
U3sJHow6NeqfHfKZ1ATyUo8kmTRPJjR5cTOmjWIq5c91BlmcTAg=
=0sIh
-----END PGP SIGNATURE-----

--sEaf4ecvdLHjKNK6--