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

2025-09-18 Thread Elizabeth Mattijsen
> On 8 Sep 2025, at 04:26, William Michels  wrote:
> PS  If `Str` had a `spurt` method, wouldn't you be in constant fear of a 
> sensitive string literal (e.g. a password) being accidentally written to 
> disk? 

How would that be different from the fear of $io.spurt($sensitive-data) ??

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

2025-09-16 Thread Marc Chantreux
On Sat, Sep 13, 2025 at 09:18:20AM -0400, Brian Duggan wrote:
> The feed operator already sort of fits well here
> "example.txt".IO.slurp.subst('Hello','Hi') ==> spurt($filename)

I have a mixed feeling there. YA operator.

but hey .. it works...

-- 
Marc Chantreux


signature.asc
Description: PGP signature


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

2025-09-13 Thread Brian Duggan
> > 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.

The feed operator already sort of fits well here

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

Brian


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

2025-09-08 Thread Marc Chantreux
hi William,

On Sun, Sep 07, 2025 at 07:26:21PM -0700, William Michels via perl6-users wrote:
> `~$ raku -e 'my $fh = "ImportantFile_bak".IO;  #create filehandle \
>"ImportantFile".IO.slurp.subst(:global, "Hello ", "Hi ") andthen
> spurt($fh,  $_,  :createonly);' `

this is way behond the rewrite of the example. and my sadness about the
way spurt is usable but still an interesting feedback because
TIMTODY and but there is no way to really describe why we choose one
against the other.

* I'm also fan of what I call "method as pipe" syntax and I would like
  to write them as multiline but AFAIR I had some issues with that.

  to illustrate that: my shell scripts looks like

getent passwd |
cut -d: -f7   |
sed '
/zsh$/ !d
s//&-static/
' |
sort  |
uniq -c   > busybox_fs/etc/passwd


   and as I hate "misplaced parentheses" (I don't fear parentheses
   when they're in the right place to tell the right thing like in scheme)
   and that's one of the reasons I felt immediately in love with perl
   30 years ago.

so my raku of dream would allow me something like:

so my dream would be to write liz's example close to this:

"example.txt".IO.slurp
.&{ g:s/Hello/Hi/ }
.spurt: $filename

regards
Marc


signature.asc
Description: PGP signature


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

2025-09-08 Thread Marc Chantreux
On Mon, Sep 08, 2025 at 11:36:32AM +0200, Elizabeth Mattijsen wrote:
> The reason this doesn't work, is because  s:g/Hello/Hi/  requires a
> writeable $_, and the invocant of .&{  } is not writeable in this
> example.

AFAIR, there was also problems with the way I split the lines because
it changed priorities or was just not parsable.

> If you really like s/// syntax that much


not only I prefer the s!!! (with whatever separator syntax) but il like
the fact you can respect the left-to-right with .&{ } is super cool.

> why not use .subst(/Hello/, "Hi", :g)   instead?

my brain consider .subst(, "Hi", :g) as noise.  s/Hello/Hi/ is not
only faster to write/edit it's also less painful tu read but
I really need to refresh my skills so I can make better feedbacks.

-- 
Marc Chantreux


signature.asc
Description: PGP signature


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

2025-09-08 Thread Elizabeth Mattijsen
> On 8 Sep 2025, at 11:29, Marc Chantreux  wrote:
> so my dream would be to write liz's example close to this:
> 
> "example.txt".IO.slurp
> .&{ g:s/Hello/Hi/ }
> .spurt: $filename

The reason this doesn't work, is because  s:g/Hello/Hi/  requires a writeable 
$_, and the invocant of .&{  } is not writeable in this example.

If you really like s/// syntax that much, why not use   .subst(/Hello/, "Hi", 
:g)   instead?

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

2025-09-08 Thread Elizabeth Mattijsen
> On 8 Sep 2025, at 04:26, William Michels  wrote:
> PS  If `Str` had a `spurt` method, wouldn't you be in constant fear of a 
> sensitive string literal (e.g. a password) being accidentally written to disk?

How would that be different from the fear of $io.spurt($sensitive-data) ??

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

2025-09-07 Thread William Michels via perl6-users
Greetings, 

I much prefer this syntax:

`~$ raku -e 'my $fh = "ImportantFile_bak".IO;  #create filehandle \
   "ImportantFile".IO.slurp.subst(:global, "Hello ", "Hi ") andthen 
spurt($fh,  $_,  :createonly);' `

It has a nice left-to-right feel and keeps you from clobbering an 
`ImportantFile`.

( Once you're sure of your code/filehandles, clobber-away by deleting 
`:createonly` ).

HTH, 

Bill.

PS  If `Str` had a `spurt` method, wouldn't you be in constant fear of a 
sensitive string literal (e.g. a password) being accidentally written to disk? 


> On Sep 7, 2025, at 13:24, Elizabeth Mattijsen  wrote:
> 
>> On 7 Sep 2025, at 20:31, Marc Chantreux  wrote:
 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.
> 
> Now a PR: 
> https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_rakudo_rakudo_pull_5949&d=DwIFAg&c=009klHSCxuh5AI1vNQzSO0KGjl4nbi2Q0M1QLJX9BeE&r=H_4IX2PNs5J8Am4L9k8XPDKLi8_PeuhJoKcQtnXHZ4c&m=CdwLh6ejqGtN5pVo5BxHnyw_NNX6Q3THBGda101VuhkyU9wfE4bILSaNb-FFWw5p&s=lZpE981EjWUqSAUkAnzmw13LGlTKBgHNSgXAtYL99zY&e=



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

2025-09-07 Thread Elizabeth Mattijsen
> On 7 Sep 2025, at 20:31, Marc Chantreux  wrote:
>>> 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.

Now a PR: https://github.com/rakudo/rakudo/pull/5949

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

2025-09-07 Thread Marc Chantreux
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
Description: PGP signature


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

2025-09-07 Thread Elizabeth Mattijsen
> On 7 Sep 2025, at 10:51, Marc Chantreux  wrote:
> I just gave a look on the new raku.org website and would like to
> congrat as it's really beautiful.

It is  :-)


> Aside, I saw the example which reminds me an old dicsussion about
> "spurt parameters should be flipped" and there is a perfect exemple
> in the homepage:
> 
> 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)

as the same .IO coercer is used on slurping the file.

Or even as a one-liner:

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


> which could be writen
> 
> with "example.txt".IO.slurp {
> s/Hello/Hi/;
> spurt $filename, $_
> }
> 
> 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.  What does this bring?  
Why not just $filename.spurt($_) ?

> or if Str had a spurt method:
> 
> 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.