From: Ken A. <kan...@bb...> - 2004-06-25 01:56:29
|
Yes a snippets page would be good. I've started collecting the hacks i've sent out as email. I think they should be examples of real code we've needed to use. elf/ and using/ are mostly that. I use them every day. Developing JScheme idioms is important because it really sets JScheme programming apart from Java programming. I've been doing a lot of gui development, i don't have the idiom right yet, but its nice to know you can develop a Java gui without writing a class, or compiling anything, and can change the behavior on the fly. I couldn't tell how the new parameter in the servlet is being used!? At 08:33 PM 6/24/2004 -0400, Timothy John Hickey wrote: >Nice example! > >Maybe we should create a webpage of Jscheme snippets on the >jscheme.sourceforge.net site. >This one could be titled something like > > * generate a sort list of selected fields from tab-separated file of >records... And we should say where to get such data. Geoffrey had the same data i did because we are working on projects related to aviation. >Here's an example I wrote today. >Its a servlet that generates a webpage showing all of the symbols that >are defined > >If you call it with a "which" parameters, e.g. > show_bindings.servlet?new >it will filter out all of the primitives, all of the javadot, and all >those symbols defined in elf/basic.scm > >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; >;;; show_bindings.servlet >(servlet (new) > (define js (jscheme.JScheme.)) > (define mod (.eval js '(use-module "elf/basic.scm"))) > > (define (getBindings env) (.rep$# env)) > (define jsenv (.INTERACTION_ENVIRONMENT$ (.evaluator$# js))) > > (define primitives > (getBindings jsenv)) > (define currentbindings > (getBindings (.INTERACTION_ENVIRONMENT$ >(jsint.Scheme.currentEvaluator)))) > > (define newbindings > (filter > (lambda(x) > (or (equal? which #null) > (and > (equal? #null (.get primitives x)) > (= -1 (.indexOf (.toString x) ".")) ))) > (map* (lambda(x) x) (.keys currentbindings)))) > > (define (show-bindings) > {<ol>[ > (map* > (lambda(x){<li>[x] </li>\n}) > (sort newbindings (comparator string<? .toString))) > ] > </ol>}) > >(show-bindings) >) >;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; > > >This is somewhat fragile code however since it uses the jsint package >and things may change >more rapidly in jsint than in jscheme (witness the disappearance of >jsint.Version.java!) > >---Tim--- > >On Jun 23, 2004, at 7:10 PM, Ken Anderson wrote: > >>I wrote this piece of code today and it struck me: >> >>(define (readCountryData) >> (sort >> (remove-duplicates >> (readingTabData >> (File. "../dafif/Dafift/AppC/appc_cc_icao.txt") >> (lambda (country country_name icao_rgn usage) >> (list country country_name)))) >> (comparator string<? car))) >> >>(define (readingTabData file f) >> (map* (lambda (r) (apply f (vector->list (.split r "\t")))) >> (BufferedReader. (FileReader. file)))) >> >>Now, this code can be improved in a lot of ways, but it did what i >>wanted - grind over a tab separated file, extract the fields i wanted, >>and sort the result. It also abstracted out readinging from a tab >>separated file so it can be resused. >> >>While you might argue that i should have produced an iterator to be >>Java compatible, to do it in Java, you'd need an interface with >>methods call and apply, and each of the 4 loops would require at least >>50% more lines of code. >> >> >> >>------------------------------------------------------- >>This SF.Net email sponsored by Black Hat Briefings & Training. >>Attend Black Hat Briefings & Training, Las Vegas July 24-29 - >>digital self defense, top technical experts, no vendor pitches, >>unmatched networking opportunities. Visit www.blackhat.com >>_______________________________________________ >>Jscheme-user mailing list >>Jsc...@li... >>https://lists.sourceforge.net/lists/listinfo/jscheme-user |