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/
/Users/none
/Users
/

The second code example will first check for a given directory:

~$ echo "/Users/admin/Documents/" | raku -e 'for lines.IO -> $a is copy {if
$a.d {$a.Str.say; repeat {$a.=parent andthen $a.Str.say;} until $a eq
$*SPEC.rootdir}};'
/Users/admin/Documents/
/Users/admin
/Users
/
~$ echo "/Users/none/bogus_dir/" | raku -e 'for lines.IO -> $a is copy {if
$a.d {$a.Str.say; repeat {$a.=parent andthen $a.Str.say;} until $a eq
$*SPEC.rootdir}};'
~$

https://docs.raku.org/type/IO::Path#File_test_operators

HTH, Bill.

On Wed, Sep 7, 2022 at 7:39 AM William Michels 
wrote:

> 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/admin
> /Users
> /
>
> Note, above won't actually check if the given directory is valid--it only
> checks the parents. To check a given directory first, try the following:
>
> ~$ echo "/Users/admin/bogus_dir/" | raku -e 'for lines.IO -> $a is copy
> {if $a.d {$a.Str.say; repeat {$a.=parent andthen $a.Str.say;} until $a eq
> $*SPEC.rootdir}};'
>
> #returns nothing for `bogus_dir`
>
> HTH, Bill.
>
>
> On Mon, Sep 5, 2022 at 1:56 PM Marc Chantreux  wrote:
>
>> 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 Services Avancés à la Recherche (CESAR)
>> http://annuaire.unistra.fr/p/20200
>>
>


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
> opposite to "idiomatic", for programming that arrives at a solution by
> a Rube Goldberg/Heath Robinson sort of convoluted and unnecessary
> path, or utterly abuses the language in a fashion that contradicts its
> underlying purpose or philosophy (writing video games in sed or
> invoicing programs in Lisp). "Idiotmatic" suggests itself. :-)*
>

  Sure you don't want "idiosyncratic"?


Eirik


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 Goldberg/Heath Robinson sort of convoluted and unnecessary
path, or utterly abuses the language in a fashion that contradicts its
underlying purpose or philosophy (writing video games in sed or
invoicing programs in Lisp). "Idiotmatic" suggests itself. :-)*


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/admin
/Users
/

Note, above won't actually check if the given directory is valid--it only
checks the parents. To check a given directory first, try the following:

~$ echo "/Users/admin/bogus_dir/" | raku -e 'for lines.IO -> $a is copy {if
$a.d {$a.Str.say; repeat {$a.=parent andthen $a.Str.say;} until $a eq
$*SPEC.rootdir}};'

#returns nothing for `bogus_dir`

HTH, Bill.


On Mon, Sep 5, 2022 at 1:56 PM Marc Chantreux  wrote:

> 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 Services Avancés à la Recherche (CESAR)
> http://annuaire.unistra.fr/p/20200
>


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
languages. But what do *you* mean? Or, even better, can you identify a
few of the many useful suggestions folk have made in this thread which
you would count as being, or possibly worthy of being, "idioms"?

Wikipedia notes two uses of the term "idiom" in this context (claiming the first
is correct but the second isn't, though the distinction seems immaterial here):

> code [with a] semantic role, which recurs frequently across software projects

> using a programming language in a typical way

I know I wasn't particularly aiming at either of those, but instead playing golf
in response to what I thought you were after, and focusing on:

* First and foremost, Larry's notion of "clean golf" (minimal tokens,
not bytes).

* Secondarily my notion of "semantic golf" (minimal mental effort when reading).

In other words my goal was code requiring minimal reading effort to understand
while still appropriately expressing the desired computational result
and/or effect.



> > Is that because it knows me, or has google started blessing Larry's
> > neologisms for the whole planet?!? )

I now think it (gmail and/or my brain; they may or may not have
merged) glitched on me.

> Why not? new words happens all the time and those one are useful for
> programmers.

I had done a google for "whipupitude" before I wrote the thought bubble in
my previous message. Google claimed it found 300 results. I just tried again;
adding -perl shrank their claim to just 8 matches.

That said, right now gmail is claiming whipupitude is misspelled...

--
raiph



>
> --
> Marc Chantreux
> Pôle de Calcul et Services Avancés à la Recherche (CESAR)
> http://annuaire.unistra.fr/p/20200