Re: the new raku.org is really beautiful (and tought about spurt)

[email protected] (Marc Chantreux) Sun, 7 Sep 2025 20:31:42 +0200
Newsgroups perl.perl6.users
Message-ID <aL3Pjteemocufrie@prometheus>
Hello Liz,

On Sun, Sep 07, 2025 at 11:02:10AM +0200, Elizabeth Mattijsen wrote:
> > my $content = "example.txt".IO.slurp;       # Read file
> > $content ~~ s/Hello/Hi/;                    # Modify content
> > spurt $filename, $content;                  # Write back to file

> FWIW, I don't know why that example isn't doing
> $filename.IO.spurt($content)

this is a really interesting question because I have to admit I prefer
the one of the exemple but I don't know how biased is my explaination.

I would say I found it a little less noisy and harder to edit but the
difference is so thin to me I don't mind.

but I would like to write

	spurt $content, $filename

with multimethod

	spurt $filename # which would be spurt $_, $filename

> $filename.IO.spurt( "example.txt".IO.slurp.subst("Hello","Hi") )

> > but it we were able to write this:
> > 
> > with "example.txt".IO.slurp {
> > s/Hello/Hi/;
> > .&spurt: $filename;
> > }
> >
> I really dislike indirect object syntax used this way.

I love it because it's a way to declare a method without monkey-patching

> What does this bring?  Why not just $filename.spurt($_) ?

Again: I feel it's less noisy

	.&spurt: $filename;
	$_.spurt($filename);

I can't explain the core of it and as I say: I probably use both without
noticing.

> > with "example.txt".IO.slurp {
> > s/Hello/Hi/;
> > .spurt: $filename;
> > }
> 
> Now *that* I find to be an interesting idea.  The oneliner would then become:
> 
>   "example.txt".IO.slurp.subst("Hello","Hi").spurt($filename)
> 
> which has a nice left-to-right feel.

Which would be indeed my syntax of choice.

amicalement,

-- 
Marc Chantreux
signature.asc (application/pgp-signature, 228 B)
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQQrhynLytp14smlCwy+er2aYc+1WAUCaL3PfQAKCRC+er2aYc+1
WE6AAQDrtvHkG3KwWO3SG9Jd4RRwLXGw/CMfl7vUdQzwiE6dIgEAxDb8OkGCLRxy
sMaU0FjVe6aWH0Qhmo5Flnt+2hIdMQU=
=3/4Z
-----END PGP SIGNATURE-----