## [REBOL] Sameness - a pragmatic approach.

### From: lmecir::mbox::vol::cz at: 11-Feb-2003 8:36

In my opinion the best sameness should be the one that is the most useful
for a purpose, for which it is normally used.
My model task is:
let's have a block B with length 2. Let's suppose, that our partner tells
us, that his function F has inserted a value V into it. Our task is to find
the position at which the given value is.
The first implementation:
implementation1: func [b [block!] v [any-type!]] [
either equal? first b get/any 'v [1] [2]
]
This implementation has got the following disadvantage:
v: [1]
b: [[1]]
insert/only tail b v
implementation1 b v ; == 1
, although we know, that the value V has been stored at the position 2.
Let's improve our implementation using SAME? instead of EQUAL?:
implementation2: func [b [block!] v [any-type!]] [
either same? first b get/any 'v [1] [2]
]
implementation2 b v ; == 2
Which is better than before. Nevertheless, Joel showed that IMPLEMENTATION2
isn't optimal, because:
v: 3.0
b: [3]
insert/only tail b v
implementation2 b v ; == 1
, while the correct answer is 2. My last implementation will use my
IDENTICAL? function (described in
http://www.rebolforces.com/~ladislav/evaluation.html ).
do http://www.rebolforces.com/~ladislav/evaluation.r
implementation3: func [b [block!] v [any-type!]] [
either identical? first b get/any 'v [1] [2]
]
implementation3 b v ; == 2
In the above mentioned article I proved, that there is no other function,
which could be used instead of the IDENTICAL? function for a new
implementation and help us to get the correct answer with higher probability
than IMPLEMENTATION3.
Regards
-L