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

World: r3wp

[!REBOL3-OLD1]

Ladislav
4-Jul-2009
[16040x2]
try this in R3


>> do http://www.rebol.org/download-a-script.r?script-name=identity.r
Script: "Identity.r" Version: none Date: 7-May-2009/8:59:07+2:00
Script: "Contexts" Version: none Date: 12-May-2006/15:58+2:00
Script: "Closure" Version: none Date: 11-May-2009/19:13:51+2:00
Script: "Apply" Version: none Date: 7-May-2009/9:25:31+2:00
== make function! [[
    "finds out, if the VALUE is mutable"
    value [any-type!] /local r
][
    parse head insert/only copy [] get/any 'value [

        any-function! | error! | object! | port! | series! | bitset! |
        struct! | set r any-word! (
            either bind? :r [r: none] [r: [skip]]
        ) r
    ]
]]

>> a: [z] append/only a a
== [z [...]]

>> b: [z [z]] append/only second b second b
== [z [...]]

>> c: [z [z]] append/only second c c
== [z [z [...]]]

>> equal-state? a a
== true

>> equal-state? a b
== true

>> equal-state? a c
== true
Apply and Closure not needed, but the script was written for R2
BrianH
4-Jul-2009
[16042]
Mere cycle detection is only good enough to throw a good error. To 
determine equivalence you need to compare different cycles to see 
if  they are the same shape. Or topologically equivalent if you are 
ambitious.
Ladislav
4-Jul-2009
[16043x2]
as I said: if we have 32 bits available for marking, it *is* enough
(and, said 32 bits are needed only for block-like data values, for 
other values, like objects, one bit is plenty)
BrianH
4-Jul-2009
[16045]
You didn't post the relevant code so I can't evaluate what you are 
saying. I'm searching for the code now.
Ladislav
4-Jul-2009
[16046x2]
do http://www.rebol.org/download-a-script.r?script-name=identity.r
(it is posted above)
BrianH
4-Jul-2009
[16048]
I got the link, but am reading it to find the code.
Ladislav
4-Jul-2009
[16049]
(R2 code, unadjusted for R3)
BrianH
4-Jul-2009
[16050]
There's a lot of code in there, not all of it relavant.
Ladislav
4-Jul-2009
[16051x2]
...but this variant does not use Mark bits, since those are available 
only in C
search for EQUAL-STATE?
BrianH
4-Jul-2009
[16053]
I'm translating while I read, boith to R3 and C.
Ladislav
4-Jul-2009
[16054]
LOL
BrianH
4-Jul-2009
[16055x2]
It's not as hard as it sounds :)
Already found some R2-isms, and I'm not just talking about the reflective 
accessors. Assumed case-sensitive equivalence of words, for instance.
Ladislav
4-Jul-2009
[16057]
yes, lots of those, no adjustment for R3, it is a surprise that it 
works at all
BrianH
4-Jul-2009
[16058]
Words in R3 preserve the case they are typed in, but are considered 
equivalent on a case-insensitive basis.
Ladislav
4-Jul-2009
[16059x2]
...but that is the case of R2 words too
(the variants having different case are "automatic aliases", as I 
call them)
BrianH
4-Jul-2009
[16061]
R2 words preserve the case they are *first* typed in, not the case 
they are  in every time.
Ladislav
4-Jul-2009
[16062]
I would need to see an example where it differs
BrianH
4-Jul-2009
[16063]
I noticed the difference before, but am not able to replicate it 
now :(
Ladislav
4-Jul-2009
[16064]
nevermind, we will "rediscover" it :-D
BrianH
4-Jul-2009
[16065]
In any case, for R3 line 502:
            if strict-not-equal? mold :a mold :b [return false]
should probably be this:
            if not-equal? mold :a mold :b [return false]
Ladislav
4-Jul-2009
[16066]
well, that is "in transition" still
BrianH
4-Jul-2009
[16067]
Probably for R2 as well, if your statement about R2 case-preserving 
is true.
Ladislav
4-Jul-2009
[16068]
depends on the level of strictness we want to achieve for the said 
EQUAL-STATE? function...
BrianH
4-Jul-2009
[16069]
Unless you want
>> equal-state? [A] [a]
== false
Ladislav
4-Jul-2009
[16070x2]
yes, that is what I achieved, as it looks
(lots of possibilities, and it was written long ago)
BrianH
4-Jul-2009
[16072]
You do topological comparison here, not  marking.
Ladislav
4-Jul-2009
[16073x4]
yes, I am actually unable to do marking in Rebol
but, if you want a model, I can write one
do you know how many bits can I use for marking?
(or is it just one bit? - in that case it indeed is a problem)
BrianH
4-Jul-2009
[16077]
Well, my point was that marking isn't enough here, and that this 
kind of comparison (the kind in equal-state?) is needed.
Ladislav
4-Jul-2009
[16078]
so, the question is, how many marking bits are available
BrianH
4-Jul-2009
[16079x3]
Only Carl has that answer. Still reading...
You would have to do something similar to a simplified EQUAL-STATE? 
even in a C version. There will never be enough bits for marking 
because every concurrent instance of your comparison would need its 
own set. Having thread-local done lists would work though.
concurrent instance of your comparison
 -> "concurrently running instance of your comparison function"
Ladislav
4-Jul-2009
[16082]
concurrently running instance of EQUAL? - yes, understood, that would 
be impossible, but such a thing can be made "atomic/protected", can't 
it?
BrianH
4-Jul-2009
[16083]
No.
Ladislav
4-Jul-2009
[16084]
why? RECYCLE and MOLD will be protected, won't they?
BrianH
4-Jul-2009
[16085]
You can make GC single-instance, but not MOLD or EQUAL?. MOLD and 
EQUAL? will be done too often to lock.
Ladislav
4-Jul-2009
[16086]
too often to lock - I would say, that RECYCLE is more likely to be 
"encountered" than MOLD or EQUAL?
BrianH
4-Jul-2009
[16087]
Unlikely - RECYCLE isn't FREE. The whole point to GC is that it isn't 
done that often.
Ladislav
4-Jul-2009
[16088]
yes, but it takes time: the "probability of encountering" is proportional 
to running time as well as to call frequency
BrianH
4-Jul-2009
[16089]
OK, EQUAL-STATE? is too strict in another way: It also considers 
values that precede the series references. I'm going to figure out 
if it will still work if changed to use the level of equivalence 
expected from EQUAL?. Note:
>> equal? next [a a] next [b a]
== true
>> equal? next [a a] next 'b/a
== false
Not sure about that last one - will it be true in R3?