REBOL3 tracker
  0.9.12 beta
Ticket #0001719 User: anonymous

Project:

Previous Next
rss
TypeWish Statusreviewed Date26-Oct-2010 20:22
Versionalpha 109 CategoryUnspecified Submitted byCarl
PlatformAll Severityminor Prioritynormal

Summary Add COMPARE or MATCH
Description This is a commonly used function that I want to add, so make your comments known. (One question is whether this belongs in native or mezzanine code.)

Definition: when given two series, it will match them until they differ, and return the first series indexed to the difference position.

Usage example: you want to compare two binary exe's to see where they differ (like simple use of cmp in Unix/Linux).

An alternate implementation is to add MATCH (as proposed before, similar to FIND/match).
Example code
>> s: compare "abcdef" "abcdez"
== "f"
>> index? s
== 6

Assigned ton/a Fixed in- Last Update28-Oct-2010 21:14


Comments
(0002663)
maxim
26-Oct-2010 22:53

I'd prefer it be called diff.

this way:

>> diff "123" "123"
== none

and

>> diff "abcd" "abce"
== "e"
(0002664)
oldes
26-Oct-2010 22:54

And or:

find/diff
(0002665)
BrianH
26-Oct-2010 22:56

I agree with Maxim about the name. I can't think of an efficient enough way to do this in mezzanine though, so you might have to do a native. Perhaps as a FIND option like Oldes suggests.
(0002671)
Graham
26-Oct-2010 23:58

It's not a diff as it only shows where they start to differ.

I'd suggest the word - 'diverge or 'diverge?

diverge? "123" "123"
== none


(0002674)
BrianH
27-Oct-2010 00:28

The word "diverge" is a verb ("divergence" is the noun), but the DIVERGE? version would probably be OK. Or we could go with DIVERGENCE. DEVIATION would work too, though it might be better to reserve it for statistics and such.
(0002682)
Carl
27-Oct-2010 04:53

It's not DIFF. That name is reserved for a real diff that returns a block of differences, such as what Gabrielle has written already.

Isn't it really more of a match or compare? What Unix calls cmp?
(0002686)
Gregg
27-Oct-2010 21:12

I have an old FIND-DIFF mezz, but don't use it much. Carl, when you say "commonly used", what are the scenarios where you use it most? Unless you're using it on large series (e.g. > 100K) and also doing it in a loop where performance is critical, a mezzanine should be fast enough.

I like COMPARE better than MATCH, saving the latter for pattern matching. If COMPARE works on series, you have a tie-in to a CMP func that operates on files and is part of a standard RSH (REBOL Shell) environment. Of course, if you aren't thinking in terms of CMP, COMPARE is such a generic name that it doesn't tell you what it does--and why I chose FIND-DIFF as my mezz name.
(0002691)
maxim
28-Oct-2010 21:11

I do prefer COMPARE over MATCH in any case.
(0002692)
maxim
28-Oct-2010 21:14

also, it could be a nice refinement to FIND

>> s: find/difference "abcdef" "abcdez"

difference works here cause find implies stop at first match. Overall I think this is the most elegant naming in all the discussions I seen about this.

Date User Field Action Change
28-Oct-2010 21:15 maxim Comment : 0002692 Modified -
28-Oct-2010 21:14 maxim Comment : 0002692 Added -
28-Oct-2010 21:11 maxim Comment : 0002691 Added -
27-Oct-2010 21:12 Gregg Comment : 0002686 Added -
27-Oct-2010 04:53 carl Comment : 0002682 Added -
27-Oct-2010 00:28 BrianH Comment : 0002674 Modified -
27-Oct-2010 00:28 BrianH Comment : 0002674 Added -
26-Oct-2010 23:58 Graham Comment : 0002671 Added -
26-Oct-2010 22:57 BrianH Comment : 0002665 Modified -
26-Oct-2010 22:56 BrianH Comment : 0002665 Added -
26-Oct-2010 22:54 oldes Comment : 0002664 Added -
26-Oct-2010 22:53 maxim Comment : 0002663 Added -
26-Oct-2010 20:22 carl Description Modified -
26-Oct-2010 20:22 carl Code Modified -
26-Oct-2010 20:22 carl Status Modified submitted => reviewed
26-Oct-2010 20:22 carl Ticket Added -