zsh-users
 help / color / mirror / code / Atom feed
* (j.|.)
@ 2023-01-31 16:38 Ray Andrews
  2023-01-31 16:41 ` (j.|.) Roman Perepelitsa
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2023-01-31 16:38 UTC (permalink / raw)
  To: Zsh Users

Bart:

Your clipped comments and code:

# ${(j.|.)var} means to join an array with vertical bars; here the var 
is @ for the positional parameters.

# ${~something} means the value of something can be treated as a 
pattern, so the |-joined positional parameters form a pattern.

# "set --" replaces the original positional parameters with this array 
of parameter names.

set -- ${(ok)parameters[(I)${_v_case}${~${(j.|.)@}}]}

... I understand everything but the '(j.|.)' -- it seems ok like this:

     set -- ${(ok)parameters[(I)${_v_case}${~${@}}]}

... I see no vertical bars either before or after.  The PP's print as a 
spaced array either way.  But  you didn't but that in for no reason.  
Besides, the idea of joining the array seems backwards.





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-01-31 16:38 (j.|.) Ray Andrews
@ 2023-01-31 16:41 ` Roman Perepelitsa
  2023-01-31 16:49   ` (j.|.) Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Roman Perepelitsa @ 2023-01-31 16:41 UTC (permalink / raw)
  To: Ray Andrews; +Cc: Zsh Users

On Tue, Jan 31, 2023 at 5:39 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> Bart:
>
> Your clipped comments and code:
>
> # ${(j.|.)var} means to join an array with vertical bars; here the var
> is @ for the positional parameters.
>
> # ${~something} means the value of something can be treated as a
> pattern, so the |-joined positional parameters form a pattern.
>
> # "set --" replaces the original positional parameters with this array
> of parameter names.
>
> set -- ${(ok)parameters[(I)${_v_case}${~${(j.|.)@}}]}
>
> ... I understand everything but the '(j.|.)' -- it seems ok like this:
>
>      set -- ${(ok)parameters[(I)${_v_case}${~${@}}]}
>
> ... I see no vertical bars either before or after.  The PP's print as a
> spaced array either way.  But  you didn't but that in for no reason.
> Besides, the idea of joining the array seems backwards.

Try it with more than one argument to see the difference.

Roman.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-01-31 16:41 ` (j.|.) Roman Perepelitsa
@ 2023-01-31 16:49   ` Ray Andrews
  2023-01-31 17:50     ` (j.|.) Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2023-01-31 16:49 UTC (permalink / raw)
  To: zsh-users


On 2023-01-31 08:41, Roman Perepelitsa wrote:
> Try it with more than one argument to see the difference. 

A run time parse error!  Ok, I'll figure out what's happening.





^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-01-31 16:49   ` (j.|.) Ray Andrews
@ 2023-01-31 17:50     ` Ray Andrews
  2023-01-31 18:10       ` (j.|.) Roman Perepelitsa
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2023-01-31 17:50 UTC (permalink / raw)
  To: zsh-users


On 2023-01-31 08:41, Roman Perepelitsa wrote:
>> Try it with more than one argument to see the difference. 
>
>
Frustrating, Bart's version is necessary alright, but I can't dismantle 
it so as to see what's going on.  At no point is a vertical bar visible, 
it hasta be an operator of some kind, yes? An alternation?  Even 'set 
-x' is no help at all it shows the completed adjusted '@' with no 
indication of how it's put together.  How can I see how that works?


>
>
>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-01-31 17:50     ` (j.|.) Ray Andrews
@ 2023-01-31 18:10       ` Roman Perepelitsa
  2023-01-31 19:13         ` (j.|.) Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Roman Perepelitsa @ 2023-01-31 18:10 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 439 bytes --]

On Tue, 31 Jan 2023 at 18:50, Ray Andrews <rayandrews@eastlink.ca> wrote:

>
> On 2023-01-31 08:41, Roman Perepelitsa wrote:
> >> Try it with more than one argument to see the difference.
> >
> >
> Frustrating, Bart's version is necessary alright, but I can't dismantle
> it so as to see what's going on.  At no point is a vertical bar visible,
> it hasta be an operator of some kind, yes? An alternation?


print -r -- ${(j.|.)@}

Roman.

[-- Attachment #2: Type: text/html, Size: 1410 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-01-31 18:10       ` (j.|.) Roman Perepelitsa
@ 2023-01-31 19:13         ` Ray Andrews
  2023-01-31 20:19           ` (j.|.) Roman Perepelitsa
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2023-01-31 19:13 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 599 bytes --]


