Re: steps of a path

2022-09-07 Thread William Michels via perl6-users
Apologies: the first code example in my previous email won't check for a given directory, and will print out bogus paths: ~$ echo "/Users/none/bogus_dir/" | raku -e 'for lines.IO -> $a is copy {$a.Str.say; repeat {$a.=parent andthen $a.Str.say;} until $a eq $*SPEC.rootdir};' /Users/none/bogus_dir/

Re: steps of a path

2022-09-07 Thread The Sidhekin
On Wed, Sep 7, 2022 at 6:27 PM Parrot Raiser <1parr...@gmail.com> wrote: > > > > That said, right now gmail is claiming whipupitude is misspelled... > > > An alternative is "whipitupitude" (the difference being the first "it". > > Given the examples I've seen over the years, there's a need for an

Re: steps of a path

2022-09-07 Thread Parrot Raiser
> > That said, right now gmail is claiming whipupitude is misspelled... > An alternative is "whipitupitude" (the difference being the first "it". Given the examples I've seen over the years, there's a need for an opposite to "idiomatic", for programming that arrives at a solution by a Rube Goldber

Re: steps of a path

2022-09-07 Thread William Michels via perl6-users
Hi Marc, Does this do what you want? I've omitted the call to `run` and used mostly IO::Path calls instead: ~$ echo "/Users/admin/logs" | raku -e 'for lines.IO -> $a is copy {$a.Str.say; repeat {$a.=parent andthen $a.Str.say;} until $a eq $*SPEC.rootdir;};' #returns: /Users/admin/logs /Users/ad

Re: steps of a path

2022-09-07 Thread Ralph Mellor
On Wed, Sep 7, 2022 at 1:20 AM Marc Chantreux wrote: > > Actually what I really like the most from all your answers was the fact > that I learned a lot not only about the langage but also some idoms. That sounds cool. :) I know what *I* think of when I write "idiom" in the context of programming

Re: steps of a path

2022-09-06 Thread Marc Chantreux
Hi Ralph, > Given that the broader picture is file/path related operations, it makes > sense to me you're mostly exploring use of `.parent` and `map`s etc. Actually what I really like the most from all your answers was the fact that I learned a lot not only about the langage but also some idoms.

Re: steps of a path

2022-09-06 Thread Ralph Mellor
On Mon, Sep 5, 2022 at 8:07 AM Marc Chantreux wrote: > > I just played again with your solution and got the beauty of it. > > Actually: this is by far the simplest solution. Thanks. Thanks for the follow up. So I'm not going mad! :) Given that the broader picture is file/path related operations,

Re: steps of a path

2022-09-05 Thread Marc Chantreux
I love this one. I used uniq and run so the whole script can be run from raku (except the xargs ls avoid the ARG_MAX error) <<. raku -e 'run < ls -lUd >, unique map {(.IO, *.parent …^ "/")>>.Str.Slip}, lines' /var/log/messages /var/log/auth.log regards -- Marc Chantreux Pôle de Calcul et Servi

Re: steps of a path

2022-09-05 Thread Bruce Gray
> On Sep 5, 2022, at 1:54 AM, Marc Chantreux wrote: --snip of Bill's pointer to Mathew's email-- > I tried this line but got an immutability problem. I tried > multiple work around with no success for the moment. > <<. raku -e 'lines.IO.map: {repeat {.put} while not .=parent ~~ "/" }' > /var/log/m

Re: steps of a path

2022-09-05 Thread Fernando Santagata
Hello, you can get around the immutability problem: raku -e '"/var/log/messages".IO.map: -> $_ is copy {repeat {.put} while ! ($_ .= parent ~~ "/") }' On Mon, Sep 5, 2022 at 8:55 AM Marc Chantreux wrote: > hello William, > > On Sat, Sep 03, 2022 at 04:27:04PM -0700, William Michels wrote: > >

Re: steps of a path

2022-09-05 Thread Marc Chantreux
Hi Ralph, > The `.Str.say` can be just `.put`. oh! got it. thanks :) > If not, can you see why I'm surprised -- why `m:g{ "/" <-[/]>+ }` > seems simpler to me than `m:ex{^ [:r "/" <-[/]>+]+? }`? I just played again with your solution and got the beauty of it. why made me realize I should take t

Re: steps of a path

