zsh-users
 help / color / mirror / code / Atom feed
* Why approximate pattern doesn't match?
@ 2016-05-09 20:07 Sebastian Gniazdowski
  2016-05-09 20:11 ` Sebastian Gniazdowski
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-05-09 20:07 UTC (permalink / raw)
  To: Zsh Users

Hello,

a=( "git commit amend" )
pattern1='git*~^*comit*~^*amend'
pattern2='git*~^*commit*~^*amend'
echo "${(@M)a:#(#ia2)*$~pattern1*}"
-> [nothing]
echo "${(@M)a:#(#ia2)*$~pattern2*}"
-> git commit amend

Does somebody know why a2 isn't sufficient to match "comit" against "commit" ?

Best regards,
Sebastian Gniazdowski


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

* Re: Why approximate pattern doesn't match?
  2016-05-09 20:07 Why approximate pattern doesn't match? Sebastian Gniazdowski
@ 2016-05-09 20:11 ` Sebastian Gniazdowski
  2016-05-10  3:56   ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-05-09 20:11 UTC (permalink / raw)
  To: Zsh Users

Hello again,
it appears that the approximate matching works only for first word in
the *~^* sequence:

a=( "git push" )
pattern1='git*~^*pash*'
pattern2='pash*~^*git*'
echo "${(@M)a:#(#ia2)*$~pattern1*}"
-> [nothing]
echo "${(@M)a:#(#ia2)*$~pattern2*}"
-> git push

Any solution?

Best regards,
Sebastian Gniazdowski


On 9 May 2016 at 22:07, Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote:
> Hello,
>
> a=( "git commit amend" )
> pattern1='git*~^*comit*~^*amend'
> pattern2='git*~^*commit*~^*amend'
> echo "${(@M)a:#(#ia2)*$~pattern1*}"
> -> [nothing]
> echo "${(@M)a:#(#ia2)*$~pattern2*}"
> -> git commit amend
>
> Does somebody know why a2 isn't sufficient to match "comit" against "commit" ?
>
> Best regards,
> Sebastian Gniazdowski


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

* Re: Why approximate pattern doesn't match?
  2016-05-09 20:11 ` Sebastian Gniazdowski
@ 2016-05-10  3:56   ` Bart Schaefer
  2016-05-10  5:16     ` Sebastian Gniazdowski
  2016-05-10 16:42     ` Mikael Magnusson
  0 siblings, 2 replies; 11+ messages in thread
From: Bart Schaefer @ 2016-05-10  3:56 UTC (permalink / raw)
  To: Zsh Users

On May 9, 10:11pm, Sebastian Gniazdowski wrote:
} Subject: Re: Why approximate pattern doesn't match?
}
} Hello again,
} it appears that the approximate matching works only for first word in
} the *~^* sequence:
} 
} a=( "git push" )
} pattern1='git*~^*pash*'

I read that as: git followed by anything, except NOT matching (~)
anything NOT containing "pash".  Who came up with that double-negative?

} Any solution?

It doesn't seem so.

	/*
	 * By default, approximations are turned off in exclusions:
	 * we need to do this here as otherwise the code compiling
	 * the exclusion doesn't know if the flags have really
	 * changed if the error count gets restored.
	 */

So you don't get approximate non-matching, only approximate matching.

You can possibly refactor it this way:

    a=( "git push" )
    pat1='git*'
    pat2='*pash*'
    echo ${(@M)${(@M)a:#(#ia2)$~pat1}:#(#ia2)$~pat2}


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

* Re: Why approximate pattern doesn't match?
  2016-05-10  3:56   ` Bart Schaefer
@ 2016-05-10  5:16     ` Sebastian Gniazdowski
  2016-05-10 15:05       ` Peter Stephenson
  2016-05-10 16:42     ` Mikael Magnusson
  1 sibling, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-05-10  5:16 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

On 10 May 2016 at 05:56, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On May 9, 10:11pm, Sebastian Gniazdowski wrote:
> } Subject: Re: Why approximate pattern doesn't match?
> }
> } Hello again,
> } it appears that the approximate matching works only for first word in
> } the *~^* sequence:
> }
> } a=( "git push" )
> } pattern1='git*~^*pash*'
>
> I read that as: git followed by anything, except NOT matching (~)
> anything NOT containing "pash".  Who came up with that double-negative?