On 2023-01-31 10:10, Roman Perepelitsa wrote:
> print -r -- ${(j.|.)@}
>
Ah!  I tried printing everything but that -- the obvious thing. Ok, so 
the multiple args are converted to one string with bars between and 
somehow that ends up as an array of space-separated args in '@'.  I 
think I'm missing something important, I can't recall any such thing 
with bars like that.  zsh knows that the pattern expands to parameters 
too, I'm ... I guess the pattern isn't expanded until we know were 
within the $parameters ... yeah, so that's fine.  But I'd better get 
this 'bars' thing straight.




[-- Attachment #2: Type: text/html, Size: 1647 bytes --]

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-01-31 19:13         ` (j.|.) Ray Andrews
@ 2023-01-31 20:19           ` Roman Perepelitsa
  2023-01-31 21:50             ` (j.|.) Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Roman Perepelitsa @ 2023-01-31 20:19 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

On Tue, Jan 31, 2023 at 8:14 PM Ray Andrews <rayandrews@eastlink.ca> wrote:
>
> On 2023-01-31 10:10, Roman Perepelitsa wrote:
>
> print -r -- ${(j.|.)@}
>
> Ah!  I tried printing everything but that -- the obvious thing.  Ok, so the multiple args are converted to one string with bars between and somehow that ends up as an array of space-separated args in '@'.  I think I'm missing something important, I can't recall any such thing with bars like that.  zsh knows that the pattern expands to parameters too, I'm ... I guess the pattern isn't expanded until we know were within the $parameters ... yeah, so that's fine.  But I'd better get this 'bars' thing straight.

Do you understand what this does?

    print -r -- ${(ok)parameters[(I)pa*|PA*]}

How about this?

    () { print -r -- ${(ok)parameters[(I)${(j.|.)@}]} } 'pa*' 'PA*'

Roman.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-01-31 20:19           ` (j.|.) Roman Perepelitsa
@ 2023-01-31 21:50             ` Ray Andrews
  2023-01-31 23:33               ` (j.|.) Lawrence Velázquez
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2023-01-31 21:50 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: zsh-users


On 2023-01-31 12:19, Roman Perepelitsa wrote:
>
> Do you understand what this does?
>
>      print -r -- ${(ok)parameters[(I)pa*|PA*]}

I'm afraid I don't, never seen anything like it before this.  But I'd 
better find out.  I'm sure I've seen the pipe char. as an operator.  
Alternation, no?  But never in this sort of context. That would make 
sense: this pattern OR that pattern.  Above, obviously lower or upper 
case 'pa'.   Except that I can throw three or more patterns at the 
command so that would require another vertical bar, no? : ... pattern1 | 
pattern2 | pattern3 ... so if it only accepted two patterns I'd say 
that's it for sure, but it takes more than two.

  ... but wait ... the 'j' ... I don't know where to read up on that ... 
is it perhaps saying: 'keep on joining forever'?  Again, I've never seen 
it before, but if that's correct, then that's the answer -- join 
everything.  So then the bar in the string is in fact an operator, as I 
suspected, yes?  Then '(I)' matches anything in the alternation string 
and feeds the correct index # into the machinery there which then grabs 
the appropriate name. Sorta.  Yeah, that's gotta be it.  The tree I was 
barking up, was that somehow the aa|bb|cc ... was being directly 
converted into aa bb cc.  No, the former is a huge alternation.  Yes?  
'j' is the power in this.







^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-01-31 21:50             ` (j.|.) Ray Andrews
@ 2023-01-31 23:33               ` Lawrence Velázquez
  2023-02-01  0:21                 ` (j.|.) Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Lawrence Velázquez @ 2023-01-31 23:33 UTC (permalink / raw)
  To: Ray Andrews, Roman Perepelitsa; +Cc: zsh-users

On Tue, Jan 31, 2023, at 4:50 PM, Ray Andrews wrote:
> On 2023-01-31 12:19, Roman Perepelitsa wrote:
>>
>> Do you understand what this does?
>>
>>      print -r -- ${(ok)parameters[(I)pa*|PA*]}
>
> I'm afraid I don't, never seen anything like it before this.  But I'd 
> better find out.  I'm sure I've seen the pipe char. as an operator.  
> Alternation, no?

Search for "x|y" in zshexpn(1).

> But never in this sort of context.

Search for "Subscript Flags" in zshparam(1), then find the "I" flag.

>   ... but wait ... the 'j' ... I don't know where to read up on that ...

Search for "j:string:" in zshexpn(1).

-- 
vq


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-01-31 23:33               ` (j.|.) Lawrence Velázquez
@ 2023-02-01  0:21                 ` Ray Andrews
  2023-02-01  1:33                   ` (j.|.) Lawrence Velázquez
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2023-02-01  0:21 UTC (permalink / raw)
  To: zsh-users


On 2023-01-31 15:33, Lawrence Velázquez wrote:
> Search for "x|y" in zshexpn(1). 
No completions.  But it is an alternation surely.  Thing is that 
characters can have many different uses and one has to be sure of the 
context.  Before this I'd never seen anything other than something 
easily understandable as a plain vanilla number within '[ ]'.
> Search for "Subscript Flags" in zshparam(1), then find the "I" flag.
Ok, I have that one about understood.  So many tricks attach to 
associative arrays!   It's a powerful world in itself.
> Search for "j:string:" in zshexpn(1).

So my analysis was about right then (after Roman put me on the right 
scent).  hard to find the right place to read up on these single 
character operators.  Anyway that's maybe the deepest/hardest single 
statement I've yet tried to understand.  I learn more from studying 
something one of you masters has written than by attempting 'textbook' 
style study.

Tx.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-02-01  0:21                 ` (j.|.) Ray Andrews
@ 2023-02-01  1:33                   ` Lawrence Velázquez
  2023-02-01  1:59                     ` (j.|.) Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Lawrence Velázquez @ 2023-02-01  1:33 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

On Tue, Jan 31, 2023, at 7:21 PM, Ray Andrews wrote:
> On 2023-01-31 15:33, Lawrence Velázquez wrote:
>> Search for "x|y" in zshexpn(1). 
> No completions.

I don't know you're talking about.  Just run "man zshexpn" and
search for "x|y".  (You might have to escape the "|".  Alternately,
search for "Glob Operators" and find it by eye.)

>> Search for "Subscript Flags" in zshparam(1), then find the "I" flag.
> Ok, I have that one about understood.  So many tricks attach to 
> associative arrays!

The flag is not limited to associative arrays.

	% foo=axaybxby
	% print ${foo[(I)a?]}
	3
	% bar=(ax ay bx by)
	% print ${bar[(I)a?]}
	2
	% typeset -A baz=(ax 1 ay 2 bx 3 by 4)
	% print ${baz[(I)a?]}
	ax ay

-- 
vq


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-02-01  1:33                   ` (j.|.) Lawrence Velázquez
@ 2023-02-01  1:59                     ` Ray Andrews
  2023-02-01  2:14                       ` (j.|.) Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2023-02-01  1:59 UTC (permalink / raw)
  To: zsh-users


On 2023-01-31 17:33, Lawrence Velázquez wrote:
>
> I don't know you're talking about.  Just run "man zshexpn" and
> search for "x|y".  (You might have to escape the "|".  Alternately,
> search for "Glob Operators" and find it by eye.)
I can find it by eye.  Yeah with man: 'x\|y' works, but I was using info 
and it doesn't work. Never mind.
>
> The flag is not limited to associative arrays.
>
> 	% foo=axaybxby
> 	% print ${foo[(I)a?]}
> 	3
> 	% bar=(ax ay bx by)
> 	% print ${bar[(I)a?]}
> 	2
> 	% typeset -A baz=(ax 1 ay 2 bx 3 by 4)
> 	% print ${baz[(I)a?]}
> 	ax ay
>
Cool.  So much power!




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-02-01  1:59                     ` (j.|.) Ray Andrews
@ 2023-02-01  2:14                       ` Ray Andrews
  2023-02-01 22:47                         ` (j.|.) Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2023-02-01  2:14 UTC (permalink / raw)
  To: zsh-users


2 /aWorking/Zsh/Source/Wk 2 $ . v; dp widgets    # 'dp' = display-params
association-readonly-hide-hideval-special widgets

2 /aWorking/Zsh/Source/Wk 2 $ typeset + | grep widgets
association readonly widgets




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-02-01  2:14                       ` (j.|.) Ray Andrews
@ 2023-02-01 22:47                         ` Ray Andrews
  2023-02-02  0:43                           ` (j.|.) Lawrence Velázquez
  0 siblings, 1 reply; 16+ messages in thread
From: Ray Andrews @ 2023-02-01 22:47 UTC (permalink / raw)
  To: zsh-users


I guess nobody's interested in these things but here's another 
interesting one:


     3 /aWorking/Zsh/Source/Wk 0 $ typeset -LZ zz='  Howdy  '; echo $zz; 
dp zz
       How
     scalar-left-right_zeros zz='  Howdy  '

Doc only says that '-LZ' will be specially handled but doesn't say how 
right there.

'left-right_zeros' ??  BTW we seem to use 'zeroes' sometimes in the docs 
which is strictly speaking correct for 'zeroes in on the target' but 
deprecated as the plural.  Just to split hairs.

...

  Ah!  It's not documented that I can see, but maybe the above is 
accurately descriptive:


     3 /aWorking/Zsh/Source/Wk 0 $ typeset -LZ zz='000Howdy000'; echo 
$zz; dp zz
     Howdy
     scalar-left-right_zeros zz=000Howdy000

... so thereyago, it stripped zeros left and right :-)

