From: Timothy J. H. <ti...@cs...> - 2004-01-05 20:44:44
|
On Monday, January 5, 2004, at 03:19 PM, Ken Anderson wrote: > Is this a good idea? > > I've checked in a version of string-set! to allow for better use of > slib. > The definition is: > > (define (string-set! s i v) > (.hash$# s 0) > (vector-set! (.value$# s) i v)) Is this going to create a problem with interned strings? I seem to remember that we were interning literal strings by default in Jscheme. > > So when a character is set the hashcode is set to 0 so it will be > recomputed when needed. So as long as you stop calling string-set! on > a string before putting it in a hashtable you'll be OK. Using > string-set! on a string that in a hashtable will of course be a bad > thing to do. I wasn't sure what you were doing until I went into Jscheme and played around a little, as follows: > (define s "abcdef") "abcdef" > (.hash$# s) 0 > (.value$# s) [C@dc9766 > (load "elf/basic.scm") #t > (describe s) abcdef is an instance of java.lang.String // from java.lang.String value: [C@dc9766 offset: 0 count: 6 hash: 0 () > So, you are messing around with the undocumented implementation of String, so as to make strings mutable! This is clever, but violates all sorts of information hiding rules and fundamental precepts about object-oriented programming. Very cool! Sounds good! Lets use it! > > I've put this in jsint/primproc.scm because it is part of r4rs, but > maybe it should > get located with slib/ i can't decide. > > k But maybe put it in the slib code since we only really need strings to be mutable inside slib and there may be unforseen consequences (e.g. it might not work on all JDKs now and in the future...) Eventually, we might need to make it uglier by having it check which Java version it is using before mucking around with the internal undocumented representation.... ---Tim--- > > > > ------------------------------------------------------- > This SF.net email is sponsored by: IBM Linux Tutorials. > Become an expert in LINUX or just sharpen your skills. Sign up for > IBM's > Free Linux Tutorials. Learn everything from the bash shell to sys > admin. > Click now! http://ads.osdn.com/?ad_id=1278&alloc_id=3371&op=click > _______________________________________________ > Jscheme-user mailing list > Jsc...@li... > https://lists.sourceforge.net/lists/listinfo/jscheme-user |