r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[RAMBO] The REBOL bug and enhancement database

Ladislav
26-Jan-2007
[2548x2]
I show you something from my article:

a: b: charset [#"a" #"b"] c: insert charset [#"a"] #"b
identical?: func [
    {are the values identical?}
    a [any-type!]
    b [any-type!]
    /local var var2
] [
    ; compare types

    if not-equal? type? get/any 'a type? get/any 'b [return false]
    ; there is only one #[unset!] value
    unless value? 'a [return true]
    ; errors can be disarmed and compared afterwards
    if error? :a [a: disarm :a b: disarm :b]
    ; we need to be transitive for decimals and money
    if any [decimal? :a money? :a] [
        return found? all [same? a b zero? a - b]
    ]
    ; we need to be transitive for dates

    if date? :a [return found? all [same? a b same? a/time b/time]]
    ; we need to be able to compare even the closed ports
    if port? :a [return equal? reduce [a] reduce [b]]
    ; our function has to work for structs
    if struct? :a [return same? third a third b]
    ; we can have something stronger than SAME? for bitsets
    if bitset? :a [
        unless same? a b [return false]
        if 0 = length? a [return true]
        unless equal? var: find a 0 find b 0 [return false]
        either var [
            remove/part a 0
            var2: find b 0
            insert a 0
        ] [
            insert a 0
            var2: find b 0
            remove/part a 0
        ]
        return var <> var2 
    ]
    same? :a :b
]
identical? a b ; == true
identical? a c ; == false
identical? a copy a ; == false
Pekr
26-Jan-2007
[2550]
the question probably is, what we consider being "identical"? Is 
5 in memory slot 1234 identical to 5 in memory slot 4321? It could 
be. But I can also imagine that 'same serves the purpose of finding 
out, if two words reference the same slot?
Ladislav
26-Jan-2007
[2551]
your question is answered in http://www.fm.tul.cz/~ladislav/rebol/identity.html
Pekr
26-Jan-2007
[2552]
ok, thanks, will read it ...
Volker
26-Jan-2007
[2553]
Expected behavior: things  which are modified  when one thing is 
 modified should be same.

Expected Reason for  current behavior:  bitsets with the  same data 
 share the  same data automatically  to save  space.

Expected Reason for bug: 'same? compares the  pointer to  the data, 
which is automatically made same with equal data.
Expected Fix: comare something else :)
Pekr
26-Jan-2007
[2554]
:-)
Ladislav
26-Jan-2007
[2555x2]
Expected Reason for  current behavior:  bitsets with the  same data 
 share the  same data automatically  to save  space.
 proven wrong above
Expected Reason for bug: 'same? compares the  pointer to  the data, 
which is automatically made same with equal data.
 proven wrong above
Anton
26-Jan-2007
[2557]
Yep, I think SAME? was just quickly implemented using the existing 
equality function.
Pekr
26-Jan-2007
[2558]
then it needs to be fixed, and we need precise definition, of what 
actually 'same compares and decides upon
Volker
26-Jan-2007
[2559x2]
can you make a simpler example, so i can analyze code? My tests say 
 yes, what  do i miss?