Doc says leading zeros will be removed but silent about trailing zeros.




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-02-01 22:47                         ` (j.|.) Ray Andrews
@ 2023-02-02  0:43                           ` Lawrence Velázquez
  2023-02-02  1:21                             ` (j.|.) Ray Andrews
  0 siblings, 1 reply; 16+ messages in thread
From: Lawrence Velázquez @ 2023-02-02  0:43 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh-users

On Wed, Feb 1, 2023, at 5:47 PM, Ray Andrews wrote:
> I guess nobody's interested in these things but here's another 
> interesting one:
>
>
>      3 /aWorking/Zsh/Source/Wk 0 $ typeset -LZ zz='  Howdy  '; echo $zz; 
> dp zz
>        How
>      scalar-left-right_zeros zz='  Howdy  '
>
> Doc only says that '-LZ' will be specially handled but doesn't say how 
> right there.

Look at the documentation for "typeset -L".


> BTW we seem to use 'zeroes' sometimes in the docs 
> which is strictly speaking correct for 'zeroes in on the target' but 
> deprecated as the plural.

Debatable.  No reason to use both, though.


>   Ah!  It's not documented that I can see, but maybe the above is 
> accurately descriptive:
>
>
>      3 /aWorking/Zsh/Source/Wk 0 $ typeset -LZ zz='000Howdy000'; echo 
> $zz; dp zz
>      Howdy
>      scalar-left-right_zeros zz=000Howdy000
>
> ... so thereyago, it stripped zeros left and right :-)
>
> Doc says leading zeros will be removed but silent about trailing zeros.

That's because nothing is done to trailing zeros.

	% unset zz
	% typeset -LZ zz=000Howdy000
	% echo $zz
	Howdy000   
	% print -nr -- $zz | od -A n -t a
	           H   o   w   d   y   0   0   0  sp  sp  sp

I can't reproduce your results.  Try again in a clean shell, perhaps.


-- 
vq


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: (j.|.)
  2023-02-02  0:43                           ` (j.|.) Lawrence Velázquez