It was Mikael

> } Any solution?
>
> It doesn't seem so.
>
>         /*
>          * By default, approximations are turned off in exclusions:
>          * we need to do this here as otherwise the code compiling
>          * the exclusion doesn't know if the flags have really
>          * changed if the error count gets restored.
>          */
>
> So you don't get approximate non-matching, only approximate matching.

Too bad.. I was quite optimistic that this is: if there is another
matching run for consecutive ~^ block, then maybe some approximate
matching flag is just lost in the process, and the fix will be easy :(
What does above message mean, maybe it's 'just' "this is difficult as
we have only one error count" ?

> You can possibly refactor it this way:
>
>     a=( "git push" )
>     pat1='git*'
>     pat2='*pash*'
>     echo ${(@M)${(@M)a:#(#ia2)$~pat1}:#(#ia2)$~pat2}

I get input from user, multiple space separated words

Best regards,
Sebastian Gniazdowski


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

* Re: Why approximate pattern doesn't match?
  2016-05-10  5:16     ` Sebastian Gniazdowski
@ 2016-05-10 15:05       ` Peter Stephenson
  2016-05-10 15:21         ` Sebastian Gniazdowski
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Stephenson @ 2016-05-10 15:05 UTC (permalink / raw)
  To: Sebastian Gniazdowski, Zsh Users

By the way, reading the documentation isn't *always* futile.

  When  using  exclusion  via  the  ~  operator,  approximate matching is
  treated entirely separately for the excluded part and must be activated
  separately.  Thus, (#a1)README~READ_ME matches READ.ME but not READ_ME,
  as the trailing READ_ME is  matched  without  approximation.   However,
  (#a1)README~(#a1)READ_ME does not match any pattern of the form READ?ME
  as all such forms are now excluded.

pws


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

* Re: Why approximate pattern doesn't match?
  2016-05-10 15:05       ` Peter Stephenson
@ 2016-05-10 15:21         ` Sebastian Gniazdowski
  2016-05-10 15:40           ` Peter Stephenson
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-05-10 15:21 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh Users

Can (#a1) be embedded in parameter? Because it seems to not work. I do:

    search_pattern="${search_buffer// ##/*~(#a1)^*}"

to obtain (out from "git comit"):
git*~(#a1)^*comit

and then use it in:

    list=( "${(@M)list:#(#ia1)*$~search_pattern*}" )

So it's:

(#ia1)*git*~(#a1)^*comit*

in result.

Best regards,
Sebastian Gniazdowski


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

* Re: Why approximate pattern doesn't match?
  2016-05-10 15:21         ` Sebastian Gniazdowski
@ 2016-05-10 15:40           ` Peter Stephenson
  2016-05-10 17:16             ` Sebastian Gniazdowski
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Stephenson @ 2016-05-10 15:40 UTC (permalink / raw)
  To: Zsh Users

On Tue, 10 May 2016 17:21:33 +0200
Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote:
> Can (#a1) be embedded in parameter? Because it seems to not work. I do:
> 
>     search_pattern="${search_buffer// ##/*~(#a1)^*}"

I rather lost the point of all this right at the start, but the answer
to the question you're asking may be that as "^" is also a negation you
need to put the (#a1) after that, too, not just after the ~.

pws


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

* Re: Why approximate pattern doesn't match?
  2016-05-10  3:56   ` Bart Schaefer
  2016-05-10  5:16     ` Sebastian Gniazdowski
@ 2016-05-10 16:42     ` Mikael Magnusson
  1 sibling, 0 replies; 11+ messages in thread
From: Mikael Magnusson @ 2016-05-10 16:42 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

On Tue, May 10, 2016 at 5:56 AM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> On May 9, 10:11pm, Sebastian Gniazdowski wrote:
> } Subject: Re: Why approximate pattern doesn't match?
> }
> } Hello again,
> } it appears that the approximate matching works only for first word in
> } the *~^* sequence:
> }
> } a=( "git push" )
> } pattern1='git*~^*pash*'
>
> I read that as: git followed by anything, except NOT matching (~)
> anything NOT containing "pash".  Who came up with that double-negative?