The the explanation with equal? makes sensse too.
Ladislav
26-Jan-2007
[2561]
I have proven, that there is a function (IDENTICAL?), which has got 
the following property:
a: b: charset [#"a" #"b"] c: insert charset [#"a"] #"b
identical? a b ; == true
identical? a c ; == false
identical? a copy a ; == false
Volker
26-Jan-2007
[2562]
but  how does itdecide that? If  it is by modifying the data, that 
would be re-samed when you change  the data  back
Ladislav
26-Jan-2007
[2563]
nothing is re-samed, if it were, IDENTICAL? a b would have to yield 
FALSE
Volker
26-Jan-2007
[2564x3]
hu? a and b have the equal content. so  they would point to  the 
same  data. so  'same? would return true.
Hmm, complicated . you may be  right. *thinking
would cost  much performance to keep track of all the data.
Ladislav
26-Jan-2007
[2567]
you are right, that it is *theoretically* possible, but in that case 
my IDENTICAL? function wouldn't be able to yield TRUE
Volker
26-Jan-2007
[2568x3]
It would if there is  an intemediate  structure. value -> intermediate 
-> bitsetdata.
then a and b point to that structure. the pointer in the structure 
is  changed. but a and b return the same still  the stuff.
.. return still the equal stuff.
Ladislav
26-Jan-2007
[2571]
I rather state it in a positive way: since my IDENTICAL? function 
correctly compares bitsets (can be tested), the model I am using 
is correct
Volker
26-Jan-2007
[2572x2]
IMHO  but  implementations would  have the same results, but mine 
is more silly;)
but -> both
Ladislav
26-Jan-2007
[2574]
as I said, I consider my claims proven. The IDENTICAL? function explores 
the identity by manipulating the data, so it actually is able to 
find out whether two bitsets share data or not
Volker
26-Jan-2007
[2575]
You modify the  a-node and  b points to the same node. if you check 
b you see the same changes.
Ladislav
26-Jan-2007
[2576x2]
yes, I found out, that A and B share data
in the same way I found out the A and C don't share data
Volker
26-Jan-2007
[2578]
They still  share the same data  if you point  a pointer in the node 
to something else. But - here is  rambo, move somewhere else. Your 
 version seems more  plausible from the  implementation effort, i 
want to makemy point  for  academical reasons.
Ladislav
26-Jan-2007
[2579]
understood, but you are missing an inconsistency in your reasoning
Volker
26-Jan-2007
[2580]
.. let us move somewhere else? (do not want to command you ;)
Ladislav
26-Jan-2007
[2581]
I am still not sure, whether this can or cannot be called a bug:

    #"a" = #"A" ; == false
Rebolek
26-Jan-2007
[2582]
Not a bug.

DESCRIPTION:
     Returns TRUE if the values are equal.

>> equal? #"a" #"A"
== false

and

>> to integer! #"a"
== 97
>> to integer! #"A"
== 65

Definitely not equal.
Ladislav
26-Jan-2007
[2583]
it is related to:

    difference [#"a"] [#"A"]
Rebolek
26-Jan-2007
[2584]
I think that case-sentisitivity does matter only with string! not 
with char!
Ladislav
26-Jan-2007
[2585]
looks so, but I don't think it is explicitely stated anywhere
Rebolek
26-Jan-2007
[2586]
but that's not true with FIND, hm.
Ladislav
26-Jan-2007
[2587]
yes, the situation is somewhat "mixed"
Rebolek
26-Jan-2007
[2588]
If FIND can be changed for R3, I'll be glad. I remember having problems 
with finding bytes in binary because of this inconsistency. I had 
to use find/case always.
Ladislav
26-Jan-2007
[2589]
unfortunately for you it seems to make sense, because the opposite 
refinement does not exist
Rebolek
26-Jan-2007
[2590]
yes, but it seems little bit strange, use find/case with pure binary 
data :)

But I though changing it only for char!, you can always use (find 
string "a") for case insensitive search.
JaimeVargas
26-Jan-2007
[2591]
Ladislav, I wonder if your task will be easier if you have an semantic 
model for the language instead of trying to create a coverage test 
set.
Ladislav
27-Jan-2007
[2592]
Another question worth asking: I can agree that it is useful to obtain 
TRUE from equal? 0.1 + 0.1 + 0.1 0.3, although zero? 0.1 + 0.1 + 
0.1 - 0.3 cannot yield TRUE due to the limitations of 64-bit IEEE754 
floating point format. On the other hand the STRICT-EQUAL? and/or 
SAME? functions may be stricter. E.g. my IDENTICAL? function (see 
above) is the most strict possible in that respect and yields FALSE.
Volker
27-Jan-2007
[2593]
AFAIK equal? in rebol is relaxed and does a range-check. For close-to-zero. 
And 'equal?  is the  relaxed version. 'strict-equal? should not. 
IMHO.
Ladislav
27-Jan-2007
[2594]
that is my understanding too. what about SAME?,  where would you 
like to see that in the strictness scale?
Volker
27-Jan-2007
[2595x2]
even more strict than 'strict-equal? :)
may break with  save/load because of conversion-errors, but if i 
use that i know what i do.
Ladislav
27-Jan-2007
[2597]
actually, e.g. for decimal! values there *is* a way how to suppress 
the conversion errors