Xref: utzoo comp.lang.scheme:876 comp.lang.lisp:2285 comp.text:5316 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!ukc!icdoc!sot-ecs!sra From: sra@ecs.soton.ac.uk (Stephen Adams) Newsgroups: comp.lang.scheme,comp.lang.lisp,comp.text Subject: Re: Looking for "literate programming" tools for Scheme/LISP Message-ID: Date: 22 Oct 89 19:58:35 GMT References: <1989Oct16.153232.19051@mentor.com> Sender: sra@ecs.soton.ac.uk Organization: Southampton University Computer Science Lines: 122 In-reply-to: plogan@mentor.com's message of 16 Oct 89 15:32:32 GMT In article <1989Oct16.153232.19051@mentor.com> plogan@mentor.com (Patrick Logan) writes: (1) Does someone have WEB or equivalent set up for Scheme or another LISP? (2) Do you know of any references to "literate programming" applied to Scheme/LISP? I have a solution for Common lisp. The same idea should work for most lisps. I use the following code to read in latex files that have bits of lisp code embedded in `lisp' or `program' environments. It works by redefining the readtable so that 1. Latex comments are treated as comments in lisp .to treat latex comment as lisp comments. 2. Anything starting with a `\' is a comment until the start of a `lisp' or `program' environment. It has been used under Sun Common Lisp (Lucid) and Kyoto Common Lisp. I think that a full-blown WEB equivalent for lisp is a waste of time. Much of what WEB offers is there to circumvent weaknesses in the host language. Many lisp programs are declaration order independent (or should be if you want to compile them). If you want to refine something later functions and macros can be used. Cheers ---- cut here, put it in latex.lisp ----- ; ; Literate programming for common lisp and latex ; ; Only those bits of program in a `lisp' or `program' environment ; are loaded. This is achieved as follows: ; ; 1. `%' (the tex comment character) is make to act exactly like lisp's ; semicolon ; 2. `\' is make to skip text until a line containing only ; \begin{lisp} ; or \begin{program} ; The skipped text including the \begin bit is treated as a comment. ; 3. Devious code make the character dispatch read macro (#\... ) ; still work. I hope. ; ; ; Re-building this file: ; On both lucid and kcl there are problems with overwriting the readtable ; while loading. It only seems to work properly if the functions are ; compiled and the readtable is updated in one operation. But that is ; a one-legged-chicken theory. ; ; To compile: ; Start lucid or KCL. (if you are already in lisp, exit & restart it) ; (compile-file "latex.lsp") ; either (bye) [in kcl] or (quit) [in lucid] ; Dont be tempted to load latex.{o,lbin} after compiling. It doesnt work. ; ; At any other time it is reasonable to load the compiled stuff. ; (eval-when (compile) (proclaim '(optimize (safety 2)))) (defvar *default-hash-backslash-function* (get-dispatch-macro-character #\# #\\)) (defun install-latex-readtable () (labels ( (backslash-mystifier (stream ch &aux line) (unread-char ch stream) (setf line (read-line stream nil nil t)) (loop ;;;; (format t "---> ~S~%" line) (if (equal (peek-char nil stream nil 'T) 'T) (return (values))) (setf line (read-line stream nil nil t)) (if (or (null line) (string-equal line "\\begin{lisp}") (string-equal line "\\begin{program}") ) (return (values))) ) ) (grotty-new-character-reader (stream ch prefix &aux name (result nil)) (unwind-protect (progn (set-syntax-from-char #\\ #\\) (set-dispatch-macro-character #\# #\\ *default-hash-backslash-function*) (unread-char ch stream) (setf name (read stream nil nil nil)) (setf prefix (if prefix (format nil "~D" prefix) "")) (setf result (read-from-string (format nil "#~A\\~A" prefix name))) ) (progn (set-macro-character #\\ #'backslash-mystifier nil) (set-dispatch-macro-character #\# #\\ #'grotty-new-character-reader) result)) )) (let ((newtable (copy-readtable nil))) (set-syntax-from-char #\% #\; newtable newtable) (set-macro-character #\\ #'backslash-mystifier nil newtable) (set-dispatch-macro-character #\# #\\ #'grotty-new-character-reader newtable) (setf *readtable* newtable) ))) (eval-when (load) (install-latex-readtable)) -- Stephen Adams S.Adams@uk.ac.soton.ecs (JANET) Computer Science S.Adams@ecs.soton.ac.uk (Bitnet) Southampton S09 5NH, UK S.Adams@sot-ecs.uucp (uucp)