I think I sent a mail to the list when I discovered it, the operations
simplify to "AND", which we don't have as a primitive. Eg foo~^bar
means result that match both patterns foo and bar. It is most
obviously useful when the second or first pattern is surrounded by *
so that it means *foo*~^*bar* gives files foobazbar, barbazfoo, barfoo
etc.

-- 
Mikael Magnusson


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

* Re: Why approximate pattern doesn't match?
  2016-05-10 15:40           ` Peter Stephenson
@ 2016-05-10 17:16             ` Sebastian Gniazdowski
  2016-05-10 17:29               ` Sebastian Gniazdowski
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-05-10 17:16 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh Users

On 10 May 2016 at 17:40, Peter Stephenson <p.stephenson@samsung.com> wrote:
> On Tue, 10 May 2016 17:21:33 +0200
> Sebastian Gniazdowski <sgniazdowski@gmail.com> wrote:
>> Can (#a1) be embedded in parameter? Because it seems to not work. I do:
>>
>>     search_pattern="${search_buffer// ##/*~(#a1)^*}"
>
> I rather lost the point of all this right at the start, but the answer
> to the question you're asking may be that as "^" is also a negation you
> need to put the (#a1) after that, too, not just after the ~.

This works. Thanks!

The point is: search history with set of keywords, requiring all of
them to match.

Best regards,
Sebastian Gniazdowski


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

* Re: Why approximate pattern doesn't match?
  2016-05-10 17:16             ` Sebastian Gniazdowski
@ 2016-05-10 17:29               ` Sebastian Gniazdowski
  2016-05-10 18:12                 ` Bart Schaefer
  0 siblings, 1 reply; 11+ messages in thread
From: Sebastian Gniazdowski @ 2016-05-10 17:29 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh Users

Moreover, (#a1) is also required after "|" when doing alternative for
"//" substitution:

colsearch_pattern="${search_buffer// ##/|(#a1)}"

What's interesting is that this (doing ${a//(#a1)a|(#a1)b|...}) is
painfully slow when compared to *~^* and :#, it works slower for 25
elements than :# works for 5000.

Best regards,
Sebastian Gniazdowski


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

* Re: Why approximate pattern doesn't match?
  2016-05-10 17:29               ` Sebastian Gniazdowski
@ 2016-05-10 18:12                 ` Bart Schaefer
  0 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2016-05-10 18:12 UTC (permalink / raw)
  To: Zsh Users

On May 10,  7:29pm, Sebastian Gniazdowski wrote:
}
} What's interesting is that this (doing ${a//(#a1)a|(#a1)b|...}) is
} painfully slow when compared to *~^* and :#, it works slower for 25
} elements than :# works for 5000.

As Mikael pointed out, ~^ is "and", whereas | is "or" -- for the "or"
case you have to compare every possibility to every array element, but
for the "and" case you can rapidly discard elements that don't match
the initial pattern.  It's not quite O(n*m) vs. O(n) but is in that
ballpark.


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

end of thread, other threads:[~2016-05-10 18:11 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-09 20:07 Why approximate pattern doesn't match? Sebastian Gniazdowski
2016-05-09 20:11 ` Sebastian Gniazdowski
2016-05-10  3:56   ` Bart Schaefer
2016-05-10  5:16     ` Sebastian Gniazdowski
2016-05-10 15:05       ` Peter Stephenson
2016-05-10 15:21         ` Sebastian Gniazdowski
2016-05-10 15:40           ` Peter Stephenson
2016-05-10 17:16             ` Sebastian Gniazdowski
2016-05-10 17:29               ` Sebastian Gniazdowski
2016-05-10 18:12                 ` Bart Schaefer
2016-05-10 16:42     ` Mikael Magnusson

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).