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

Re: Feature request – substitutions similar to +, -, :+, :-

On 18 Nov 2017 at 19:46:18, Bart Schaefer (schaefer@xxxxxxxxxxxxxxxx) wrote:
> If I understand your example correctly, $theme[use-name] is either
> unset/empty, or it contains "1" or "0".
> So I think :& is just ${(M)theme[use-name]:#1} and :^ is ${theme[use-name]:#0}.

It looks for me that this would filter value "1" or filter-out value "0". It seems that this doesn't translate to code-shortening one-liner. I was rather wrong in my original post when I wrote about boolean substitutions targetting 0 and 1 values. Direct access to use case is needed to filter useful thing (while I was doing retrospection). However today an IRC user had one use case:

:- does:

if (VAR) { return VAR } else { return "something else"; }

new :- (with proposed :^ form) should:

if (VAR) { return "" } else { return "something else" }

So it's about clearing default output. This would allow somewhat boolean-style code, like:

% DOCS=yes (or DOCS="")
% find ${${DOCS:^Pictures}:-Documents}

This does: If DOCS empty (checked by :^ substitution), then use "Pictures", otherwise, use "Documents" (because :- detects empty default output <-> DOCS is true, not-empty).

For boolean evaluations, clearing actual output is intuitively expected. What's left is just that as long as ^ associates with negation action, a better form would be good, that would associate with empty value, like minus "-", ":-".

Sebastian Gniazdowski
psprint /at/ zdharma.org

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