From: Ken A. <kan...@bb...> - 2004-07-19 15:25:17
|
Hi, please join the Jscheme-user mailing list! At 05:09 PM 7/18/2004 -0400, Alan Donovan wrote: >Hi Ken, I've had a little play around with JScheme this weekend and I >love it! Especially for building GUIs, interactive programming is >obviously the Right Way; it avoids the long library start-up times >since you never stop. There's also so much less "crap" to be typed in >to implement a simple event handler. It reminds me of interacting >with 'wish' (Tcl/Tk). Yes! I'm glad you like it. I find it a lot of fun! >I have a couple of questions though: > >1) How does "eq?" and "eqv?" relate to ".equals"? "eq?" seems to use > object identity and "eqv?" seems to implement 'equivalence', but > only for certain datatypes (e.g. Integer but not String). What's > going on here? > > For example: > > (eq? (Integer. 1) (Integer. 1)) = #f ;; reference equality > > (eqv? (Integer. 1) (Integer. 1)) = #t ;; interpreter knows > ;; equivalence relation of > ;; Integers (?) > > (eqv? (String. "foo") (String. "foo")) = #f ;; interp doesn't know > ;; about Strings > > (.equals (String. "foo") (String. "foo")) = #t ;; use Java equivalence > http://www.math.grin.edu/courses/Scheme/r5rs-html/r5rs_48.html (eq? x y) checks that x and y are the same object. However, JScheme caches small Integers and Characters, so they may sometimes be eq?: > (eq? 10 10) #t > (eq? 34141 34141) #f Also, JScheme uses Java semantics and interns string constants: > (eq? "foo" "foo") #t > (eq? "foo" (String. "foo")) #f (eqv? x y) is x and y are of the same atomic class and they are .equals? This is actully different than the current implementation. Currently, > (eqv? 3L 3) #t > (eqv? 3.0 3) #t which i think should both return #f. Tim, i'd like to propose this as a new definition of eqv? (define (atomicClass? c) (or (eq? c Boolean.class) (eq? c Byte.class) (eq? c Short.class) (eq? c Integer.class) (eq? c Long.class) (eq? c Float.class) (eq? c Double.class) (eq? c Symbol.class))) (define (eqv? x y) (or (eqv? x y) (let ((c (.getClass x))) (and (atomicClass? c) (eq? c (.getClass y)) (.equals x y))))) > Also, I don't understand how this interacts with 'case', which > according to R4RS, uses the semantics of the 'eqv?' relation. > Therefore: > > (case (String. "foo") > ((String. "foo") #t) > (else #f)) > > should yield the same as the eqv? expression above (#f) but does > not: it returns #t, which is surprising. Does 'case' use .equals? You're using case incorrectly. Your code expands into: (let ((temp var (String. "foo"))) (cond ((member temp var '(String. "foo")) #t) (else #f))) > I suspect that many Java programs don't implement equals() very > well, in particular, some classes throw an exception if the RHS > operand cannot be casted as expected -- i.e. equals is implemented > as a partial function in the RHS. I can see that this might be a > reason to avoid eagerly calling .equals. > >2) Do you have an Emacs scheme mode that correctly handles the > character literals #'(' etc? My standard scheme mode gets rather > confused. I use src/emacs/scheme-init.el, but it doesn't handle #'x' either. This might be worth looking into. >3) Do you have any JLib library + example code for building tree > widgets? I've never much liked the Swing API, it's super-complex > when most of the time you just want to make something simple. src/jsintc/jlib/demo/ClassBrowser.scm >4) Is there any online documentation of all the available library > procedures? http://jscheme.sourceforge.net/jscheme/doc/R4RSprimitives.html You can also do apropos. and describing a function with print its definition: car: {jsint.Primitive car[1]} set-car!: {jsint.Primitive set-car![2]} #f > (describe describe) Closure named describe (lambda (x) (if (eq? x '#null) (display (!{} '"" x '" is null ")) (describe-object x))) 26 |