Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Inconsistencies in "-quoting and @-splitting, could someone elaborate?



PS. I'm not examining this to induce some changes in Zsh – I think
every project can have bunch of its distinct traits, non-symmetrical –
but to gain more knowledge and maybe get information about other flags
like z&s, to provide a possibly clear paragraph about exceptions in
the document "Zsh Native Scripting Handbook". It currently follows "@
is double-quoted splitting" based on completion-description and some
insight/revelations, and it's too optimistic, doesn't describe
exceptions.
On Sun, 28 Oct 2018 at 16:41, Sebastian Gniazdowski
<sgniazdowski@xxxxxxxxx> wrote:
>
> On Sun, 28 Oct 2018 at 12:54, Sebastian Gniazdowski
> <sgniazdowski@xxxxxxxxx> wrote:
> > Despite array is single element, @ splits it into array type. (s::)
> > and (z) behave differently for single-element result, that is one
> > (maybe subjective) inconsistency, and for the second – @ doesn't help
> > (ie. (z@) still doesn't return as an array), that's second
> > inconsistency IMO.
>
> I've forgot one inconsistency and thought that a more explicit
> description of them (of the (subjective) inconsistencies) can be
> provided:
>
> 1.a) array=( "foo" ); print "${#${(@)array}}" -> 1
> 1.b) words="singleword"; print "${#${(z)words}}" -> 10
> 1.description) with @, it is possible to obtain "always-array"
> behavior, while (z) and (s::) have exceptions and not always return
> arrays (one could think that if a flag takes the responsibility for
> splitting in string-context ("-quoted), then that it will mimic the
> first tool to do that, the @)
>
> 2.a) the same as 1.a
> 2.b) words="singleword"; print "${#${(z@)words}}" -> 10
> 2.description) if ${(@)array} makes single-element quoted array back
> an array again, then shouldn't @ acting on single-element data (Bart
> said it's not array) returned by (z)/(s::) also make it an array
> again?
>
> 3.a) array=( "foo" "bar" ); print -rl "$array" -> foo bar # both
> elements in one line, signaling the expected "scalarization"
> 3.b) words="two words"; print -rl "${(z)words}" -> foo\nbar # two
> lines, with one word each, indicating non-scalar result
> 3.c) words="two words"; print -rl "${(s: :)words}" -> foo\nbar # --- " ---
> 3.description) Basically, the general method of Zshell to obtain
> scalars with no splits – double-quoting – isn't followed by (z) and
> (s::) flags. The manuals often elaborate about some situations and
> "-quoting like if this would be a general "scalarization" method
> guaranteed by Zsh design. Hard to give examples, but maybe this one:
>
>     ${name:|arrayname}
>               ... If the substitution is scalar, either because
>               name is a scalar variable >>or the expression is
> quoted<<, the elements of arrayname are instead  tested
>               against the entire expression.
>
> Above slightly suggests "-quoting as a general method for obtaining scalars.
> --
> Sebastian Gniazdowski
> News: https://twitter.com/ZdharmaI
> IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
> Blog: http://zdharma.org



-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org



Messages sorted by: Reverse Date, Date, Thread, Author