@ 2023-02-02  1:21                             ` Ray Andrews
  0 siblings, 0 replies; 16+ messages in thread
From: Ray Andrews @ 2023-02-02  1:21 UTC (permalink / raw)
  To: zsh-users


On 2023-02-01 16:43, Lawrence Velázquez wrote:

>
>> I can't reproduce your results.  Try again in a clean shell, perhaps.

Neither can I :(  These first explorations are very chaotic, it's hard 
to be sure what I did.  Probably forgot to unset the var. Anyway that 
returns to the original point that:

     scalar-left-right_zeros zz='  Howdy  '

... is a strange construction.  All my fooling around is meant to see 
both what the various options to typeset are going to do in practice, 
and also what attribute descriptions will show up.  So far the above is 
the only one that seems strange.  Basically it all very tight.  Perhaps 
a 'global' description would be nice. Other than that the only ambiguity 
is that decimal floats aren't distinguished from  scientific notation 
floats.  For once zsh is going the distance providing really readable 
and complete descriptions of something.

integer-readonly-hide-hideval-special:  ZCURSES_COLOR_PAIRS =

... could hardly be more helpful.




^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2023-02-02  1:22 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-31 16:38 (j.|.) Ray Andrews
2023-01-31 16:41 ` (j.|.) Roman Perepelitsa
2023-01-31 16:49   ` (j.|.) Ray Andrews
2023-01-31 17:50     ` (j.|.) Ray Andrews
2023-01-31 18:10       ` (j.|.) Roman Perepelitsa
2023-01-31 19:13         ` (j.|.) Ray Andrews
2023-01-31 20:19           ` (j.|.) Roman Perepelitsa
2023-01-31 21:50             ` (j.|.) Ray Andrews
2023-01-31 23:33               ` (j.|.) Lawrence Velázquez
2023-02-01  0:21                 ` (j.|.) Ray Andrews
2023-02-01  1:33                   ` (j.|.) Lawrence Velázquez
2023-02-01  1:59                     ` (j.|.) Ray Andrews
2023-02-01  2:14                       ` (j.|.) Ray Andrews
2023-02-01 22:47                         ` (j.|.) Ray Andrews
2023-02-02  0:43                           ` (j.|.) Lawrence Velázquez
2023-02-02  1:21                             ` (j.|.) Ray Andrews

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).