[fluxus] equality commit (Re: interactivity issues)
Dave Griffiths
dave at pawfal.org
Mon Jul 17 07:06:20 PDT 2006
>>> I'm not sure I follow - how can you look up in an alist when
>>> eq/eqv/equal are not defined on the primitives?
>>
>> I need to do some research if a primitive-eq is enough for assq, and if
>> I
>> need to implement eqv and equal (which will be slow as they'll have to
>> do
>> a deep compare against every vertex, and won't be much use afaict)
>>
>> To be honest I'm tempted to revert it to the old system, where
>> primitives
>> were just represented by exact id numbers, it would make all this a lot
>> simpler again. I haven't tried this sort of thing since doing that :)
>
> ok, i think i missed this change which probably confused things a bit, but
> i
> would still assume that manually creating some structure containing
> something-like-what-mouse-over-used-to-return and whatever-it-retuns-now
> could
> work. ie. manually create object ids, when the actors are created [either
> by
> 'themselves' or otherwise). maybe think of it as extnded event handling,
> rathen
> than doing anythign to the actors, if it seems like inverted logic. or am
> i
> completly off the mark?!
I'm not sure, but the problem was that mouse-over returns something which
you can't accurately test equality on, so I don't think you can code a way
out of it without using something else like the transform or a special id
pdata value on the primitive.
This is fixed now anyway (in cvs) and I understand the problem a lot
better now (the bottom line for Claude is to update and use assoc or
equal?).
Equality is one of those things that needs a little more explanation than
you'd think. It's all about eq, eqv and equal. eq is fast and lazy, and
just tests simple values and references, eqv is a little more fussy, but
doesnt make any diffence in this context (I think).
so currently this works as expected:
(define a (build-cube))
(define b a)
(eq? a b)
=> #t
guile knows that b is a reference to a and can tell that they are the same.
However, (mouse-over) returns a new scheme primitive type, which
internally points to the same primitive in fluxus as the primitives in
your list.
But guile doesn't know this, so:
(define a (build-cube))
(define (render)
(if (eq? (mouse-over) a)
... do stuff))
Wont work, as eq? will always return #f. To solve this we have equal?
which does a deeper (and potentially slower) compare to see if the _things
that the references point to_ are the same. I've added a call which I
missed from the primitive scheme type for guile to use for this (which
compares the id integer so it's not slow)... so:
(define a (build-cube))
(define (render)
(if (equal? (mouse-over) a)
... do stuff))
does now work, and is consistent to the way scheme works.
To use associative arrays, you need to use assoc - which uses equal? to do
the key compare, rather than assq which uses eq?, or assqv which uses eqv?
For more information on this confusing topic:
http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-9.html#%_sec_6.1
cheers,
dave
More information about the Fluxus
mailing list