This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: embedding question: defining symbols?


Han-Wen Nienhuys <hanwen@cs.uu.nl> writes:

> jimb@red-bean.com writes:
> > Hail, Han-Wen!  (gosh)
> > 
> > 
> > You have the right idea.  However, guile doesn't have first-class
> > environments at the moment; we just use ordinary hash tables to map
> > our symbols to their values.
> > 
> > So I think (if I can read your C++) that you want to make a C++ class
> > that wraps Guile symbol objects with a few methods, and then use a
> > Dictionary<Guile_Symbol> in class Bla.  
> 
> Is it guaranteed that the value of SCM is not changed from under
> during GC, so that I can just use ((SCM >> 32) ^ (SCM & 0xffffffff))
> as a hashing function?

Yep, a SCM is just a pointer into the heap, or an immediate
object, neither of which is changed by the gc. 

That's probably not the best hash function, though, at least on 32 bit
intel machines, since there
((SCM >> 32) ^ (SCM & 0xffffffff)) == 0

(the intel sar/shr operations are masked to 5 bits, so
 SCM>>32 == SCM>>0 == SCM)

The correct hash for this is probably
(((SCM >>31)>>1) ^ (SCM & 0xffffffff))
but ~SCM does the same thing, and it's quicker :)

> > That is, find some way to use
> > symbols as the keys in your table.
> > 
> > When Guile acquires real first-class environments, then you may want
> > to change your code.
> 
> So what you are saying is, that I also cannot recode C++ methods in
> Scheme? Hmm...
> 
> > I wonder if Guile's new MOP could somehow accomodate your classes, and
> > let LilyPond objects be subclassed in Scheme, etc.
> 
> What is a MOP?
 
MetaObject Protocol. Basically (as I understand it) it's a way to
define an object system in terms of metaobjects, which are the basic
objects that constitute the system, and describe the behaviour of the
actual object system in terms of metaobjects (a bit recursive, I would
think ;). Better than me trying to explain it more (and confusing
myself ;), an example is the clos-mop, online at

http://www.elwood.com/alu/mop/index.html

or (ps and latex sources)

ftp://parcftp.xerox.com:/pub/pcl/mop/


-- 
Greg