From: Ken A. <kan...@bb...> - 2003-06-21 22:27:06
|
Your group stuff sounds cool, you should share it with the JScheme group! Your example is great. I was worried that {[]} and other stuff in JScheme allowed you to mix languages as your example nicely shows, and that it might be hard for new users to read and write themselves. We have 2 unquoting mechanisms, quasi-string where you use [] to escape to lisp, and quasi-quote where you use , and ,@. Could they be unified somehow? Would that make the language better? At 05:48 PM 6/21/2003 -0400, Timothy John Hickey wrote: >On Saturday, June 21, 2003, at 01:32 PM, Ken Anderson wrote: > >>I think you're more willing to play with strange syntax than i am, probably your prolog background. >probably so! >> >>I do get confused sometimes when i have to go between Scheme and Java a lot, which is why i like to stay in Scheme. >In my CS2a summer school class we just covered a servlet that mixed four languages (html, css, scheme, and sql). >This is pretty common in servlet programming, but I really like the way it works in jscheme. >Here's the program. It implements a simple web interface for a CD database. > > >>(april-page ; april is one of the students, all students define a page format that others can use.... >> >> {<form method="post" action="cd.servlet"> >> <select name="cmd"> >> <option value="show"> show table</option> >> <option value="insert">insert entry</option> >> <option value="search"> search </option> >> <option value="sby"> sort by year</option> >> <option value="cba"> count by artist</option> >> </select><br/><br/> >> <input type="submit"> >> </form> >> >> [(servlet (cmd title artist year) >> (case cmd >> >> (("cba") (table "" (dbquery ;; dbquery is a procedure which sends the SQL over a predefined JDBC connection > > ;; and returns a list of lists; one sublist per record. >> {select artist,count(*) from timscds >> group by artist order by artist asc} >> ))) >> >> (("sby") (table "" (dbquery >> {select * from timscds order by year asc}))) >> >> (("show") (table "" (dbquery {select * from timscds}))) >> >> (("search") {not yet implemented....}) >> >> (("insert") >> {Fill out this form: >> <form method="post" action="cd.servlet"> >> title:<input type="text" name= "title"><br/> >> artist:<input type="text" name="artist"><br/> >> year:<input type="text" name= "year"><br/> >> <input type="submit"> >> <input type="hidden" name="cmd" value="do-insert"> >> </form>}) >> >> (("do-insert") >> (dbquery {insert into timscds >> values("[title]","[artist]",[year])}) >> {[title] was inserted } >> ) ;close do-insert >> >> (else "Life is good!") >> >> ) ;close case >> ) ;close servlet >> ]} >>) ; close april-page > > >> >>Since we have complete control over evaluation i was thinking we could play with some ARC ideas. For example (h .put 'Tim 3) or ((vector 1 2 3) 1) >I like the PLT idea of allowing modules to be written in new "languages" >They define languages in terms of macros, but we could be more general.... > >> >>The group stuff sounds great! >Its fun. I'm writing some short papers on it and I'll send you a copy when they're complete. > >---Tim--- > > >>At 08:51 AM 6/21/2003 -0400, Timothy John Hickey wrote: >> >>>On Saturday, June 21, 2003, at 01:54 AM, Geoffrey Knauth wrote: >>> >>>>(From LL1.) This made me think of the JScheme convention of (message object args...). >>>As in >>> (.append ta (.getText ta2)) >>>Hmmmm. This would rewrite as (ta .append (ta2 .getText)) .... cool. >>> >>>Peter Norvig once told me that he had provided a syntactic variant of >>>Lisp for his non-lisper colleagues in which >>>he replaced (f a b ... z) with f( a, b, ... , z) to go from Lisp to Fn notation and >>>f(a, b, ... z) --> (f a b ... z) (i.e. move the function in the arg list and ignore the commas! >>> >>>This seemed to be a very easy operation that appealed to many non-lispers. >>>So we would get >>> ,append(ta, .getText(ta2)) >>>or >>>define(sq(x),*(x,x)) >>>I'm didn't ask how he handled other syntax, such as let, case, etc..... >>> >>>---Tim--- >>> >>>P.S. Sorry I haven't been very responsive lately. I'm teaching two summmer school >>>courses that each meet 2.5 hours/day, 3 days a week. >>> >>>I've continued to "use" Jscheme pretty heavily and have built a java.nio-based networking library >>> groupscheme/kernel/NioGroupTools.scm in the groupscheme.sourceforge.net >>>which works very nicely. It maintains a single thread for handling all socket I/O using non-blocking >>>selects. >>> >>> >>>You create a server using >>> (make-group-server PORT) >>>and a client using >>> (define c (make-group-client YOURNAME YOURGROUP SERVER-IP SERVER-PORT)) >>> >>>clients can send a list of s-expressions to all members of their group using >>> (c 'send A B ... Z) (which writes the message M= (A B ... Z) to the server's socket. >>>They can add listeners to the socket using >>> (c 'add-super-listener (lambda M ..do something with M...)) >>>or >>> (c 'add-listener 'A (lambda (A B ... Z) do something with the message M provided (car M)=A)) >>>The message can only contain elements for which reading/writing is the identity. >>> >>>Anyway, the cool thing is that the use of java.nio allows us to have many many >>>simultaneous servers and clients with only one thread. >>> >>>> >>>>Begin forwarded message ("Anton van Straaten" <an...@ap...>, ): >>>> >>>>>(module reverse-apply mzscheme >>>>> >>>>> ; define a "backwards" application operation >>>>> (define-syntax reverse-apply >>>>> (syntax-rules () >>>>> [(_ fn) (fn)] ;support zero-arg calls >>>>> [(_ obj fn arg ...) (fn obj arg ...)])) >>>>> >>>>> ; allow this module to be used as a "language" (see below) >>>>> (provide (all-from-except mzscheme #%app) >>>>> ; provide reverse-apply, replacing default #%app >>>>> (rename reverse-apply #%app))) >>>>> >>>>>Save the above in a file called "reverse-apply.scm". To use this >>>>>interactively, at the Scheme prompt you can execute: >>>>> >>>>> (require "reverse-apply.scm") >>>>> >>>>>Now you can do the following: >>>>> >>>>> (1 + 2) ;==> 3 >>>>> ('a cons 'b) ;==> (a . b) >>>>> ('(a b) car) ;==> a >>>>> ('(a b) cdr) ;==> (b) >>>>> >>>>> ; some dummy definitions - note reversed syntax >>>>> (define (filter x y) ("[filtering " string-append x y "] ")) >>>>> (define (merge x y) ("[merging " string-append x y "] ")) >>>>> (define (sort x) ("[sorting " string-append x "] ")) |