From: Marco A. <ma...@cs...> - 2001-06-05 14:39:25
|
To: nic...@iw... CC: clo...@li... In-reply-to: <wsk...@or...> (message from Nicolas Neuss on 05 Jun 2001 15:42:01 +0200) Subject: Re: AMBLER, a modern, simplified "WALKER/Visitor" package. References: <200...@oc...> <wsk...@or...> --text follows this line-- > Cc: clo...@li... > From: Nicolas Neuss <nic...@iw...> > Sender: clo...@li... > X-BeenThere: clo...@li... > X-Mailman-Version: 2.0.5 > Precedence: bulk > List-Help: <mailto:clo...@li...?subject=help> > List-Post: <mailto:clo...@li...> > List-Subscribe: <http://lists.sourceforge.net/lists/listinfo/clocc-list>, > <mailto:clo...@li...?subject=subscribe> > List-Id: <clocc-list.lists.sourceforge.net> > List-Unsubscribe: <http://lists.sourceforge.net/lists/listinfo/clocc-list>, > <mailto:clo...@li...?subject=unsubscribe> > List-Archive: <http://lists.sourceforge.net/archives//clocc-list/> > Date: 05 Jun 2001 15:42:01 +0200 > Content-Length: 1595 > > Marco Antoniotti <ma...@cs...> writes: > > > Hi, > > > > I decided to put together the following little utility that can be > > used to "amble" through Lisp code while doing extra things in the > > meanwhile. > > > > I decided to write it, because most of the WALKER packages around are > > kinda oldish and I find them too tied to non-portable aspects of the > > underlying Common Lisp implementation. > > > > I'd like some comments about it. > > > > Please play around with it and let me know what you think. > > > > Of course, I hope to eventually put it into the CLOCC. > > > > Cheers > > > > Marco > > Hello, Marco. > > I've looked at your code hoping that the documentation would give me a > clue what an ambler is and how to use it. I have read: > > ;;; ambler.lisp -- > ;;; Simple code ambler. Purely syntactic and without `environment' > ;;; hacking. > ;;; This is essentially an instantiation of the "Visitor Pattern" > ;;; which, by means of CL multiple dispatching is readily implemented. > ;;; > ;;; This facility is inspied by the WALKER functionalities available > ;;; in many implementations. This facility does not implement all the > ;;; features (mostly non-portable) available in many WALKER > ;;; implementations, but at least it is (should be) very portable and > ;;; usable. > > Unfortunately, I have not yet used another Lisp than CMUCL, so that I > am somewhat lost in what your WALKER or AMBLER can do. Could you give > me a small example of usage? Suppose you want to define a nice macro which implements a new language extension. Or, suppose you want to define a new sublanguage altogether. E.g. you want a Estere\lambda (check out www.esterel.org). I.e you want to be able to write something like (defmodule abro ((a :signal :input) (b :signal :input) (r :signal :input) (o :signal :output)) (loop (par (await a) (await b)) (emit o) each r)) CL programs are already in AST form, but they may need further processing. E.g. you may need to figure out that the 'o' in the '(emit o)' expression has been already declared. To this end you can write a AMBLER for (or a "WALKER" form). Suppose you have defined a new ambler class (forget the packages for the time being). (defclass esterel-ambler-context (identity-ambling-context) ((environments () :accessor environments))) ; a stack of alists. Now you can write something like (def-form-ambler emit (emit-form esterel-ambler-context) (let* ((output-signal (second emit-form)) ((declared-signal (find-id output-signal (environments esterel-ambler-context)))) ) (unless declared-signal (error "Trying to emit an unknown signal ~S." output-signal)) )) And (def-form-ambler loop (loop-form esterel-ambler-context) (let ((termination (first (last (butlast loop-form))))) (when (eq termination 'each) ;; process EACH loop clause) (amble-expression (subseq loop-form 1 (when (eq termination 'each) (- (length loop-form) 2))) esterel-ambler-context))) I apologize for not having written a more through documentation of this little package with more examples. I just got frustrated with ahvng tons of code implementing what is essentially the "Visitor" pattern for S-exprs. Really, there is not much more to it. I just thought that packaging it would be of use to other people as well. Cheers -- Marco Antoniotti ======================================================== NYU Courant Bioinformatics Group tel. +1 - 212 - 998 3488 719 Broadway 12th Floor fax +1 - 212 - 995 4122 New York, NY 10003, USA http://bioinformatics.cat.nyu.edu "Hello New York! We'll do what we can!" Bill Murray in `Ghostbusters'. |