Kjetil S. Matheussen: > I think local-eval is necessary for making > a namespace system of the below type without having to use > codewalking macros to expand the bodies of functions: > > (define-namespace bank) > (def-bank sum 0) > (def-bank (add n) > (set! sum (+ n sum)) ;; Note that it's enough to write "sum". > > (bank.add 50) > bank.sum > => 50
This certainly looks like trashing global namespace (which isn't good in the long run) and doesn't allow you to have object handlers (like many variables referring to the same object) without additional quirks. > But for implementing a message passing OO system, > it's easier to use macros and hash tables, plus > that it probably performs much better: Pefrorms better than local-eval or better than define-namespace? > (def-class <bank> > (def-var sum 0) > (def-method (add n) > (set! sum (+ n sum))) > > (define bank (new <bank>)) > (-> bank add 50) > (-> bank sum) > => 50 > > There's a bunch of these systems for scheme. > The syntax above is used from > http://snd.cvs.sourceforge.net/snd/cvs-snd/oo.scm?view=log > > Guile's own OO system called GOOPS is also very nice. > GOOPS a quite verbose but very powerful and a lot > more interactive. It's similar to CL's CLOS, which > you should look at if you are not familiar with > already. Well, I've read some documentation of GOOPS and then I took a glimpse at its source. It has at least a few disadvantages, for it is an object system implemented in scheme -- it is therefore hard to access its objects from C (while closures are easily accessible through scm_local_eval) and it probably won't run as fast as local-eval, at least conceptually. (It is essential to observe that closures are already like objects and that any additional object systems are doubtfully needed with closures implemented properly -- as long as you can access their scope) Yet still I reserve the right to be wrong as a newbie :)
