Version française
Home     About     Download     Resources     Contact us    
Browse thread
ocamlagrep anybody ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Xavier Leroy <Xavier.Leroy@i...>
Subject: Re: [Caml-list] ocamlagrep anybody ?
> ocamlagrep produces strange results in my hands:
>
>   let p =  Agrep.pattern "test" ;;
>   let s = "Hello test world." ;;
>   let l = String.length s ;;
>
>   Agrep.errors_substring_match p s ~numerrs:0 ~pos:0 ~len:l
>
>     ==> returns 0   ( as expected )
>
>   Agrep.errors_substring_match p s ~numerrs:3 ~pos:0 ~len:l
>
>     ==> returns 3   ( why ??? Should be 0 !!! )
>
> I tried many other combinations and do not get what's going on.

It's been a long time since I wrote this library, but AFAIK
Agrep stops at the first (approximate) match found.
So, in your example with numerrs=0 it scans s all the way to "test"
and reports success; and in your example with numerrs=3 it stops
at "Hell" (a 3-error match) and reports success.

In other terms, the integer returned by errors_substring_match
is not the minimal number of errors for a match over the whole text.
If that's what you want, you can obtain that number by repeated calls
to errors_substring_match using binary search on the value of numerrs.

- Xavier Leroy