2022-09-04 Thread Marc Chantreux
hello William, On Sat, Sep 03, 2022 at 04:27:04PM -0700, William Michels wrote: > Hi Marc, There's also this conversation from March 2021 on the mailing list: > https://www.nntp.perl.org/group/perl.perl6.users/2021/03/msg9857.html > [Matthew's answer looks very interesting]. Interesting as it can

Re: steps of a path

2022-09-03 Thread Ralph Mellor
Marc Chantreux wrote: > > I got ([^1,^2,^3]) and tried to generalize it with something > more generic (using * to get the number of elements). Yeah, I was disappointed that that didn't work, and that what did was relatively ugly, which is why I didn't bother to share it. <<. raku -ne '.Str.say f

Re: steps of a path

2022-09-03 Thread William Michels via perl6-users
Hi Marc, There's also this conversation from March 2021 on the mailing list: https://www.nntp.perl.org/group/perl.perl6.users/2021/03/msg9857.html [Matthew's answer looks very interesting]. Anyway, HTH. --Bill. On Sat, Sep 3, 2022 at 2:51 PM Marc Chantreux wrote: > On Sat, Sep 03, 2022 at 09

Re: steps of a path

2022-09-03 Thread Marc Chantreux
On Sat, Sep 03, 2022 at 09:50:08PM +0100, Ralph Mellor wrote: > > ( A B C ) to ((A) (A B) (A B C)) ? > [^1,^2,^3] I got that one and tried to generalize it with something more generic (using * to get the number of elements). thanks for helping -- Marc Chantreux Pôle de Calcul et Services Av

Re: steps of a path

2022-09-03 Thread Marc Chantreux
Hi Bruce and William, Ineed: I was looking for [\,] but your code removes the anoying empty string because of the leading / (which is awesome) so I mixed from both answers (<-[/]> is more robust than .alpha ) and added .Str to .say. finally I got: <<. raku -ne '.Str.say for m:ex /^ ["/" <-[/]>+:

Re: steps of a path

2022-09-03 Thread Ralph Mellor
On Sat, Sep 3, 2022 at 9:50 PM Ralph Mellor wrote: > > .put for [\~] '/A/B/C' ~~ m:g { '/'? <-[/]>+ } That won't match just a slash (`/`). Maybe: .put for [\~] '/A/B/C' ~~ m:g { ('/'? <-[/]>*) } And it'll treat `/a/b` and `/a/b/` as distinct if the input string is `/a/b/`. -- raiph

Re: steps of a path

2022-09-03 Thread Ralph Mellor
On Sat, Sep 3, 2022 at 9:50 PM Ralph Mellor wrote: > > it makes more sense to do something like Bruce or Michel's solutions. s/Michel/William/ -- raiph

Re: steps of a path

2022-09-03 Thread Ralph Mellor
On Sat, Sep 3, 2022 at 6:17 PM Marc Chantreux wrote: > > ( A B C ) to ((A) (A B) (A B C)) ? [^1,^2,^3] I could share a generalization but it's pretty ugly and I also think it makes more sense to do something like Bruce or Michel's solutions. Here's my variation: .put for [\~] '/A/B/C' ~

Re: steps of a path

2022-09-03 Thread William Michels via perl6-users
Hi Marc (and Bruce)! Okay, I use our old friend `:exhaustive` adverb below: ~$ echo "/var/log/messages" | raku -ne '.say for m:ex/ ^ ["/" <.alpha>+:]**?{1..*} /;' 「/var」 「/var/log」 「/var/log/messages」 If you remove the `?` frugal quant-modifier, the output is the same--except in the reverse ord

Re: steps of a path

2022-09-03 Thread Bruce Gray
> On Sep 3, 2022, at 12:17 PM, Marc Chantreux wrote: --snip-- > I thought the raku one could be shorter It will be hard to beat the brevity of a language with single-character instructions. --snip-- > I'm pretty sure I saw a very concise and elegant way to transform > ( A B C ) to ((A) (A

steps of a path

2022-09-03 Thread Marc Chantreux
hello people, I have this steps() function implemented this way in shell: steps() sed -r ':b p; s,/[^/]+$,,; t b' # demo: <<. steps | xargs ls -lUd /var/log/messages which shows -rw-r- 1 root adm 464304 Sep 3 19:03 /var/log/messages drwxr-xr-x 22 root root 4096 Sep 3 00:00 /var/log dr