├── README.md ├── latex ├── Makefile ├── acknowledgments.tex ├── automata.tex ├── build ├── conclusion.tex ├── fancyvrb1.sty ├── interpreters.tex ├── introduction.tex ├── language.tex ├── preface.tex ├── quotes.txt ├── scmxlate │ ├── COPYING │ ├── INSTALL │ ├── README │ ├── clmacros.cl │ ├── clnames.cl │ ├── clprocs.cl │ ├── history │ ├── index.tex │ ├── makefile │ ├── manifest │ ├── mbe-procs.cl │ ├── sample.configure │ ├── scm2cl.cl │ ├── scm2cl.tex │ ├── scmxlate-version.tex │ ├── scmxlate.cl │ └── scmxlate.scm ├── slatex │ ├── COPYING │ ├── INSTALL │ ├── README │ ├── callsla.scm │ ├── cltl.sty │ ├── defun.tex │ ├── dialects │ │ ├── bigloo-slatex-src.scm │ │ ├── chez-slatex-src.scm │ │ ├── cl-slatex-src.scm │ │ ├── dialects-supported.scm │ │ ├── files-to-be-ported.scm │ │ ├── gambit-slatex-src.scm │ │ ├── guile-slatex-src.scm │ │ ├── make-callsla.scm │ │ ├── make-echo-script.scm │ │ ├── make-qualified-names.scm │ │ ├── mitscheme-slatex-src.scm │ │ ├── mzscheme-slatex-src.scm │ │ ├── operating-systems-supported.scm │ │ ├── other-slatex-src.scm │ │ ├── petite-slatex-src.scm │ │ ├── plt-slatex-src.scm │ │ ├── scm-slatex-src.scm │ │ ├── scsh-slatex-src.scm │ │ ├── sxm-slatex-src.scm │ │ └── umbscheme-slatex-src.scm │ ├── history │ ├── makefile │ ├── manifest │ ├── scmxlate-slatex-src.scm │ ├── slatex │ ├── slatex-src.scm │ ├── slatex.scm │ ├── slatex.sty │ ├── slatxdoc.bib │ ├── slatxdoc.t2p │ ├── slatxdoc.tex │ ├── tex2page.tex │ └── version.tex ├── title.tex ├── tufte-book.cls ├── tufte-common.def ├── urib-prelude.tex ├── urib.bib ├── urib.pdf ├── urib.tex └── xeslatex ├── old-outlines ├── most-recent-old-outline.org ├── most-recent-outline.txt ├── old-outline-small.org └── outline-big.org └── old-src ├── interp.scm ├── matche.scm ├── mk.scm ├── pmatch.scm ├── scope.scm └── test-check.scm /README.md: -------------------------------------------------------------------------------- 1 | Untitled Relational Interpreter Book 2 | ==================================== 3 | 4 | by 5 | 6 | William E. Byrd 7 | 8 | 9 | ------------------------------------------------------------------- 10 | 11 | Update (June 23rd, 02015): 12 | 13 | New working title: 14 | 15 | 'Playing with Executable Semantics in miniKanren' 16 | 17 | My current thinking is to show how to encode a number of formal 18 | systems in miniKanren, ideally directly from the semantics. This 19 | would include interpreters for both a Scheme-like language and the 20 | 'While' imperative language, along with other formal systems and 21 | languages. 22 | 23 | I'm therefore working on yet another new outline (`outline.txt`). 24 | 25 | ------------------------------------------------------------------- 26 | 27 | Update (June 14th, 02015): 28 | 29 | I've changed the name of the book/repository too many times, so I'll 30 | just call the repo 'untitled-relational-interpreter-book' for now. 31 | 32 | The working title of the book is: 33 | 34 | 'Playing with Relational Interpreters' 35 | 36 | I hope I can capture the sense of play and excitement 37 | I get from playing with the relational interpreter. 38 | 39 | My current plan is to write a *thin*, very focused book on relational 40 | interpreters, with all non-awesomeness removed. I want the book to be 41 | readable by as general an audience as possible. Narrow focus, wide 42 | audience. 43 | 44 | I'm working on a new outline (`outline.txt`). I've moved the old 45 | outlines to the `old-outlines` directory. 46 | 47 | I've been moderating/hosting a series of weekly miniKanren "uncourse" 48 | Hangouts 49 | (https://www.youtube.com/playlist?list=PLO4TbomOdn2cks2n5PvifialL8kQwt0aW). 50 | These hangouts have been extremely helpful for helping me understand 51 | how to teach relational interpreters. Many thanks to everyone who has 52 | participated! 53 | 54 | Special thanks to: Celeste Hollenbeck for pushing me to keep working 55 | on this book; Michael Ballantyne for close collaboration on miniKanren 56 | and relational interpreters; Matt Might, who has made this 57 | collaboration possible; Michael Adams, for collaboration on tree 58 | automata for miniKanren, and countless helpful conversations; Celeste 59 | Hollenbeck and Maria Jenkins for helping figure out how to teach a 60 | minimal introduction to Scheme; Tom Gilray for explorations in 0-CFA 61 | in miniKanren; and all my other colleagues in the U Combinator lab and 62 | at University of Utah for creating an intellectually stimulating 63 | environment. 64 | 65 | Special thanks to David Nolen for porting my dissertation to Clojure. 66 | I doubt I would have had the courage to continue working on miniKanren 67 | otherwise. 68 | 69 | Special thanks to Stu Halloway for his quines observation, which has 70 | driven my research (and my sleep patterns) for the past three years. 71 | Thanks also to Stu and Joey for their amazing hospitality. 72 | 73 | Special thanks to Rich Hickey, Lynn Grogan, Alex Miller, Nada Amin, 74 | Bodil Stokke, Fogus, David Nolen, Stu Halloway, and the rest of the 75 | Clojure community for being so welcoming. 76 | 77 | Special thanks to Andy Lumsdaine and Rebecca Schmidt for their 78 | tremendous support -- and their friendship -- while I was at the 79 | Center for Research in Extreme Scale Technologies (CREST). And thanks 80 | to all the other CREST researchers and employees, whom I'll not try to 81 | name here for fear of leaving someone out. I'll save it for the book. 82 | 83 | Special thanks to Alan Sherman at UMBC for his support and mentorship 84 | over the years. 85 | 86 | And, of course, thanks to the usual suspects -- all the people who 87 | have developed and improved miniKanren and its variants and ports. 88 | Special thanks to my 'Reasoned Schemer' co-authors Dan Friedman and 89 | Oleg Kiselyov. I'm not going to try to name anyone else, since I know 90 | I'll accidentally leave people out. I'll try to thank everyone 91 | properly in the book. I fear this is already an impossible task. 92 | 93 | Special thanks to my H211/C211/C311 students, and to my teaching 94 | assistants: Lindsey Kuper, Michael Adams, and Abdulaziz Ghuloum. 95 | 96 | Finally, a very special thanks to my family for your love and support. 97 | 98 | ------------------------------------------------------------------- 99 | 100 | Old, hilariously optimistic update: 101 | 102 | I'm currently (as of July 4th, 2014) working on a detailed outline for 103 | the book: 104 | 105 | https://github.com/webyrd/relational-programming-in-miniKanren/blob/master/outline.org 106 | 107 | I'll begin writing prose in earnest once the outline is complete. I 108 | expect to be finished with the outline by mid-August, 2014. 109 | 110 | Before writing prose, I might first use the outline as a basis for a 111 | Google-Hangout based mini-course on relational programming. This 112 | mini-course would help me flesh out examples, help me understand where 113 | people get confused, and help ensure the structure and order of 114 | presentation makes sense. Anyone interested in such a course can 115 | email me at `webyrd@gmail.com`. 116 | 117 | Cheers, 118 | 119 | --Will 120 | 121 | ------------------------------------------------------------------- 122 | 123 | 124 | This work is licensed under a Creative Commons Attribution 4.0 International License. 125 | (CC BY 4.0) (http://creativecommons.org/licenses/by/4.0/) 126 | 127 | 128 | The PDF file for the book is at: 129 | 130 | `latex/urib.pdf` 131 | 132 | 133 | Build instructions (somewhat out of date, but should still work; as of 14 June 02015 I'm using a new laptop with Mac OS 10.10.3 and a later TeX distro): 134 | 135 | I build the book under Mac OS 10.8 using the MacTeX-2012 Distribution of TeX Live. (http://tug.org/mactex/) For some bizarre reason, you need to be careful when downloading the `MacTeX.pkg` file, or it will be corrupted; one safe way to download the file is to use Safari. I'm typesetting the book using XeLaTeX, which should be included in any modern TeX distribution. 136 | 137 | I'm using SLaTeX (http://www.ccs.neu.edu/home/dorai/slatex/) to typeset Scheme and miniKanren code. I've included SLaTeX in the Github repo, but SLaTeX expects a Scheme implementation in order to work. I'm using the 32-bit nonthreaded version of Petite Chez Scheme 8.4 (http://www.scheme.com/download/). If you use another Scheme implementation, you'll have to update the `xeslatex` file in the main directory, replacing `petite` with your Scheme implementation of choice. Of course you will need to make sure your Scheme implementation is on your `PATH`. 138 | 139 | Once you have installed your TeX distribution and a Scheme implementation, you should be ready to typeset the book: 140 | 141 | `cd latex` 142 | 143 | `make squeaky; make` 144 | 145 | `make squeaky` removes all generated files, including the PDF of the book. `make clean` removes temporary files, but not the book PDF. 146 | -------------------------------------------------------------------------------- /latex/Makefile: -------------------------------------------------------------------------------- 1 | BOOK=urib 2 | 3 | all: 4 | ./build 5 | 6 | clean: 7 | rm -f .Z* 8 | rm -f .q* 9 | rm -f .old* 10 | rm -f *.aux 11 | rm -f *.log 12 | rm -f *.toc 13 | rm -f ${BOOK}.out 14 | rm -f ${BOOK}.bbl 15 | rm -f ${BOOK}.blg 16 | rm -f *.idx 17 | 18 | squeaky: 19 | make clean 20 | rm -f ${BOOK}.pdf 21 | rm -f ${BOOK}.dvi 22 | rm -f *~ 23 | -------------------------------------------------------------------------------- /latex/acknowledgments.tex: -------------------------------------------------------------------------------- 1 | \chapter*{Acknowledgments} 2 | 3 | % probably should include in preface, instead of as a separate section 4 | -------------------------------------------------------------------------------- /latex/automata.tex: -------------------------------------------------------------------------------- 1 | \chapter{Finite Automata} 2 | 3 | %% \vspace{-1.5cm} 4 | %% \begin{fullwidth} 5 | %% \begin{flushright} 6 | %% \Large 7 | %% \textit{gl hf!} 8 | 9 | %% \wspace 10 | 11 | %% ---Greg ``IdrA'' Fields 12 | %% %(Traditional greeting in the Koprulu Sector) 13 | %% \normalsize 14 | %% \end{flushright} 15 | %% \end{fullwidth} 16 | 17 | -------------------------------------------------------------------------------- /latex/build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BOOK=urib 4 | 5 | PATH=./slatex:$PATH 6 | export PATH 7 | 8 | TEXINPUTS=./:$TEXINPUTS 9 | TEXINPUTS=./scmxlate:$TEXINPUTS 10 | TEXINPUTS=./slatex:$TEXINPUTS 11 | export TEXINPUTS 12 | 13 | rm -f .qq* 14 | rm -f .old* 15 | rm -f .Z* 16 | bibtex $BOOK 17 | ./xeslatex $BOOK.tex 18 | bibtex $BOOK 19 | ./xeslatex $BOOK.tex 20 | bibtex $BOOK 21 | ./xeslatex $BOOK.tex 22 | bibtex $BOOK 23 | makeindex -c -s $BOOK.ist $BOOK 24 | printf "\a" 25 | -------------------------------------------------------------------------------- /latex/conclusion.tex: -------------------------------------------------------------------------------- 1 | \chapter{Conclusion} 2 | 3 | %\openepigraph{G.G.}{Sean ``Day[9]'' Plott} 4 | 5 | \vspace{-1.5cm} 6 | \begin{fullwidth} 7 | \begin{flushright} 8 | \Large 9 | \textit{G.G.} 10 | 11 | \wspace 12 | 13 | ---Sean ``Day[9]'' Plott 14 | \normalsize 15 | \end{flushright} 16 | \end{fullwidth} 17 | -------------------------------------------------------------------------------- /latex/fancyvrb1.sty: -------------------------------------------------------------------------------- 1 | \NeedsTeXFormat{LaTeX2e} 2 | \ProvidesPackage{fancyvrb1}[2007/03/17 Improved fancyvrb by ccshan] 3 | \RequirePackage{fancyvrb} 4 | 5 | \DeclareOption{compact}{% 6 | \let\saveFV@ListProcessLine@i \FV@ListProcessLine@i 7 | \let\saveFV@ListProcessLine@ii \FV@ListProcessLine@ii 8 | \let\saveFV@ListProcessLine@iii \FV@ListProcessLine@iii 9 | \let\saveFV@ListProcessLine@iv \FV@ListProcessLine@iv 10 | \let\saveFV@BProcessLine \FV@BProcessLine 11 | \def\FV@ListProcessLine@i {\let\saveFV@Compact\saveFV@ListProcessLine@i 12 | \afterassignment\FV@Compact\toks@}% 13 | \def\FV@ListProcessLine@ii {\let\saveFV@Compact\saveFV@ListProcessLine@ii 14 | \afterassignment\FV@ListCompact\toks@}% 15 | \def\FV@ListProcessLine@iii {\let\saveFV@Compact\saveFV@ListProcessLine@iii 16 | \afterassignment\FV@ListCompact\toks@}% 17 | \def\FV@ListProcessLine@iv {\let\saveFV@Compact\saveFV@ListProcessLine@iv 18 | \afterassignment\FV@ListCompact\toks@}% 19 | \def\FV@BProcessLine {\let\saveFV@Compact\saveFV@BProcessLine 20 | \afterassignment\FV@Compact\toks@}% 21 | } 22 | \ProcessOptions 23 | 24 | \def\FV@compactskip{\penalty-200 \medskip} 25 | \def\FV@Compact{\edef\next{\the\toks@}% 26 | \ifx\next\empty 27 | \FV@compactskip 28 | \else 29 | \expandafter\saveFV@Compact\expandafter{\the\toks@}% 30 | \fi}% 31 | \def\FV@ListCompact{\edef\next{\the\toks@}% 32 | \ifx\next\empty 33 | \FV@ListProcessLastLine 34 | \FV@compactskip 35 | \let\FV@ProcessLine\FV@ListProcessLine@i 36 | \else 37 | \expandafter\saveFV@Compact\expandafter{\the\toks@}% 38 | \fi}% 39 | -------------------------------------------------------------------------------- /latex/interpreters.tex: -------------------------------------------------------------------------------- 1 | \chapter{Relational Interpreters} 2 | 3 | \vspace{-1.5cm} 4 | \begin{fullwidth} 5 | \begin{flushright} 6 | \Large 7 | \textit{We will never run out of things to program as long as there is a single program around.} 8 | 9 | \wspace 10 | 11 | ---Alan J. Perlis 12 | 13 | \noindent 14 | Epigrams on Programming, \#100\nocite{Perlis:1982:SFE:947955.1083808} 15 | \normalsize 16 | \end{flushright} 17 | \end{fullwidth} 18 | -------------------------------------------------------------------------------- /latex/introduction.tex: -------------------------------------------------------------------------------- 1 | \chapter{Introduction} 2 | 3 | %\openepigraph{gl hf!}{Greg ``IdrA'' Fields} 4 | 5 | \vspace{-1.5cm} 6 | \begin{fullwidth} 7 | \begin{flushright} 8 | \Large 9 | \textit{gl hf!} 10 | 11 | \wspace 12 | 13 | ---Greg ``IdrA'' Fields 14 | %(Traditional greeting in the Koprulu Sector) 15 | \normalsize 16 | \end{flushright} 17 | \end{fullwidth} 18 | 19 | Relational programs generalize functional programs, in that they do 20 | not distinguish between the ``input'' arguments passed to a function 21 | and the ``output'' result returned by that function. 22 | % 23 | For example, consider a two-argument variant of Scheme's addition function, restricted to natural\marginnote{The \emph{natural numbers} are the non-negative integers: 0, 1, $\ldots$} numbers: \mbox{\scheme|(+ 3 4) => 7|}. 24 | % 25 | A relational version of addition, \scheme|+o|, takes three arguments:\marginnote{Here we are taking a notational liberty, as \scheme|+o| expects 3 and 4 to be represented as \emph{binary}, \emph{little-endian} lists: \mbox{\scheme|(1 1)|} and \mbox{\scheme|(0 0 1)|}, respectively. Zero is uniquely represented as the empty list, \scheme|()|. To ensure a unique representation of each number, lists may not end with the digit \schemeresult|0|. This numeric representation is extremely flexible, since the lists can contain logic variables---for example, the list \mbox{\scheme|`(1 . ,x)|} represents any odd natural number, while \mbox{\scheme|`(0 . ,x)|} represents any positive even natural. \\ We can also perform relational arithmetic on built-in Scheme numbers, using \emph{Constraint Logic Programming over Finite Domains}, or \emph{CLP(FD)}; as we will see, CLP(FD) is faster, but less general, than \scheme|+o| and friends (\scheme|*o|, \scheme|/o|, etc.).} \mbox{\scheme|(+o 3 4 z)|}, 26 | where \scheme|z| is a \emph{logic variable} representing the result 27 | of adding the first two arguments of \scheme|+o|. In this case 28 | \scheme|z| is associated with \schemeresult|7|. 29 | % 30 | More interestingly, we can write \mbox{\scheme|(+o 3 y 7)|}, which 31 | associates \scheme|y| with \schemeresult|4|; our addition relation 32 | also performs subtraction. 33 | % 34 | We can also write \mbox{\scheme|(+o x y 7)|}, which associates 35 | \scheme|x| and \scheme|y| with all pairs of natural numbers that sum 36 | to \schemeresult|7|; \scheme|+o| produces multiple 37 | answers, including \mbox{\scheme|x = 3|} and \mbox{\scheme|y = 4|}, and 38 | \mbox{\scheme|x = 0|} and \mbox{\scheme|y = 7|}. 39 | % 40 | Finally, we can write \mbox{\scheme|(+o x y z)|}, which enumerates 41 | all triples of natural numbers $(x, y, z)$ such that $x + y = z$; 42 | \scheme|+o| produces infinitely many answers. 43 | % 44 | Informally, we say that the call \mbox{\scheme|(+o 3 4 z)|} runs the \scheme|+o| relation ``forwards,'' 45 | %(that is, in the same direction as the corresponding Scheme function), 46 | while the calls \mbox{\scheme|(+o 3 y 7)|}, \mbox{\scheme|(+o x y 7)|}, and \mbox{\scheme|(+o x y z)|} run ``backwards.'' 47 | %Informally, we say that the \scheme|+o| relation can ``run backwards,'' in 48 | %contrast to Scheme's \scheme|+| function, which only can be used in the 49 | %``forwards'' direction. 50 | 51 | We will see that the remarkable flexibility of the \scheme|+o| 52 | relation is exhibited by more complex relations, such as interpreters, 53 | type inferencers, and finite-state machines. 54 | % 55 | For example, we will write a relational interpreter for a subset 56 | of Scheme, \scheme|evalo|. Running \scheme|evalo| forwards, the call\marginnote{As might be expected, \scheme|evalo| will interpret the quoted list \mbox{\schemeresult|(+ x 2)|} as the call \mbox{\scheme|(+o x 2 val)|}, where the logic variable \scheme|x| is associated with \schemeresult|4|.} 57 | \mbox{\scheme|(evalo '((lambda (x) (+ x 2)) 4) val)|} associates 58 | \scheme|val| with \schemeresult|6|. Running 59 | backwards is more interesting: \mbox{\scheme|(evalo exp '6)|} generates legal 60 | Scheme expressions that \emph{evaluate} to 6, while 61 | \mbox{\scheme|(evalo exp exp)|} generates \emph{quines}, which are Scheme expressions that evaluate to themselves. 62 | 63 | %\marginnote{Douglas Hofstadter coined the term \emph{quine}, in honor of logician Willard Van Orman Quine (1908--2000). Writing quines has long been a favorite hacker activity, and quines are often featured in the The International Obfuscated C Code Contest (\url{http://www.ioccc.org/}). A delightful introduction to quines can be found in Doug's classic, \emph{GEB}: \cite{GEB79}} 64 | 65 | %This book will teach you how to write relations that produce 66 | %interesting answers when running forwards and backwards. 67 | % 68 | %Running a relation in the forward direction is usually straight-forward. 69 | % 70 | %Running a relation backwards is where the fun begins.\marginnote{All 71 | %too often this fun never ends, as the relation diverges (loops forever)!} 72 | % 73 | %I hope you'll enjoy the neverending fun of relational programming as 74 | %much as I have. 75 | 76 | 77 | 78 | %%% I need to decide who my intended audience is, and always keep them 79 | %%% in mind. I need to be especially careful about referring to 80 | %%% things PL folks and CS PhDs take for granted. In the margin notes 81 | %%% I can geek out all I want. 82 | 83 | 84 | %%% Do I believe this? Yes. However, unless the reader knows what logic programming is, this claim won't mean much. 85 | 86 | % Logic programming has failed. 87 | 88 | % More specifically, logic programming, as currently practiced, has failed to live up to its promise as the ultimate in declarative programming. 89 | 90 | 91 | 92 | %%% I guess this paragraph is okay, as far as it goes. But once 93 | %%% again, mind my audience. Also, concentrate on ideas over specific 94 | %%% languages or implementations whenever possible. Want the book to 95 | %%% be useful and interesting even for readers who have no interest in 96 | %%% ever using miniKanren. 97 | 98 | % This book describes the miniKanren programming language\marginnote{miniKanren is actually a family of related programming languages, embedded in a variety of host languages. Unless otherwise specifified, we use the term ``miniKanren'' to refer to the entire family of languages, including {\tt core.logic}, cKanren, and any other variants.}, and how to use miniKanren to write programs in a {\em relational} style. Just as functional programming is based on the notion of mathematical functions, relational programming is based on the notion of mathematical relations. For this reason, relational programs are in some ways similar to relational databases.\marginnote{Indeed, SQL is arguably the most successful relational (and declarative) programming language. As we will see, miniKanren is more expressive than SQL, although this increased expressivity has disadvantages.} Relational programming goes beyond relatioal databases, however, and can be seen as an especially pure variant of logic programming. Although both views of relational programming are valid and useful, we shall concentrate on an alternate, complementary view of relational programming, based on the transformation of functions in a functional programming language to relations in miniKanren. 99 | 100 | 101 | 102 | % the promise of declarative programming 103 | 104 | % advantages of relational programming 105 | 106 | % limitations of relational programming 107 | 108 | % using miniKanren for non-relational programming 109 | -------------------------------------------------------------------------------- /latex/language.tex: -------------------------------------------------------------------------------- 1 | \chapter{The miniKanren Language} 2 | 3 | %% \vspace{-1.5cm} 4 | %% \begin{fullwidth} 5 | %% \begin{flushright} 6 | %% \Large 7 | %% \textit{gl hf!} 8 | 9 | %% \wspace 10 | 11 | %% ---Greg ``IdrA'' Fields 12 | %% %(Traditional greeting in the Koprulu Sector) 13 | %% \normalsize 14 | %% \end{flushright} 15 | %% \end{fullwidth} 16 | 17 | -------------------------------------------------------------------------------- /latex/quotes.txt: -------------------------------------------------------------------------------- 1 | for a chapter on extending miniKanren, or maybe on cKanren 2 | 3 | We make expand, then defense it. 4 | White Ra 5 | 6 | -------------------------------------------------------------------------------- /latex/scmxlate/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 1997-2003, Dorai Sitaram. 2 | All rights reserved. 3 | 4 | Permission to distribute and use this work for any 5 | purpose is hereby granted provided this copyright 6 | notice is included in the copy. This work is provided 7 | as is, with no warranty of any kind. 8 | -------------------------------------------------------------------------------- /latex/scmxlate/INSTALL: -------------------------------------------------------------------------------- 1 | scmxlate 2 | INSTALL 3 | (c) Dorai Sitaram 4 | 5 | - 6 | 7 | Download the scmxlate distribution from 8 | http://www.ccs.neu.edu/~dorai/scmxlate/scmxlate.html 9 | (the download link immediately follows the title). 10 | 11 | scmxlate is supplied as a gzipped, tar file 12 | scmxlate.tar.gz. Unpack it in a directory of your 13 | choice, producing a subdirectory scmxlate . 14 | 15 | Make a note of the full pathname of the file 16 | scmxlate.scm in that directory. 17 | -------------------------------------------------------------------------------- /latex/scmxlate/README: -------------------------------------------------------------------------------- 1 | README 2 | scmxlate 3 | (c) Dorai Sitaram 4 | 5 | scmxlate is a tool for configuring Scheme packages to run 6 | on the dialect of Scheme or Common Lisp on your system. 7 | 8 | scmxlate is available at 9 | http://www.ccs.neu.edu/~dorai/scmxlate/scmxlate.html. 10 | 11 | The file INSTALL contains instructions on how to install 12 | scmxlate. 13 | -------------------------------------------------------------------------------- /latex/scmxlate/clmacros.cl: -------------------------------------------------------------------------------- 1 | ;translator macros 2 | 3 | ;last change 2009-03-31 4 | 5 | (defvar *scm2cl-macros* (make-hash-table)) 6 | 7 | (defvar *scm2cl-gentemp-prefix* "Scheme-to-CL-") 8 | 9 | (defmacro defmacro-scm2cl (name args &rest body) 10 | `(setf (gethash ',name *scm2cl-macros*) 11 | #'(lambda ,args ,@body))) 12 | 13 | (defmacro-scm2cl scm2cl-lambda (args &rest body) 14 | `(function 15 | (lambda ,(scm2cl-dot-to-rest args) ,@body))) 16 | 17 | (defmacro-scm2cl scm2cl-functionless-lambda (args &rest body) 18 | `(lambda ,(scm2cl-dot-to-rest args) ,@body)) 19 | 20 | (defun scm2cl-dot-to-rest (vv) 21 | (if (null vv) nil 22 | (if (symbolp vv) `(&rest ,vv) 23 | (let* ((l (last vv)) 24 | (d (cdr l))) 25 | (unless (null d) 26 | (setf (cdr l) `(&rest ,d))) 27 | vv)))) 28 | 29 | (defmacro-scm2cl 30 | define (x &rest ee) 31 | (let (new-alias-cell (e (car ee))) 32 | (cond ((and (consp x) (eq (car x) 'function)) 33 | (setq x (cadr x))) 34 | ;remaining clauses add definee to 35 | ;*aliases* 36 | ((consp x) 37 | (let ((f (car x))) 38 | (setq new-alias-cell (cons f `(function ,f))) 39 | (push new-alias-cell *aliases*))) 40 | ((and (consp e) (eq (car e) 'scm2cl-lambda)) 41 | (setq new-alias-cell (cons x `(function ,x))) 42 | (push new-alias-cell *aliases*)) 43 | ((and (consp e) (= (length e) 3) 44 | (eq (car e) 'scm2cl-let) (eq (car (caddr e)) 'scm2cl-lambda)) 45 | (setq new-alias-cell (cons x `(function ,x))) 46 | (push new-alias-cell *aliases*))) 47 | ; 48 | (if (and (symbolp x) (cdr ee)) 49 | (error "bad define: ~s" (cons 'define (cons x ee)))) 50 | ; 51 | ;follg to allow self-recursion 52 | (when new-alias-cell 53 | (setq ee 54 | (nsublis (list new-alias-cell) ee)) 55 | (setq e (car ee))) 56 | ; 57 | (cond ((and (symbolp x) (consp e) (eq (car e) 'scm2cl-lambda)) 58 | `(defun ,x ,(scm2cl-dot-to-rest (cadr e)) ,@(cddr e))) 59 | ((and (symbolp x) (consp e) (= (length e) 3) 60 | (eq (car e) 'scm2cl-let) 61 | (eq (car (caddr e)) 'scm2cl-lambda)) 62 | `(scm2cl-let ,(cadr e) 63 | (define ,x ,(caddr e)))) 64 | ((consp x) 65 | `(defun ,(car x) ,(scm2cl-dot-to-rest (cdr x)) ,@ee)) 66 | (t `(defparameter ,x ,e))))) 67 | 68 | (defmacro-scm2cl scm2cl-let (n &rest ee) 69 | (if (and n (symbolp n)) 70 | (let ((tail-recursive-p (search "LOOP" (symbol-name n)))) 71 | `(,(if (and tail-recursive-p (= tail-recursive-p 0)) 72 | 'scm2cl-named-let-tr 73 | 'scm2cl-named-let-non-tr) ,n ,@ee)) 74 | `(let ,n ,@ee))) 75 | 76 | (defmacro-scm2cl letrec (xvxv &rest ee) 77 | `(let ,(mapcar #'(lambda (xv) `(,(car xv) 'void)) xvxv) 78 | ,@(mapcar #'(lambda (xv) (cons 'setq xv)) xvxv) 79 | ,@ee)) 80 | 81 | (defmacro-scm2cl scm2cl-named-let-non-tr (n xvxv &rest ee) 82 | `(labels ((,n ,(mapcar #'car xvxv) ,@ee)) 83 | (,n ,@(mapcar #'cadr xvxv)))) 84 | 85 | (defmacro-scm2cl scm2cl-named-let-tr (n xvxv &rest ee) 86 | (let ((xx (mapcar #'car xvxv))) 87 | `(let ,xvxv 88 | (flet ((,n ,xx 89 | (throw ',n (values ,@xx)))) 90 | (loop 91 | (multiple-value-setq ,xx 92 | (let ,(mapcar #'(lambda (x) `(,x ,x)) xx) 93 | (catch ',n 94 | (return ,(if (= (length ee) 1) (car ee) 95 | (cons 'progn ee))))))))))) 96 | 97 | (defmacro-scm2cl scm2cl-cond (&rest clauses) 98 | (if (some #'(lambda (clause) 99 | (and (>= (length clause) 2) 100 | (eq (cadr clause) '=>))) clauses) 101 | `(scm2cl-cond-with-arrow ,@clauses) 102 | `(scm2cl-cond-without-arrow ,@clauses))) 103 | 104 | (defun scm2cl-cond-with-arrow-aux (clause) 105 | (if (not (and (= (length clause) 3) 106 | (eq (elt clause 1) '=>))) 107 | clause 108 | `((setq __test__ ,(elt clause 0)) 109 | (funcall ,(elt clause 2) __test__)))) 110 | 111 | (defmacro-scm2cl scm2cl-cond-with-arrow (&rest clauses) 112 | (let ((n (length clauses))) 113 | (if (= n 0) 'nil 114 | (let ((last-clause (elt clauses (1- n)))) 115 | (when (eq (car last-clause) 'else) 116 | (setf (car last-clause) 't)) 117 | `(let ((__test__ nil)) 118 | (cond ,@(mapcar #'scm2cl-cond-with-arrow-aux clauses))))))) 119 | 120 | 121 | (defmacro-scm2cl scm2cl-cond-without-arrow (&rest clauses) 122 | (let ((n (length clauses))) 123 | (if (= n 0) 'nil 124 | (let ((last-clause (elt clauses (1- n)))) 125 | (when (eq (car last-clause) 'else) 126 | (setf (car last-clause) 't)) 127 | `(cond ,@clauses))))) 128 | 129 | (defmacro-scm2cl scheme-defstruct (name &rest fields) 130 | (mapc #'(lambda (field) 131 | (when (consp field) (setq field (car field))) 132 | (let ((constructor 133 | (intern (concatenate 'string (symbol-name name) "." 134 | (symbol-name field))))) 135 | (push (cons constructor `(function ,constructor)) 136 | *aliases*))) 137 | fields) 138 | `(defstruct (,name (:conc-name 139 | ,(intern (concatenate 'string (symbol-name name) ".")))) 140 | ,@fields)) 141 | 142 | (defun struct-setter-p (x) 143 | (and x (symbolp x) 144 | (let ((xs (symbol-name x))) 145 | (and (> (length xs) 4) 146 | (eql (search "SET!" xs) 0))))) 147 | 148 | (defun struct-getter (setter-name) 149 | (intern (subseq (symbol-name setter-name) 4))) 150 | 151 | (defun struct-maker-p (call) 152 | (and (oddp (length call)) 153 | (let ((fn (car call))) 154 | (and (symbolp fn) 155 | (let ((fns (symbol-name fn))) 156 | (and (> (length fns) 5) 157 | (eql (search "MAKE-" fns) 0) 158 | (progn (pop call) 159 | (loop 160 | (if (null call) (return t)) 161 | (let ((f (pop call))) 162 | (unless (and (consp f) 163 | (= (length f) 2) 164 | (eq (car f) 'quote)) 165 | (return nil)) 166 | (pop call)))))))))) 167 | 168 | (defun keywordize-fieldnames (args) 169 | (let ((s '())) 170 | (loop 171 | (when (null args) (return)) 172 | (push (intern (symbol-name (cadr (pop args))) 173 | :keyword) s) 174 | (push (pop args) s) 175 | ) 176 | (nreverse s))) 177 | 178 | '(defmacro-scm2cl scheme-define-macro (name xfmr) 179 | ;MzScheme's define-macro 180 | (unless (eq (car xfmr) 'lambda) 181 | (error "scheme-define-macro ~s ~s" name xfmr)) 182 | `(defmacro ,name ,@(cdr xfmr))) 183 | 184 | ;mbe 185 | 186 | (defmacro-scm2cl scheme-define-syntax (macroname synrules) 187 | (let ((keywords (cadr synrules)) 188 | (clauses (cddr synrules))) 189 | `(defmacro ,macroname (&rest __syntax-rules-arg__) 190 | ,(scheme-mbe-syntax-rules-proc macroname keywords clauses 191 | '__syntax-rules-arg__ 192 | '__syntax-rules-keywords__)))) 193 | 194 | (defmacro-scm2cl scheme-letrec-syntax (synruledefs &rest body) 195 | `(macrolet 196 | ,(mapcar #'(lambda (synruledef) 197 | (let ((macroname (car synruledef)) 198 | (keywords (cadadr synruledef)) 199 | (clauses (cddadr synruledef))) 200 | `(,macroname (&rest __syntax-rules-arg__) 201 | ,(scheme-mbe-syntax-rules-proc macroname 202 | keywords 203 | clauses 204 | '__syntax-rules-arg__ 205 | '__syntax-rules-keywords__)))) 206 | synruledefs) 207 | ,@body)) 208 | 209 | ;Actually, CL can't distinguish let- from letrec-syntax very well. 210 | 211 | (defmacro-scm2cl scheme-let-syntax (synruledefs &rest body) 212 | (case (length synruledefs) 213 | ((0) `(progn ,@body)) 214 | ((1) `(letrec-syntax ,synruledefs ,@body)) 215 | (otherwise 216 | `(letrec-syntax (,(car synruledefs)) 217 | (let-syntax ,(cdr synruledefs) 218 | ,@body))))) 219 | 220 | ;;don't load mbe.cl if not available. this feature needed 221 | ;;because scm2cl is used to create mbe.cl from mbe.scm 222 | 223 | '(load (merge-pathnames "mbe" *load-pathname*) 224 | :if-does-not-exist nil) 225 | 226 | ;inline some scheme procedure calls 227 | 228 | (defmacro-scm2cl scheme-eval (x &rest etc) 229 | `(eval ,x)) 230 | 231 | (defmacro-scm2cl scheme-assoc (x l) 232 | `(assoc ,x ,l :test #'equal)) 233 | 234 | (defmacro-scm2cl scheme-boolean? (o) 235 | `(case ,o 236 | ((t nil) t) 237 | (t nil))) 238 | 239 | (defmacro-scm2cl scheme-current-input-port () 240 | `*standard-input*) 241 | 242 | (defmacro-scm2cl scheme-current-output-port () 243 | `*standard-output*) 244 | 245 | (defmacro-scm2cl scheme-call-with-input-file (f p) 246 | (if (and (consp p) (eq (car p) 'scm2cl-lambda)) 247 | `(with-open-file (,(caadr p) ,f :direction :input) 248 | ,@(cddr p)) 249 | (let ((i (gentemp *scm2cl-gentemp-prefix*))) 250 | `(with-open-file (,i ,f :direction :input) 251 | (funcall ,p ,i))))) 252 | 253 | (defmacro-scm2cl scheme-call-with-output-file (f p) 254 | (if (and (consp p) (eq (car p) 'scm2cl-lambda)) 255 | `(with-open-file (,(caadr p) ,f :direction :output) 256 | ,@(cddr p)) 257 | (let ((o (gentemp *scm2cl-gentemp-prefix*))) 258 | `(with-open-file (,o ,f :direction :output) 259 | (funcall ,p ,o))))) 260 | 261 | (defmacro-scm2cl scheme-char-whitespace? (c) 262 | (let ((c1 (gentemp *scm2cl-gentemp-prefix*))) 263 | `(let ((,c1 ,c)) 264 | (or (char= ,c1 #\space) (char= ,c1 #\tab) 265 | (not (graphic-char-p ,c1)))))) 266 | 267 | (defmacro-scm2cl scheme-eof-object? (v) 268 | `(eq ,v :eof-object)) 269 | 270 | (defmacro-scm2cl scheme-list->string (l) 271 | `(concatenate 'string ,l)) 272 | 273 | (defmacro-scm2cl scheme-list->vector (l) 274 | `(concatenate 'vector l)) 275 | 276 | (defmacro-scm2cl scheme-make-string (n &optional c) 277 | `(make-string ,n :initial-element 278 | ,(if c c #\space))) 279 | 280 | (defmacro-scm2cl scheme-make-vector (n &optional x) 281 | `(make-array ,n :initial-element ,x)) 282 | 283 | (defmacro-scm2cl scheme-member (x l) 284 | `(member ,x ,l :test #'equal)) 285 | 286 | (defmacro-scm2cl scheme-not-quite-call/cc (p) 287 | (let ((k (gentemp *scm2cl-gentemp-prefix*))) 288 | ;had to use gentemp above because we're writing 289 | ;expansion into file 290 | `(let ((,k (gensym))) 291 | (catch ,k 292 | ,(if (and (consp p) (eq (car p) 'scm2cl-lambda)) 293 | `(,p #'(lambda (v) (throw ,k v))) 294 | `(funcall ,p #'(lambda (v) (throw ,k v)))))))) 295 | 296 | (defmacro-scm2cl scheme-number->string (n &optional b) 297 | `(write-to-string ,n 298 | ,@(if b `(:base ,b) '()))) 299 | 300 | (defmacro-scm2cl scheme-open-input-file (f) 301 | `(open ,f :direction :input)) 302 | 303 | (defmacro-scm2cl scheme-open-output-file (f) 304 | `(open ,f :direction :output)) 305 | 306 | (defmacro-scm2cl scheme-peek-char (&optional p) 307 | `(peek-char nil ,p nil :eof-object)) 308 | 309 | (defmacro-scm2cl scheme-read (&optional p) 310 | `(read ,p nil :eof-object)) 311 | 312 | (defmacro-scm2cl scheme-read-char (&optional p) 313 | `(read-char ,p nil :eof-object)) 314 | 315 | (defmacro-scm2cl scheme-string (&rest cc) 316 | `(concatenate 'string (list ,@cc))) 317 | 318 | (defmacro-scm2cl scheme-string-append (&rest ss) 319 | `(concatenate 'string ,@ss)) 320 | 321 | (defmacro-scm2cl scheme-string-set! (s i c) 322 | `(setf (char ,s ,i) ,c)) 323 | 324 | (defmacro-scm2cl scheme-string->list (s) 325 | `(concatenate 'list ,s)) 326 | 327 | (defmacro-scm2cl scheme-string->number (s &optional b) 328 | (let ((s1 (gentemp *scm2cl-gentemp-prefix*)) 329 | (n (gentemp *scm2cl-gentemp-prefix*))) 330 | (if b 331 | `(let ((,s1 ,s)) 332 | (if (position #\: ,s1 :test #'char=) nil 333 | (let* ((*read-base* ,b) 334 | (,n (read-from-string ,s1 nil))) 335 | (if (numberp ,n) ,n nil)))) 336 | `(let ((,s1 ,s)) 337 | (if (position #\: ,s1 :test #'char=) nil 338 | (let ((,n (read-from-string ,s1 nil))) 339 | (if (numberp ,n) ,n nil))))))) 340 | 341 | (defmacro-scm2cl scheme-string->symbol (s) 342 | (let ((s1 (gentemp *scm2cl-gentemp-prefix*))) 343 | `(let ((,s1 (map 'string 344 | #'(lambda (c) (cond ((upper-case-p c) (char-downcase c)) 345 | ((lower-case-p c) (char-upcase c)) 346 | (t c))) ,s))) 347 | (if (or (string= ,s1 "") (not (char= (char ,s1 0) #\:))) 348 | (intern ,s1) 349 | (intern (subseq ,s1 1) :keyword))))) 350 | 351 | (defmacro-scm2cl scheme-symbol? (x) 352 | (let ((x1 (gentemp *scm2cl-gentemp-prefix*))) 353 | `(let ((,x1 ,x)) 354 | (and (symbolp ,x1) 355 | (not (or (eq ,x1 t) (eq ,x1 nil))))))) 356 | 357 | (defmacro-scm2cl scheme-symbol->string (x) 358 | `(string-downcase (symbol-name ,x))) 359 | 360 | (defmacro-scm2cl scheme-vector-set! (v i x) 361 | `(setf (svref ,v ,i) ,x)) 362 | 363 | (defmacro-scm2cl scheme-vector->list (v) 364 | `(concatenate 'list ,v)) 365 | 366 | (defmacro-scm2cl scheme-with-input-from-file (f th) 367 | `(with-open-file (__temp-input-port ,f :direction :input) 368 | (let ((*standard-input* __temp-input-port)) 369 | (funcall ,th)))) 370 | 371 | (defmacro-scm2cl scheme-with-output-to-file (f th) 372 | `(with-open-file (__temp-output-port ,f :direction :output) 373 | (let ((*standard-output* __temp-output-port)) 374 | (funcall ,th)))) 375 | 376 | ;slib 377 | 378 | (defmacro-scm2cl scheme-with-output-to-port (p th) 379 | `(let ((*standard-output* ,p)) 380 | (funcall ,th))) 381 | 382 | (defmacro-scm2cl scheme-with-input-from-port (p th) 383 | `(let ((*standard-input* ,p)) 384 | (funcall ,th))) 385 | 386 | (defmacro-scm2cl scheme-call-with-input-string (s p) 387 | (if (and (consp p) (eq (car p) 'scm2cl-lambda)) 388 | `(with-input-from-string (,(caadr p) ,s) 389 | ,@(cddr p)) 390 | (let ((i (gentemp *scm2cl-gentemp-prefix*))) 391 | `(with-input-from-string (,i ,s) 392 | (funcall ,p ,i))))) 393 | 394 | (defmacro-scm2cl scheme-call-with-output-string (p) 395 | (if (and (consp p) (eq (car p) 'scm2cl-lambda)) 396 | `(with-output-to-string (,(caadr p)) 397 | ,@(cddr p)) 398 | (let ((o (gentemp *scm2cl-gentemp-prefix*))) 399 | `(with-output-to-string (,o) 400 | (funcall ,p ,o))))) 401 | 402 | (defmacro-scm2cl scheme-load-relative (f) 403 | `(load (merge-pathnames (make-pathname :type ,*scm2cl-lisp-extension*) 404 | (merge-pathnames ,f *load-pathname*)))) 405 | 406 | (defmacro-scm2cl scheme-read-line (&optional i) 407 | `(read-line ,i nil :eof-object)) 408 | 409 | (defmacro-scm2cl scheme-string-index (s c) 410 | `(position ,c ,s :test #'char=)) 411 | 412 | (defmacro-scm2cl scheme-string-reverse-index (s c) 413 | `(position ,c ,s :test #'char= :from-end t)) 414 | 415 | ;eof 416 | -------------------------------------------------------------------------------- /latex/scmxlate/clnames.cl: -------------------------------------------------------------------------------- 1 | ;name conversions 2 | 3 | ;last change 2009-04-10 4 | 5 | (defvar *scm2cl-fns-named-same* 6 | '( 7 | + 8 | - 9 | * 10 | / 11 | < 12 | = 13 | > 14 | <= 15 | >= 16 | apply 17 | caaar 18 | caadr 19 | caar 20 | cadar 21 | caddr 22 | cadr 23 | car 24 | cdaar 25 | cdadr 26 | cdar 27 | cddar 28 | cdddr 29 | cddr 30 | cdr 31 | cons 32 | ;eval 33 | list 34 | write-char 35 | )) 36 | 37 | (defvar *scm2cl-fns-named-diff* 38 | '( 39 | andmap every 40 | append! nconc 41 | assoc scheme-assoc 42 | assq assoc 43 | assv assoc 44 | boolean? scheme-boolean? 45 | call-with-current-continuation scheme-not-quite-call/cc 46 | call-with-input-file scheme-call-with-input-file 47 | call-with-input-string scheme-call-with-input-string 48 | call-with-output-file scheme-call-with-output-file 49 | call-with-output-string scheme-call-with-output-string 50 | char->integer char-code 51 | char? characterp 52 | char=? char= 53 | char? char> 55 | char<=? char<= 56 | char>=? char>= 57 | char-ci=? char-equal 58 | char-ci? char-greaterp 60 | char-ci<=? char-not-greaterp 61 | char-ci>=? char-not-lessp 62 | char-lower-case? lower-case-p 63 | char-upper-case? upper-case-p 64 | char-alphabetic? alpha-char-p 65 | char-numeric? digit-char-p 66 | char-whitespace? scheme-char-whitespace? 67 | close-input-port close 68 | close-output-port close 69 | complex? complexp 70 | current-input-port scheme-current-input-port 71 | current-output-port scheme-current-output-port 72 | display princ 73 | eof-object? scheme-eof-object? 74 | eq? eq 75 | equal? equal 76 | eqv? eql 77 | eval scheme-eval 78 | even? evenp 79 | file-exists? probe-file 80 | ;file-or-directory-modify-seconds file-write-date 81 | flush-output force-output 82 | for-each mapc 83 | get-output-string get-output-stream-string 84 | 85 | #+allegro getenv 86 | #+allegro system::getenv 87 | 88 | #+ecl getenv 89 | #+ecl si:getenv 90 | 91 | #+clisp getenv 92 | #+clisp ext:getenv 93 | 94 | #+sbcl getenv 95 | #+sbcl sb-ext:posix-getenv 96 | 97 | #+clozure getenv 98 | #+clozure ccl::getenv 99 | 100 | #+abcl getenv 101 | #+abcl ext:getenv 102 | 103 | inexact->exact identity 104 | integer? integerp 105 | integer->char code-char 106 | length list-length 107 | list? scheme-list? 108 | list-ref elt 109 | list-tail subseq 110 | list->string scheme-list->string 111 | list->vector scheme-list->vector 112 | load-relative scheme-load-relative 113 | make-string scheme-make-string 114 | make-vector scheme-make-vector 115 | map mapcar 116 | member scheme-member 117 | memq member 118 | memv member 119 | modulo mod 120 | negative? minusp 121 | newline terpri 122 | null? null 123 | number? numberp 124 | number->string scheme-number->string 125 | odd? oddp 126 | open-input-file scheme-open-input-file 127 | open-input-string make-string-input-stream 128 | open-output-file scheme-open-output-file 129 | open-output-string make-string-output-stream 130 | ormap some 131 | pair? consp 132 | peek-char scheme-peek-char 133 | positive? plusp 134 | procedure? functionp;;really? 135 | quotient floor 136 | read scheme-read 137 | read-char scheme-read-char 138 | read-line scheme-read-line 139 | real? realp 140 | reverse! nreverse 141 | set-car! rplaca 142 | set-cdr! rplacd 143 | sort! sort 144 | string scheme-string 145 | string? stringp 146 | string=? string= 147 | string? string> 149 | string<=? string<= 150 | string>=? string>= 151 | string-ci=? string-equal 152 | string-ci? string-greaterp 154 | string-ci<=? string-not-greaterp 155 | string-ci>=? string-not-lessp 156 | string-append scheme-string-append 157 | string-index scheme-string-index 158 | string-length length 159 | string->list scheme-string->list 160 | string->number scheme-string->number 161 | string-ref char 162 | string-reverse-index scheme-string-reverse-index 163 | string-set! scheme-string-set! 164 | string->symbol scheme-string->symbol 165 | substring subseq 166 | symbol? scheme-symbol? 167 | symbol->string scheme-symbol->string 168 | 169 | #+(and unix (or allegro clisp)) system 170 | #+(and unix (or allegro clisp)) shell 171 | 172 | #+(and unix clozure) system 173 | #+(and unix clozure) ccl::os-command 174 | 175 | #+(and (or unix darwin) ecl) system 176 | #+(and (or unix darwin) ecl) si:system 177 | 178 | #+abcl system 179 | #+abcl ext:run-shell-command 180 | 181 | transcript-on dribble 182 | transcript-off dribble 183 | vector? vectorp 184 | vector->list scheme-vector->list 185 | vector-ref svref 186 | vector-set! scheme-vector-set 187 | void values 188 | with-input-from-file scheme-with-input-from-file 189 | with-input-from-port scheme-with-input-from-port 190 | with-output-to-file scheme-with-output-to-file 191 | with-output-to-port scheme-with-output-to-port 192 | write prin1 193 | zero? zerop 194 | )) 195 | 196 | (defvar *scm2cl-kwds-named-diff* 197 | '( 198 | begin progn 199 | cond scm2cl-cond 200 | define-syntax scheme-define-syntax 201 | defstruct scheme-defstruct 202 | else t 203 | fluid-let let 204 | lambda scm2cl-lambda 205 | let scm2cl-let 206 | ;let* scm2cl-let* 207 | let-syntax scheme-let-syntax 208 | letrec-syntax scheme-letrec-syntax 209 | ;loop is a common variable in Scheme. 210 | ;we don't want it to clash with CL's loop macro 211 | loop loop! 212 | set! setq 213 | )) 214 | 215 | (defvar *predefined-aliases* '()) 216 | 217 | (dolist (x *scm2cl-fns-named-same*) 218 | (push (cons x `(function ,x)) *predefined-aliases*)) 219 | 220 | (do ((s *scm2cl-fns-named-diff* (cddr s))) 221 | ((null s)) 222 | (push (cons (car s) `(function ,(cadr s))) *predefined-aliases*)) 223 | 224 | (do ((s *scm2cl-kwds-named-diff* (cddr s))) 225 | ((null s)) 226 | (push (cons (car s) (cadr s)) *predefined-aliases*)) 227 | -------------------------------------------------------------------------------- /latex/scmxlate/clprocs.cl: -------------------------------------------------------------------------------- 1 | ;This file contains some suggested definitions that you 2 | ;may need to manually load into your 3 | ;scm2cl-generated CL file. 4 | 5 | (defvar *scm2cl-lisp-extension* "lsp") 6 | 7 | ;r5rs 8 | 9 | (defun scheme-assoc (x l) 10 | (assoc x l :test #'equal)) 11 | 12 | (defun scheme-boolean? (o) 13 | (or (eq o t) (eq o nil))) 14 | 15 | (defun scheme-current-input-port () 16 | *standard-input*) 17 | 18 | (defun scheme-current-output-port () 19 | *standard-output*) 20 | 21 | (defun scheme-call-with-input-file (f p) 22 | (with-open-file (i f :direction :input) 23 | (funcall p i))) 24 | 25 | (defun scheme-call-with-output-file (f p) 26 | (with-open-file (o f :direction :output) 27 | (funcall p o))) 28 | 29 | (defun scheme-call-with-values (producer consumer) 30 | (multiple-value-call consumer (funcall producer))) 31 | 32 | (defun scheme-char-whitespace? (c) 33 | (or (char= c #\space) (char= c #\tab) 34 | (not (graphic-char-p c)))) 35 | 36 | (defun scheme-eof-object? (v) 37 | (eq v :eof-object)) 38 | 39 | (defun scheme-eval (exp env) 40 | (eval exp)) 41 | 42 | (defun scheme-list? (o) 43 | (and (listp o) (null (cdr (last o))))) 44 | 45 | (defun scheme-list->string (l) 46 | (concatenate 'string l)) 47 | 48 | (defun scheme-list->vector (l) 49 | (concatenate 'vector l)) 50 | 51 | (defun scheme-make-string (n &optional (c #\space)) 52 | (make-string n :initial-element c)) 53 | 54 | (defun scheme-make-vector (n &optional x) 55 | (make-array (list n) :initial-element x)) 56 | 57 | (defun scheme-member (x l) 58 | (member x l :test #'equal)) 59 | 60 | (defun scheme-not-quite-call/cc (p) 61 | (let ((k (gensym))) 62 | (catch k 63 | (funcall p #'(lambda (v) (throw k v)))))) 64 | 65 | (defun scheme-number->string (n &optional (b 10)) 66 | (write-to-string n :base b)) 67 | 68 | (defun scheme-open-input-file (f) 69 | (open f :direction :input)) 70 | 71 | (defun scheme-open-output-file (f) 72 | (open f :direction :output)) 73 | 74 | (defun scheme-peek-char (&optional p) 75 | (peek-char nil p nil :eof-object)) 76 | 77 | (defun scheme-read (&optional p) 78 | (read p nil :eof-object)) 79 | 80 | (defun scheme-read-char (&optional p) 81 | (read-char p nil :eof-object)) 82 | 83 | (defun scheme-string (&rest z) 84 | (concatenate 'string z)) 85 | 86 | (defun scheme-string-append (&rest z) 87 | (apply #'concatenate 'string z)) 88 | 89 | (defun scheme-string-set! (s i c) 90 | (setf (char s i) c)) 91 | 92 | (defun scheme-string->list (s) 93 | (concatenate 'list s)) 94 | 95 | (defun scheme-string->number (s &optional (b 10)) 96 | (let ((s1 s)) 97 | (if (position #\: s1 :test #'char=) nil 98 | (let ((*read-base* b)) 99 | (let ((n (read-from-string s nil))) 100 | (if (numberp n) n nil)))))) 101 | 102 | (defun scheme-string->symbol (s) 103 | (let ((s (map 'string 104 | #'(lambda (c) (cond ((upper-case-p c) (char-downcase c)) 105 | ((lower-case-p c) (char-upcase c)) 106 | (t c))) s))) 107 | (if (or (string= s "") (not (char= (char s 0) #\:))) 108 | (intern s) 109 | (intern (subseq s 1) :keyword)))) 110 | 111 | (defun scheme-symbol? (o) 112 | (and (symbolp o) 113 | (not (scheme-boolean? o)))) 114 | 115 | (defun scheme-symbol->string (sym) 116 | (string-downcase (symbol-name sym))) 117 | 118 | (defun scheme-vector-set (v i x) 119 | (setf (svref v i) x)) 120 | 121 | (defun scheme-vector->list (v) 122 | (concatenate 'list v)) 123 | 124 | (defun scheme-with-input-from-file (f th) 125 | (with-open-file (i f :direction :input) 126 | (let ((*standard-input* i)) 127 | (funcall th)))) 128 | 129 | (defun scheme-with-output-to-file (f th) 130 | (with-open-file (o f :direction :output) 131 | (let ((*standard-output* o)) 132 | (funcall th)))) 133 | 134 | ;mbe 135 | 136 | (load (merge-pathnames "mbe-procs" *load-pathname*)) 137 | 138 | ;some slib procs 139 | 140 | (defun scheme-read-line (&optional i) 141 | (read-line i nil :eof-object)) 142 | 143 | (defun scheme-call-with-input-string (s p) 144 | (with-input-from-string (i s) 145 | (funcall p i))) 146 | 147 | (defun scheme-call-with-output-string (p) 148 | (with-output-to-string (o) 149 | (funcall p o))) 150 | 151 | (defun scheme-load-relative (f) 152 | (load (merge-pathnames (make-pathname :type *scm2cl-lisp-extension*) 153 | (merge-pathnames f *load-pathname*)))) 154 | 155 | (defun scheme-string-index (s c) 156 | (position c s :test #'char=)) 157 | 158 | (defun scheme-string-reverse-index (s c) 159 | (position c s :test #'char= :from-end t)) 160 | -------------------------------------------------------------------------------- /latex/scmxlate/history: -------------------------------------------------------------------------------- 1 | Last change: 2012-04-21 2 | 3 | Apr 21, 2012 4 | 5 | Chicken seems to have stopped using getenv since after about v. 6 | 4.6.0. Use get-environment-variable instead, which should work 7 | for older versions too. Rpt by Timothy Beyer. 8 | 9 | Apr 11, 2009 10 | 11 | Updated for Chicken Scheme 4.0.0. 12 | 13 | Apr 10, 2009 14 | 15 | Some support for Armed Bear Common Lisp. However: It abbreviates long 16 | sexprs with "...", which is no use at all. 17 | 18 | Updated for Gambit 4.4.2. 19 | 20 | datum->syntax-object and syntax-object->datum now are named 21 | datum->syntax and syntax->datum. 22 | 23 | Apr 2, 2009 24 | 25 | Scheme quotient == CL floor. 26 | 27 | Mar 31, 2009 28 | 29 | Less verbose translation of cond with =>; and let*. 30 | 31 | Mar 19, 2009 32 | 33 | Some support for Clozure CL. 34 | 35 | Jun 13, 2006 36 | 37 | In previous change, => should have been <= 38 | (greater-than-or-equals). This was causing => in cond to 39 | translate badly. 40 | 41 | May 21, 2006 42 | 43 | clnames.cl: *scm2cl-fns-named-same* should include < = > <= => 44 | 45 | clmacros.lsp: scheme-make-vector typo (should use make-array instead of 46 | make-string). Correction from Jacques Mequin, j-mequin at ti dot com. 47 | 48 | Apr 15, 2005 49 | 50 | getenv => posix-getenv for SBCL 51 | 52 | Apr 12, 2005 53 | 54 | scm2cl changes: 55 | 56 | - Translate cond into cascaded-if only if it contains =>. Otherwise 57 | preserve the cond for readability. 58 | 59 | - Allow eval to take a second argument, which CL will ignore. 60 | 61 | - Recognize + - * / when they appear in non-function-call position. (These 62 | have repl-related values in CL, so caused quite weird bugs, without #' in 63 | front of them!) 64 | 65 | - scm2cl: Catch more instances of automatic funcall insertion. 66 | 67 | Mar 15, 2005 68 | 69 | sample.configure added. Put this file in a scmxlate-configured package and 70 | name it 'configure' 71 | 72 | Allow ((...) ...) in subsexps of if, unless and when. (I.e., funcalls will 73 | be automatically inserted.) 74 | 75 | Sept 8, 2004 76 | 77 | If $COMSPEC is set (i.e., it's a Windows box), and $TERM is cygwin, then 78 | consider OS to be unix. 79 | 80 | July 15, 2003 81 | 82 | CL xln of call-with-output-string bugfixed. 83 | 84 | May 30, 2003 85 | 86 | Allow compile option for Chicken. 87 | 88 | Use date of release instead of (cooked up) version numbers. 89 | 90 | v 1a10a 91 | 92 | May 29, 2003 93 | 94 | Remove predefn of eof for Gauche, as it is 95 | written out as unreadable object. Remove 96 | use of file-mtime as it depends on (use file.util). 97 | 98 | v 1a10 99 | 100 | May 27, 2003 101 | 102 | Alex Shinn supplied configuration for Gauche. 103 | 104 | v 1a9 105 | 106 | Mar 25, 2003 107 | 108 | Translate define-macro into define-syntax for 109 | MzScheme version 200+. 110 | 111 | v 1a8 112 | 113 | Mar 9, 2003 114 | 115 | s/scmxlate-ignore/scmxlate-ignore-define/ 116 | 117 | v 1a7 118 | 119 | Feb 9, 2003 120 | 121 | Use pretty-print for Guile. 122 | 123 | resolve-aliases shouldn't if *reading-source-file?* 124 | 125 | Feb 8, 2003 126 | 127 | scm2cl: Recognize struct-accessors as global functions. 128 | 129 | Use pp (pretty-printer) for MIT Scheme. 130 | 131 | Translate inexact->exact as identity. 132 | 133 | Insert funcalls for top-level expr inside lambda-body 134 | if it begins with two left parens. 135 | 136 | Jan 18, 2003 137 | 138 | with-input-from-port, with-output-to-port 139 | 140 | v 1a6 141 | 142 | Jan 11, 2003 143 | 144 | Allow self-recursions of the sort 145 | 146 | (define fname 147 | (lambda (...) 148 | (... fname (as value) ...))) 149 | 150 | v 1a5 151 | 152 | Dec 15, 2002 153 | 154 | resolve-aliases s/be called only when reading 155 | source file. 156 | 157 | Dec 13, 2002 158 | 159 | current-seconds. 160 | 161 | Remove Scheme file-or-directory-modify-seconds == 162 | CL file-write-date because they have a 70-year 163 | age difference. 164 | 165 | Dec 11, 2002 166 | 167 | Scsh 0.6.2: close-input-port of input string port 168 | says Error: returning zero values when one is expected 169 | (values). Removing it for now. 170 | 171 | Scheme48 won't tolerate \n in strings, even if 172 | it's deadcode! So I can't use \n for newline 173 | in display's argument string. :-( 174 | 175 | v 1a4 176 | 177 | Dec 10, 2002 178 | 179 | STKlos 0.53. 180 | 181 | For CLISP (only), set *print-pretty* to t so calls to 182 | princ inside scmxlate-insert work like Scheme 183 | display with no gratuitous newlines. (info from Sam 184 | Steingold.) 185 | 186 | v 1a3 187 | 188 | Dec 7, 2002 189 | 190 | CL banner uses lisp-implementation-{type,version} 191 | 192 | SBCL 193 | 194 | v 1a2 195 | 196 | Dec 3, 2002 197 | 198 | Support for Chicken added. 199 | 200 | Nov 29, 2002 201 | 202 | Guile 1.6.0's eval can't be called with just one 203 | argument. 204 | 205 | Nov 27, 2002 206 | 207 | MIT Scheme seems to now use syntactic closure macros 208 | rather than syntax-table-define. Accommodate. 209 | 210 | Nov 24, 2002 211 | 212 | Reject compile request for Chez/Petite if 213 | it's really Petite. Use (eqv? (current-eval) 214 | compile) trick suggested by Gustavo Gomez. 215 | 216 | v 1a1 217 | 218 | Nov 24, 2002 219 | 220 | Add code in scm2cl.cl so, when called by itself, 221 | it displays the same version number as scmxlate. 222 | 223 | Nov 23, 2002 224 | 225 | Fix scmxlate's response to a user request for compile. 226 | Shell-magic lines are preserved. CL's compile-file 227 | (or maybe just CLISP's) doesn't seem to allow an 228 | extensionless source filename -- add workaround. 229 | 230 | v 1a 231 | 232 | Nov 23, 2002 233 | 234 | Replace scmxlate-disable-main with 235 | the more general scmxlate-uncall. 236 | 237 | Documentation now covers all relevant 238 | aspects! Version finally jumps to 1! 239 | 240 | Nov 22, 2002 241 | 242 | Replace scmxlate-when with the more versatile 243 | scmxlate-cond. Added scmxlate-eval, so 244 | scmxlate-cond and scmxlate-insert have something 245 | substantial to munch on. 246 | 247 | Nov 21, 2002 248 | 249 | Reduce the number of config files needed in dialects/ 250 | subdiry to one per source file. To this end, add 251 | the following commands: 252 | scmxlate-insert 253 | scmxlate-postamble 254 | scmxlate-postprocess 255 | 256 | v 0o 257 | 258 | Nov 20, 2002 259 | 260 | Added documentation about writing an scmxlate 261 | configuration. (Lots TBD.) 262 | 263 | Shorten some filenames. 264 | s/scm2cl-names/clnames 265 | s/scm2cl-macros/clmacros 266 | s/scheme-procs/clprocs 267 | 268 | Treat #' of local procedure names introduced by 269 | labels (from non-TR named-let) correctly. 270 | 271 | Can't believe scm2cl didn't tackle letrec till 272 | now! I guess I tend to use named-let instead. 273 | 274 | Use scm2cl to translate parts of scmxlate.scm for 275 | scmxlate.cl, so I can concentrate effort on 276 | scmxlate.scm and not worry that scmxlate.cl won't 277 | be up-to-date. 278 | 279 | Nov 19, 2002 280 | 281 | Added scmxlate-when. 282 | 283 | Nov 17, 2002 284 | 285 | Added makefile for my own use. 286 | 287 | v 0n 288 | 289 | Nov 10, 2002 290 | 291 | CL: Translate set! of global vars that were previously 292 | defuns into setf's of symbol-functions. So 293 | (define foo ) followed by (set! foo ) 294 | allows foo to continue to be treated as 295 | a global function albeit with a new value. 296 | Of course, we have to ensure the new value 297 | is also a procedure, but that's probably an ok 298 | restriction. 299 | 300 | Nov 4, 2002 301 | 302 | Check for MzScheme version (< or >= 200) made more 303 | robust. Input from Paul Steckler. 304 | 305 | Nov 1, 2002 306 | 307 | Translate define-syntax into define-macro for PLT 308 | versions before 200. 309 | 310 | v 0m 311 | 312 | 15 Sep 2002 313 | 314 | CL: If first line of file-to-be-ported starts with #, 315 | ignore it. 316 | 317 | CL: Heads of case clause should be pruned of 318 | #'. 319 | 320 | 26 Mar 2002 321 | 322 | scmxlate-rename just renames a symbol in the source. 323 | scmxlate-rename-define furthermore eliminates its 324 | definition in the source. 325 | 326 | 25 Mar 2002 327 | 328 | add *predefined-aliases* that is dialect-dependent 329 | 330 | v 0L1 331 | 332 | 24 Mar 2002 333 | 334 | scmxlate.cl now uses cl pathnames instead of 335 | os-dependent stringy pathnames. (Uses :relative which 336 | isn't in CLtL1 -- I hope this doesn't break on 337 | older CLs) 338 | 339 | scmxlate-disable-main 340 | 341 | 23 Mar 2002 342 | 343 | scmxlate calls translates the cl version of 344 | each sexp rather than scm2cl'ing the entire file 345 | and then translating that result. This allows 346 | scmxlate config for cl (which is written in cl) 347 | to be more natural, ie, it doesn't have to know 348 | what the intermediate cl-translation looks like 349 | 350 | Allow defstructs to be overridden 351 | 352 | Added scmxlate-prefix, scmxlate-include, and allow 353 | scmxlate[-dialect[-os]]-start- in dialects/ 354 | 355 | When renaming x to y, we can also ignore any 356 | definition for x. 357 | 358 | 22 Mar 2002 359 | 360 | Added scmxlate-compile? 361 | as option specifiable in user-override file 362 | 363 | 21 Mar 2002 364 | 365 | Use distinct names: scmxlate-ignore, 366 | scmxlate-rename 367 | 368 | Allow user overrides in file 369 | scmxlate- 370 | 371 | Added scmxlate-target-file, which allows user to set 372 | *target-file*, which can be fruitfully used by 373 | package-writer-supplied configuration code in 374 | dialects/ to make ready-to-run scripts 375 | 376 | v 0L 377 | 378 | 19 Mar 2002 379 | 380 | Included the Scheme-to-Scheme porting mechanism from 381 | tex2page (also schelog) into this (formerly scm2cl) 382 | distribution, and rename latter to scmxlate. It still 383 | contains scm2cl as an independently usable 384 | submodule. scmxlate is thus a general 385 | configuration tool that translates a Scheme package to 386 | a variety of Scheme dialects and Common Lisp. 387 | 388 | --- I include here some history of the porting mechanism 389 | from tex2page. 390 | 391 | --- 16 Mar 2002 392 | 393 | tex2page's to-Common-Lisp porting method made general 394 | (ie, not specific to tex2page), just like the 395 | Scheme-to-Scheme method. 396 | 397 | changes to porting mechanism to help make 398 | it more easily customizable in the 399 | "dialects" directory -- defignore, 400 | defalias. don't wait for user input 401 | if singleton files dialects-supported.scm 402 | and operating-systems-supported.scm found 403 | in dialects/ 404 | 405 | --- 31 Jan 2002 406 | 407 | Scheme 48 408 | 409 | -- 16 Dec 2001 410 | 411 | Low-level define-syntax as implemented in MzScheme. 412 | Convert this to defmacro for dialects that need it. 413 | Thing to note: Petite and SXM's low-level define-syntax is 414 | almost like MzScheme's but with a slightly less 415 | convenient semantics for the procedure datum->syntax-object. 416 | 417 | --- 18 Jan 2001 418 | 419 | SXM, Pocket Scheme 420 | 421 | --- 16 Jan 2001 422 | 423 | Scsh 424 | 425 | --- 13 Dec 2000 426 | 427 | Move porting-related clutter into subdirectory "dialects". 428 | 429 | --- 4 April 1999 430 | 431 | Petite Chez Scheme 432 | 433 | --- 16 April 1998 434 | 435 | MIT Scheme 436 | 437 | --- 14 April 1998 438 | 439 | Guile 440 | 441 | --- 24 April 1997 442 | 443 | Extensible mechanism added for porting to various Scheme dialects 444 | (MzScheme, Gambit). 445 | 446 | --- end of sxmlate pre-history from tex2page 447 | 448 | 16 Mar 2002 449 | 450 | Allow correct lexical shadowing of global 451 | procedure names, where the new value can also be a 452 | procedure. These inner procs will acquire a funcall 453 | since they are not global. 454 | 455 | v 0k3 456 | 457 | 20 Mar 2001 458 | 459 | define translates to defparameter (not defvar) 460 | so a later define overwrites an earlier define 461 | of the same identifier 462 | 463 | v 0k2 464 | 465 | 6 Jan 2001 466 | 467 | (MzScheme) flush-output = (CL) force-output 468 | 469 | Dec 19, 2000 470 | 471 | getenv = system:getenv, for ACL and CLISP 472 | 473 | v 0k1 474 | 475 | Dec 17, 2000 476 | 477 | string->symbol is more Scheme-y. 478 | Leading-colon strings are cvted to keywords. 479 | All-lowercase strings are cvted to all-uppercase 480 | symbols, so symbols can remain unescaped in both 481 | Scheme and CL. In general, a lowercase char 482 | in the string becomes an uppercase char in the 483 | symbol and an uppercase char becomes a lowercase. 484 | ":keyword" -> :keyword 485 | "symbol" -> symbol 486 | "SYMBOL" -> |symbol| 487 | "SyMbOL" -> |sYmBoL| 488 | 489 | v 0k 490 | 491 | Dec 16, 2000 492 | 493 | Allow dotted data in source. 494 | 495 | string->number should work on "" too 496 | (it's defined using read-from-string, which 497 | should return nil on eof instead of erroring) 498 | 499 | struct-setter-p (scm2cl-macros.cl) shouldn't 500 | error on nonsymbols 501 | 502 | v 0j1 503 | 504 | Nov 28, 2000 505 | 506 | labels (xln of named-let) correction. The 507 | args of the procs it introduces shd be 508 | allowed to be procs themselves. 509 | 510 | v 0j 511 | 512 | Nov 23, 2000 513 | 514 | with-input-from-file, with-output-to-file 515 | load-relative 516 | 517 | v 0i 518 | 519 | Nov 2, 2000 520 | 521 | Change CL defmacro's rest arg from just 522 | __syntax-rules-arg__ to 523 | (&rest __syntax-rules-arg__) because CL spec seems (?) 524 | to disallow former. Sugg by Rainer Joswig 525 | (joswig@corporate-world.lisp.de) 526 | 527 | v. 0h 528 | 529 | Apr 2, 2000 530 | 531 | (define x (let ((y ...)) (lambda ...))) converted to 532 | (let ((y ...)) (defun x ...)) 533 | 534 | v. 0g 535 | 536 | Oct 9, 1999 537 | 538 | Procs introduces by an earlier entry in a let* should be 539 | usable in subsequent entries. 540 | 541 | Treat cond-clause that has only one element (which is 542 | both test and then-expression). 543 | 544 | v. 0f 545 | 546 | Oct 3, 1999 547 | 548 | Give uppercase char to set-dispatch-macro-character. 549 | Shouldn't matter ideally, but a version of CLISP choked. 550 | 551 | v. 0e 552 | 553 | Feb 14, 1999 554 | 555 | current-input-port, current-output-port 556 | 557 | v. 0d 558 | 559 | Feb 11, 1999 560 | 561 | A Scheme version of defstruct supported. 562 | 563 | April 27, 1998 564 | 565 | v. 0c 566 | 567 | scheme-procs.cl not included automatically in 568 | translation (it is hardly ever needed). 569 | 570 | Only those named lets whose names begin (rather than 571 | contain) the substring "loop" are converted into CL 572 | loops 573 | 574 | April 18, 1998 575 | 576 | v. 0b 577 | 578 | let-syntax and letrec-syntax treated. 579 | 580 | Made funcall-insertion better by keeping track of 581 | bound variables. 582 | 583 | => in cond recognized. 584 | 585 | April 27, 1997 586 | 587 | v. 0a 588 | -------------------------------------------------------------------------------- /latex/scmxlate/makefile: -------------------------------------------------------------------------------- 1 | submake = make -f ${HOME}/.www/tex2page/makefile.common 2 | 3 | TRIGGER_FILES = history manifest makefile version.tex \ 4 | scmxlate.scm scmxlate.cl scm2cl.cl \ 5 | scmxlate.tex 6 | 7 | default: 8 | @cat README 9 | 10 | %.html: %.tex 11 | tex2page $(@:%.html=%) 12 | while grep -i "rerun: tex2page" $(@:%.html=%.hlog); do \ 13 | tex2page $(@:%.html=%); \ 14 | done 15 | 16 | scmxlate.html: scmxlate.tex 17 | $(submake) $@ 18 | 19 | scmxlate.pdf: scmxlate.tex 20 | $(submake) $@ 21 | 22 | dist: 23 | $(submake) scmxlate.dist 24 | 25 | html: scmxlate.html scm2cl.html 26 | 27 | pdf: scmxlate.pdf 28 | 29 | dvi: scmxlate.dvi 30 | 31 | %: FORCE 32 | $(submake) $@ 33 | 34 | FORCE: ; 35 | -------------------------------------------------------------------------------- /latex/scmxlate/manifest: -------------------------------------------------------------------------------- 1 | COPYING 2 | README 3 | INSTALL 4 | manifest 5 | makefile 6 | scmxlate.scm 7 | scmxlate.cl 8 | index.tex 9 | scm2cl.cl 10 | clnames.cl 11 | clmacros.cl 12 | clprocs.cl 13 | mbe-procs.cl 14 | scm2cl.tex 15 | history 16 | scmxlate-version.tex 17 | sample.configure 18 | 19 | ;last change: 2005-03-15 20 | -------------------------------------------------------------------------------- /latex/scmxlate/mbe-procs.cl: -------------------------------------------------------------------------------- 1 | (defun scheme-mbe-ellipsis? (x) 2 | (and (consp x) (consp (cdr x)) (eq (cadr x) '***))) 3 | 4 | (defun scheme-mbe-matches-pattern? (p e k) 5 | (cond ((scheme-mbe-ellipsis? p) 6 | (if (not (= (list-length p) 2)) (error "bad ellipsis: ~a" p)) 7 | (and (scheme-list? e) 8 | (let ((p0 (car p))) 9 | (every #'(lambda (e_i) (scheme-mbe-matches-pattern? p0 e_i k)) 10 | e)))) 11 | ((consp p) 12 | (and (consp e) (scheme-mbe-matches-pattern? (car p) (car e) k) 13 | (scheme-mbe-matches-pattern? (cdr p) (cdr e) k))) 14 | ((scheme-symbol? p) (if (member p k) (eq p e) t)) 15 | (t (equal p e)))) 16 | 17 | (defun scheme-mbe-get-ellipsis-nestings (p k) 18 | (labels ((sub (p) 19 | (cond ((scheme-mbe-ellipsis? p) 20 | (cons (sub (car p)) (sub (cddr p)))) 21 | ((consp p) (nconc (sub (car p)) (sub (cdr p)))) 22 | ((scheme-symbol? p) (if (member p k) '() (list p))) 23 | (t '())))) 24 | (sub p))) 25 | 26 | (defun scheme-mbe-ellipsis-sub-envs (nestings r) 27 | (some #'(lambda (c) 28 | (if (scheme-mbe-intersect? nestings (car c)) (cdr c) nil)) 29 | r)) 30 | 31 | (defun scheme-mbe-intersect? (v y) 32 | (if (or (scheme-symbol? v) (scheme-symbol? y)) 33 | (eq v y) 34 | (some #'(lambda (v_i) 35 | (some #'(lambda (y_j) (scheme-mbe-intersect? v_i y_j)) y)) 36 | v))) 37 | 38 | (defun scheme-mbe-get-bindings (p e k) 39 | (cond ((scheme-mbe-ellipsis? p) 40 | (let ((p0 (car p))) 41 | (list (cons (scheme-mbe-get-ellipsis-nestings p0 k) 42 | (mapcar #'(lambda (e_i) 43 | (scheme-mbe-get-bindings p0 e_i k)) 44 | e))))) 45 | ((consp p) 46 | (nconc (scheme-mbe-get-bindings (car p) (car e) k) 47 | (scheme-mbe-get-bindings (cdr p) (cdr e) k))) 48 | ((scheme-symbol? p) (if (member p k) '() (list (cons p e)))) 49 | (t '()))) 50 | 51 | (defun scheme-mbe-expand-pattern (p r k) 52 | (cond ((scheme-mbe-ellipsis? p) 53 | (nconc (let* ((p0 (car p)) 54 | (nestings (scheme-mbe-get-ellipsis-nestings p0 k)) 55 | (rr (scheme-mbe-ellipsis-sub-envs nestings r))) 56 | (mapcar #'(lambda (r_i) 57 | (scheme-mbe-expand-pattern p0 (append r_i r) k)) 58 | rr)) 59 | (scheme-mbe-expand-pattern (cddr p) r k))) 60 | ((consp p) 61 | (cons (scheme-mbe-expand-pattern (car p) r k) 62 | (scheme-mbe-expand-pattern (cdr p) r k))) 63 | ((scheme-symbol? p) 64 | (if (member p k) p (let ((x (assoc p r))) (if x (cdr x) p)))) 65 | (t p))) 66 | 67 | (defun scheme-mbe-syntax-rules-proc (macro-name kk cc arg-sym kk-sym) 68 | (let ((kk (cons macro-name kk))) 69 | `(let ((,arg-sym (cons ',macro-name ,arg-sym)) 70 | (,kk-sym ',kk)) 71 | (cond ,@(mapcar #'(lambda (c) 72 | (let ((in-pat (car c)) (out-pat (cadr c))) 73 | `((scheme-mbe-matches-pattern? 74 | ',in-pat ,arg-sym ,kk-sym) 75 | (let ((r (scheme-mbe-get-bindings ',in-pat 76 | ,arg-sym 77 | ,kk-sym))) 78 | ,(if (and (consp out-pat) 79 | (eq (car out-pat) 'with)) 80 | `(scheme-mbe-expand-pattern 81 | ',(caddr out-pat) 82 | (nconc (list ,@(mapcar #'(lambda (w) 83 | `(cons ',(car w) 84 | ,(cadr w))) 85 | (cadr out-pat))) 86 | r) 87 | ,kk-sym) 88 | `(scheme-mbe-expand-pattern ',out-pat r 89 | ,kk-sym)))))) 90 | cc) 91 | (t (error "~a: no matching clause" ',macro-name)))))) 92 | -------------------------------------------------------------------------------- /latex/scmxlate/sample.configure: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Last modified: 2005-03-15 4 | 5 | # Set scmxlate to the pathname of scmxlate/scmxlate.scm 6 | # on your system, if you know it. Otherwise let 7 | # this script figure it out. 8 | 9 | scmxlate= 10 | 11 | # Modify searchpathforscmxlate if you think a 12 | # different set of directories should be 13 | # searched for scmxlate/scmxlate.scm. 14 | 15 | searchpathforscmxlate=".. ../.. ../../.. ~ /usr/local /opt" 16 | 17 | findscmxlate() { 18 | test "$scmxlate" && return 19 | echo Trying to find scmxlate/scmxlate.scm on your machine. 20 | echo This may take a while. 21 | for f in $searchpathforscmxlate 22 | do 23 | scmxlate=`find $f -name scmxlate.scm -print|sed 1q` 24 | test "$scmxlate" && return 25 | done 26 | echo Couldn\'t find scmxlate/scmxlate.scm on your machine. 27 | echo Trying to get it off the Internet. 28 | wget http://www.ccs.neu.edu/~dorai/scmxlate/scmxlate.tar.gz 29 | test -f scmxlate.tar.gz &&\ 30 | gunzip scmxlate.tar.gz &&\ 31 | tar xf scmxlate.tar &&\ 32 | scmxlate=scmxlate/scmxlate.scm 33 | 34 | test "$scmxlate" && return 35 | echo Unable to get scmxlate off the Internet. 36 | echo scmxlate is available at 37 | echo http://www.ccs.neu.edu/~dorai/scmxlate/scmxlate.html. 38 | echo You may want to get and install scmxlate manually, 39 | echo then try configure again. 40 | exit 41 | } 42 | 43 | adieu() { 44 | for f in `cat dialects/files-to-be-ported.scm` 45 | do 46 | if test -f my-$f 47 | then 48 | echo File my-$f created. 49 | echo You may rename it to $f and 50 | echo \ \ put it in your PATH. 51 | fi 52 | done 53 | } 54 | 55 | makeit() { 56 | findscmxlate 57 | echo Ignore questions on console. 58 | case "$dialect" in 59 | bigloo) 60 | echo bigloo|bigloo -eval '(load "'$scmxlate'")';; 61 | 62 | chicken) 63 | echo chicken|csi $scmxlate;; 64 | 65 | clisp) 66 | clisp -q -i $scmxlate;; 67 | 68 | cmucl) 69 | cmucl -load $scmxlate;; 70 | 71 | gambit) 72 | echo gambit|gsi $scmxlate;; 73 | 74 | gauche) 75 | echo gauche|gosh -l $scmxlate;; 76 | 77 | guile) 78 | echo guile|guile -l $scmxlate;; 79 | 80 | mitscheme) 81 | echo mitscheme|scheme -load $scmxlate;; 82 | 83 | petite) 84 | echo petite|petite $scmxlate;; 85 | 86 | plt) 87 | echo If you are not a PLT developer, you probably shouldn\'t 88 | echo be needing to do this. 89 | echo plt|mzscheme -f $scmxlate;; 90 | 91 | sbcl) 92 | sbcl --load $scmxlate;; 93 | 94 | scm) 95 | echo scm|scm -f $scmxlate;; 96 | 97 | scsh) 98 | echo scsh|scsh -s $scmxlate;; 99 | 100 | sxm) 101 | echo sxm|sxi $scmxlate;; 102 | 103 | *) 104 | echo Dialect $dialect not supported! 105 | exit;; 106 | esac 107 | #adieu 108 | } 109 | 110 | echodialectsuggestions() { 111 | clisppresent= 112 | guilepresent= 113 | test "`which clisp 2>/dev/null|grep -v ' '`" &&\ 114 | clisppresent=yes 115 | test "`which guile 2>/dev/null|grep -v ' '`" &&\ 116 | guilepresent=yes 117 | if test "$clisppresent" -o "$guilepresent" 118 | then 119 | echo 120 | echo Note: The following looks promising on your system: 121 | echo 122 | test "$guilepresent" &&\ 123 | echo \ \ ./configure --dialect=guile 124 | test "$clisppresent" &&\ 125 | echo \ \ ./configure --dialect=clisp 126 | fi 127 | } 128 | 129 | echohelp() { 130 | echo List of dialects supported: 131 | echo 132 | echo clisp cmucl sbcl \ 133 | `grep '^[^;]' dialects/dialects-supported.scm |\ 134 | sed -e 's/^\([^ ]*\).*/\1/'` |\ 135 | sed -e 's/ \ */\n/g' |\ 136 | sort |\ 137 | sed -e '$!N;$!N;$!N;$!N;$!N;s/\n/ /g' |\ 138 | sed -e 's/^/ /g' 139 | 140 | echo 141 | echo If your dialect D is listed above, type 142 | echo \ \ ./configure --dialect=D 143 | echodialectsuggestions 144 | exit 145 | } 146 | 147 | if test 1 -eq `echo $1|grep "^--dialect="|sed 1q|wc -l` 148 | then 149 | dialect=`echo $1|sed 's/--dialect=//'` 150 | if test "$dialect" = "mzscheme" 151 | then 152 | echo Program runs out of the box on MzScheme! 153 | echo You don\'t need to configure anything! 154 | exit 155 | fi 156 | if test "$dialect" = "guile" -a -f ./dialects/make-guile-version 157 | then 158 | ./dialects/make-guile-version 159 | else 160 | makeit 161 | fi 162 | else echohelp 163 | fi 164 | -------------------------------------------------------------------------------- /latex/scmxlate/scm2cl.cl: -------------------------------------------------------------------------------- 1 | ":";exec clisp -norc -q -x '(progn (setq *load-verbose* nil) (defvar scheme-file "'$1'") (load "'$0'") (exit))' 2 | ":";exec lisp -e '(defvar scheme-file "'$1'")' -e '(load "'$0'")' -e '(exit)' 3 | 4 | ;scm2cl 5 | ;converts Scheme code to Common Lisp 6 | ;resulting code _must_ be spot-checked 7 | ;Dorai Sitaram 8 | ;April 26, 1997 9 | 10 | ;last change 2009-04-10 11 | 12 | ;Shuffle the ":" lines above so that the one relevant to 13 | ;your Common Lisp dialect is the first line. This will let 14 | ;you use this file as a Unix shellscript. 15 | 16 | ;The line containing clisp is for CLISP. 17 | ;The other line is for Allegro Common Lisp. 18 | 19 | ;You can create your own ":" line for your CL dialect 20 | ;modeled on the above. Even if you're using the abovementioned 21 | ;dialects, the Lisp executable name may be different in 22 | ;your case -- change per need. 23 | 24 | (defvar *scm2cl-lisp-extension* "cl") 25 | 26 | (setq *print-case* :downcase) 27 | (setq *load-verbose* nil) 28 | 29 | ;read #t and #f as t and nil resply 30 | 31 | (set-dispatch-macro-character #\# #\T 32 | #'(lambda (p ig ig2) 33 | (declare (ignore p ig ig2)) 34 | t)) 35 | 36 | (set-dispatch-macro-character #\# #\F 37 | #'(lambda (p ig ig2) 38 | (declare (ignore p ig ig2)) 39 | nil)) 40 | 41 | ;brackets are like parens 42 | 43 | (defun read-bracketed-sexp (i c) 44 | (declare (ignore c)) 45 | (read-delimited-list #\] i t)) 46 | 47 | (set-macro-character #\] (get-macro-character #\) nil)) 48 | (set-macro-character #\[ #'read-bracketed-sexp nil) 49 | 50 | (defvar *in-scmxlate* 51 | ;this would already be t if this file is 52 | ;being loaded by scmxlate 53 | nil) 54 | 55 | (unless *in-scmxlate* 56 | (defvar *scmxlate-version* 57 | (with-open-file (i (merge-pathnames 58 | "scmxlate" 59 | (merge-pathnames 60 | (make-pathname :type "scm") 61 | *load-pathname*))) 62 | (loop 63 | (let ((x (read i nil :eof-object))) 64 | (when (eql x :eof-object) (return)) 65 | (when (and (consp x) 66 | (= (length x) 3) 67 | (eql (car x) 'define) 68 | (eql (cadr x) '*scmxlate-version*)) 69 | (return (caddr x)))))))) 70 | 71 | (load (merge-pathnames "clnames" *load-pathname*)) 72 | 73 | (load (merge-pathnames "clmacros" *load-pathname*)) 74 | 75 | (load (merge-pathnames "clprocs" *load-pathname*)) 76 | 77 | (defvar *scm2cl-procs-used* '()) 78 | 79 | (defvar *scm2cl-bound-vars* '()) 80 | 81 | (defvar *aliases* *predefined-aliases*) 82 | (defvar *local-procedures* '()) 83 | 84 | (defun scheme-to-cl (fi &optional fo) 85 | ;create cl version of scheme file fi in fo 86 | (format t "~&Translating ~a ...~%" fi) 87 | (setq *aliases* *predefined-aliases*) 88 | (unless fo 89 | (setq fo (merge-pathnames (make-pathname :type *scm2cl-lisp-extension*) 90 | fi))) 91 | ; 92 | (with-open-file (i fi :direction :input) 93 | ;discard first line if it contains # 94 | (let ((c (peek-char nil i nil :eof-object))) 95 | (unless (eq c :eof-object) 96 | (if (char= c #\#) (read-line i nil :eof-object)))) 97 | (with-open-file (o fo :direction :output :if-exists :supersede) 98 | ;(pprint '(load "clprocs.cl") o) 99 | (format o "~&;Generated from Scheme source by scm2cl (scmxlate v ~a)~%" *scmxlate-version*) 100 | (format o ";(c) Dorai Sitaram~%") 101 | (format o "; http://www.ccs.neu.edu/~~dorai/scmxlate/scmxlate.html~%") 102 | (let ((*scm2cl-procs-used* '())) 103 | (loop 104 | (let ((x (read i nil :eof-object))) 105 | (if (eq x :eof-object) (return)) 106 | (let* ((*scm2cl-bound-vars* '()) 107 | (xm (scm2cl-sexp 108 | (nsublis *aliases* x)))) 109 | (cond ((not xm) nil) 110 | ((and (consp xm) (eq (car xm) 'progn)) 111 | (dolist (y (cdr xm)) 112 | (if y (pprint y o)))) 113 | (t (pprint xm o))) 114 | (terpri o)))) 115 | (when *scm2cl-procs-used* 116 | (format t "~%~ 117 | The following Scheme procedures in clprocs.cl were used~%") 118 | (#+abcl print #-abcl pprint *scm2cl-procs-used*))))) 119 | ; 120 | (format t "~&Translation written on ~a~%" fo) 121 | ) 122 | 123 | (defun scm2cl-map (f x) 124 | (if (null x) '() 125 | (if (consp x) 126 | (cons (funcall f (car x)) (scm2cl-map f (cdr x))) 127 | (funcall f x)))) 128 | 129 | (defun scm2cl-id (e) 130 | (cond ((consp e) 131 | (let ((a (car e))) 132 | (case a 133 | ((function) (cadr e)) 134 | (t (format t "~&Funny id ~s~%" e) 135 | e)))) 136 | (t e))) 137 | 138 | (defun scm2cl-ids (e) 139 | (cond ((consp e) 140 | (let ((a (car e))) 141 | (case a 142 | ((function) (cadr e)) 143 | (t (mapcar #'scm2cl-id e))))) 144 | (t e))) 145 | 146 | (defun scm2cl-sexp-insert-funcall (e) 147 | (scm2cl-sexp e t)) 148 | 149 | (defun scm2cl-sexp (e &optional insert-funcall-p) 150 | ;transform scheme sexp e into its cl counterpart 151 | (cond ((consp e) 152 | (let ((a (car e))) 153 | (if (consp a) 154 | (let ((aa (car a))) 155 | (case aa 156 | ((function) 157 | (let ((f (cadr a))) 158 | (if (member f *scm2cl-bound-vars*) 159 | (cons 'funcall 160 | (cons f 161 | (mapcar #'scm2cl-sexp-insert-funcall 162 | (cdr e)))) 163 | (let ((xfmr (gethash f *scm2cl-macros*))) 164 | (if xfmr 165 | (scm2cl-sexp (apply xfmr (cdr e))) 166 | (cons f 167 | (mapcar #'scm2cl-sexp-insert-funcall 168 | (cdr e)))))))) 169 | ((scm2cl-lambda) 170 | (cons 171 | (scm2cl-sexp 172 | (cons 'scm2cl-functionless-lambda (cdr a))) 173 | (mapcar #'scm2cl-sexp-insert-funcall (cdr e)))) 174 | ((case cond if when unless) 175 | (cons 'funcall 176 | (mapcar #'scm2cl-sexp-insert-funcall 177 | e))) 178 | (t 179 | (if insert-funcall-p 180 | (cons 'funcall 181 | (mapcar #'scm2cl-sexp-insert-funcall e)) 182 | (progn 183 | (unless (eq aa 'scm2cl-lambda) 184 | (format t "~&Possible funcall at ~s~%" e)) 185 | (scm2cl-map #'scm2cl-sexp-insert-funcall e)))))) 186 | (let ((xfmr (gethash a *scm2cl-macros*))) 187 | (if xfmr (scm2cl-sexp (apply xfmr (cdr e))) 188 | (cond ((eq a 'case) 189 | `(case ,(scm2cl-sexp-insert-funcall (cadr e)) 190 | ,@(mapcar 191 | #'(lambda (c) 192 | `(,(scm2cl-ids (car c)) 193 | ,@(mapcar #'scm2cl-sexp-insert-funcall 194 | (cdr c)))) 195 | (cddr e)))) 196 | ((eq a 'cond) 197 | `(cond ,@(mapcar 198 | #'(lambda (c) 199 | (mapcar #'scm2cl-sexp-insert-funcall 200 | c)) 201 | (cdr e)))) 202 | ((member a '(flet multiple-value-setq)) 203 | ;generated by named let (tr) 204 | `(,a ,(cadr e) 205 | ,@(mapcar #'scm2cl-sexp-insert-funcall 206 | (cddr e)))) 207 | ((eq a 'lambda) 208 | `(lambda ,(cadr e) 209 | ,@(let ((*scm2cl-bound-vars* 210 | (append (cadr e) *scm2cl-bound-vars*))) 211 | (mapcar 212 | #'scm2cl-sexp-insert-funcall 213 | (cddr e))))) 214 | ((member a '(if unless when)) 215 | `(,a ,@(mapcar #'scm2cl-sexp-insert-funcall 216 | (cdr e)))) 217 | ((eq a 'defun) 218 | (let ((bvv (caddr e))) 219 | `(defun ,(cadr e) ,bvv 220 | ,@(let ((*scm2cl-bound-vars* 221 | (append bvv *scm2cl-bound-vars*))) 222 | (mapcar #'scm2cl-sexp-insert-funcall 223 | (cdddr e)))))) 224 | ((eq a 'setq) 225 | (let ((x (cadr e))) 226 | (if (and (consp x) (eq (car x) 'function)) 227 | `(setf (symbol-function ',(cadr x)) 228 | ,(scm2cl-sexp (caddr e))) 229 | `(setq ,x 230 | ,(scm2cl-sexp-insert-funcall 231 | (caddr e)))))) 232 | ((and (eq a 'progn) (= (length e) 2)) 233 | (scm2cl-sexp-insert-funcall (cadr e))) 234 | ((eq a 'let) ;(member a '(let let*)) 235 | `(let ,(mapcar 236 | #'(lambda (xv) 237 | `(,(scm2cl-id (car xv)) 238 | ,(scm2cl-sexp-insert-funcall (cadr xv)))) 239 | (cadr e)) 240 | ,@(let ((*scm2cl-bound-vars* 241 | (append (mapcar 242 | #'(lambda (xv) 243 | (scm2cl-id (car xv))) 244 | (cadr e)) 245 | *scm2cl-bound-vars*))) 246 | (mapcar #'scm2cl-sexp-insert-funcall 247 | (cddr e))))) 248 | ((eq a 'let*) 249 | `(let* ,(let ((xvxv (cadr e)) (r '()) 250 | (*scm2cl-bound-vars* *scm2cl-bound-vars*)) 251 | (loop 252 | (unless xvxv (return (nreverse r))) 253 | (destructuring-bind (x v) (pop xvxv) 254 | (let ((x (scm2cl-id x))) 255 | (push `(,x ,(scm2cl-sexp-insert-funcall v)) r) 256 | (push x *scm2cl-bound-vars*))))) 257 | ,@(let ((*scm2cl-bound-vars* 258 | (append (mapcar (lambda (xv) (scm2cl-id (car xv))) (cadr e)) 259 | *scm2cl-bound-vars*))) 260 | (mapcar #'scm2cl-sexp-insert-funcall (cddr e))))) 261 | ((eq a 'labels) 262 | (let ((*local-procedures* *local-procedures*)) 263 | (mapcar #'(lambda (label-init) 264 | (push (car label-init) 265 | *local-procedures*)) 266 | (cadr e)) 267 | `(,a ,(mapcar 268 | #'(lambda (label-init) 269 | (let ((bvv (cadr label-init))) 270 | `(,(scm2cl-id 271 | (scm2cl-sexp (car label-init))) 272 | ,(mapcar #'scm2cl-sexp bvv) 273 | ,@(let ((*scm2cl-bound-vars* 274 | (append bvv 275 | *scm2cl-bound-vars* 276 | ) 277 | )) 278 | (mapcar #'scm2cl-sexp 279 | (cddr label-init)))))) 280 | (cadr e)) 281 | ,@(mapcar #'scm2cl-sexp-insert-funcall 282 | (cddr e))))) 283 | ((eq a 'with-open-file) 284 | `(,a ,(mapcar #'scm2cl-sexp (cadr e)) 285 | ,@(mapcar #'scm2cl-sexp-insert-funcall 286 | (cddr e)))) 287 | ((eq a 'quote) 288 | (let ((quotee (cadr e))) 289 | (if (and (consp quotee) 290 | (eql (car quotee) 'function)) 291 | (list 'quote (cadr quotee)) 292 | e))) 293 | ((member a '(define-macro)) 294 | (format t "~&Skipping ~a ~a~%" a (cadr e)) 295 | nil) 296 | ((and (struct-setter-p a) (= (length e) 3)) 297 | `(setf (,(struct-getter a) ,(scm2cl-sexp (cadr e))) 298 | ,(scm2cl-sexp (caddr e)))) 299 | ((struct-maker-p e) 300 | (cons a (mapcar #'scm2cl-sexp 301 | (keywordize-fieldnames (cdr e))))) 302 | ((member a *scm2cl-bound-vars*) 303 | (cons 'funcall (mapcar #'scm2cl-sexp e))) 304 | ((member a *local-procedures*) 305 | (cons (scm2cl-id (scm2cl-sexp a)) 306 | (mapcar #'scm2cl-sexp (cdr e)))) 307 | (t (scm2cl-map #'scm2cl-sexp e)))))))) 308 | ((symbolp e) 309 | (if (eql (search "SCHEME-" (symbol-name e)) 0) 310 | (pushnew e *scm2cl-procs-used*)) 311 | (if (member e *local-procedures*) 312 | `(function ,e) 313 | e)) 314 | (t e))) 315 | 316 | ;(trace scm2cl-sexp) 317 | 318 | (when (boundp 'scheme-file) 319 | ;if this file is being used as a shellscript, 320 | ;convert its first arg, which is a scheme file 321 | (let ((cl-file 322 | (merge-pathnames (make-pathname :type *scm2cl-lisp-extension*) 323 | scheme-file))) 324 | (format t "~&This is scm2cl (scmxlate v ~a)~%" *scmxlate-version*) 325 | (scheme-to-cl scheme-file cl-file) 326 | )) 327 | 328 | ;(trace scm2cl-sexp) 329 | -------------------------------------------------------------------------------- /latex/scmxlate/scm2cl.tex: -------------------------------------------------------------------------------- 1 | \input tex2page 2 | \input plainsection 3 | 4 | \let\TZPtexlayout 0 5 | \let\n\noindent 6 | 7 | \ifx\shipout\totheWeb 8 | \def\evalsto{=>} 9 | \else 10 | \def\evalsto{\leavevmode\hbox{$\Rightarrow$}} 11 | \fi 12 | 13 | 14 | \scmkeyword{function} 15 | 16 | \title{scm2cl} 17 | 18 | %\ignorenextinputtimestamp 19 | 20 | \centerline{\urlh{scmxlate.tar.bz2}{\ifx\shipout\totheWeb 21 | Download {\tt scmxlate}\fi Version 20090410}} 22 | \centerline{({\tt scm2cl} is part of the \urlh{scmxlate.html}{scmxlate} distribution)} 23 | 24 | \centerline{\urlh{../index.html}{Dorai Sitaram}} 25 | 26 | \medskip 27 | 28 | \p{scm2cl} is a Common Lisp 29 | program that converts Scheme 30 | code to Common Lisp. Its goal is to remove the tedium of 31 | transcribing a large Scheme file into CL, not to avoid human 32 | intervention altogether. You may have to do some 33 | hand-tuning --- \p{scm2cl} will assist you here too. 34 | 35 | \p{scm2cl} understands R5RS Scheme, including the 36 | high-level macros (\q{define-syntax}, \q{let-syntax}, 37 | and \q{letrec-syntax}), plus some common Scheme 38 | extensions, viz, \q{andmap}, \q{append!}, 39 | \q{call-with-input-string}, 40 | \q{call-with-output-string}, \q{delete-file}, \q{exit}, 41 | \q{file-exists?}, %\q{file-or-directory-modify-seconds}, 42 | \q{fluid-let}, \q{flush-output}, \q{getenv}, \q{get-output-string}, 43 | \q{open-input-string}, \q{open-output-string}, 44 | \q{ormap}, \q{read-line}, \q{reverse!}, 45 | \q{string-index}, \q{string-reverse-index}, \q{system}. 46 | 47 | \section{Usage} 48 | 49 | With some Common Lisp dialects, you can call \p{scm2cl.cl} 50 | on the operating-system command-line, with the Scheme file 51 | to be converted as argument: 52 | 53 | \verb{ 54 | scm2cl.cl scmfile.scm 55 | } 56 | 57 | \n This produces the CL file in \p{scmfile.cl}. 58 | 59 | If this is not possible, you may load \p{scm2cl.cl} into 60 | your Common Lisp and invoke the function \q{scheme-to-cl}. 61 | Eg, 62 | 63 | \scm{ 64 | (load "scm2cl.cl") 65 | (scheme-to-cl "scmfile.scm") 66 | } 67 | 68 | \section{Human Intervention} 69 | 70 | \subsection{\q{funcall} and \q{function}} 71 | 72 | \p{scm2cl} is good at inserting \q{funcall} and \q{function} 73 | (aka \q{#'}) where needed, but not perfect. It will, 74 | however, draw your attention to code locations where a 75 | \q{funcall} {\it may\/} be needed. \p{scm2cl} will not 76 | miss any of these problem spots, so you don't have to hunt 77 | for \q{funcall} locations on your own. 78 | 79 | No similar signaling is offered for potential 80 | \q{#'} locations. 81 | (The reason is that this would lead to too many signals for 82 | \q{#'}, the vast majority of them being red herrings. 83 | Detecting \q{funcall} is less noisy, but still not perfect 84 | --- which is why \p{scm2cl} suggests passively instead of 85 | inserting actively.) 86 | 87 | \subsection{Some additional definitions} 88 | 89 | The CL file produced by \p{scm2cl} may use some of the 90 | procedures defined in the file 91 | \p{scheme-procs.cl}. (\p{scheme-procs.cl} contains some Scheme-like 92 | procedure definitions for CL.) At the end of the 93 | conversion, \p{scm2cl} will give you the exact list of 94 | Scheme procedures from 95 | \p{scheme-procs.cl} actually used. You will need to 96 | incorporate these procedure definitions into the 97 | converted code. How you do it is up to your 98 | convenience. 99 | 100 | \subsection{Caveats} 101 | 102 | Only ``escape'' continuations are allowed for 103 | \q{call-with-current-continuation}. 104 | 105 | ``Named'' \q{let}s whose names begin with the substring 106 | \q{"loop"} are converted into iterative CL loops. 107 | \p{scm2cl} assumes that such named \q{let}s were intended to 108 | write iterative (``tail-recursive'') loops, and translates 109 | accordingly. This will cause error if the \q{let} wasn't so 110 | intended. 111 | 112 | Named \q{let}s with names that do not begin with \q{loop} 113 | are converted using CL \q{labels}. 114 | 115 | %\section{References} 116 | % 117 | %\nocite{clhs,cltl} 118 | % 119 | %\bibliographystyle{plain} 120 | %\bibliography{scm2cl} 121 | 122 | \bye 123 | -------------------------------------------------------------------------------- /latex/scmxlate/scmxlate-version.tex: -------------------------------------------------------------------------------- 1 | 20090410% last change 2 | -------------------------------------------------------------------------------- /latex/scmxlate/scmxlate.cl: -------------------------------------------------------------------------------- 1 | ":";exec clisp -q $0 2 | ":";exec lisp -Q -L $0 3 | 4 | (defvar *dialect* 'cl) 5 | 6 | (setq *load-verbose* nil) 7 | 8 | #+clisp 9 | (setq *print-pretty* nil) 10 | 11 | (defvar *in-scmxlate* t) 12 | 13 | (defun compile-possible? () t) 14 | 15 | (defmacro define (&rest ee) 16 | `(defvar ,@ee)) 17 | 18 | (load (merge-pathnames "scm2cl" *load-pathname*)) 19 | 20 | (defun eval1 (e) 21 | (eval e)) 22 | 23 | (defvar eval1 #'eval1) 24 | 25 | (defun exists-file? (f) 26 | (probe-file f)) 27 | 28 | (defun ensure-file-deleted (f) 29 | (if (probe-file f) (delete-file f))) 30 | 31 | (defun read-a-line (i) 32 | (read-line i)) 33 | 34 | (defun translate-define-syntax (e) 35 | (format t "~&define-syntax is probably best configured manually: ~s~%" e) 36 | e) 37 | 38 | (defun translate-define-macro (e) 39 | (format t "~&define-macro is probably best configured manually: ~s~%" e) 40 | e) 41 | 42 | (defun writeln (e o) 43 | (pprint 44 | (if *reading-source-file?* 45 | (let ((*scm2cl-bound-vars* '())) 46 | (scm2cl-sexp (nsublis *aliases* e))) 47 | (progn 48 | (when (and (consp e) (eq (car e) 'defun)) 49 | (let ((name (cadr e))) 50 | (push (cons name `(function ,name)) *aliases*))) 51 | (if (and (consp e) (eq (car e) 'define)) 52 | ;silently change define in non-source file 53 | ;to defvar (useful for user-override file 54 | ;that user forgot to change for CL) 55 | `(defvar ,@(cdr e)) 56 | e))) o) 57 | (terpri o)) 58 | 59 | (defun scmxlate-system (c) 60 | 61 | #+(or allegro clisp) 62 | (shell 63 | #+win32 (concatenate 'string "cmd /c " c) 64 | #-win32 c) 65 | 66 | #+(and (or cmu sbcl) unix) 67 | (#+cmu ext:run-program 68 | #+sbcl run-program 69 | "/bin/sh" (list "-c" c)) 70 | 71 | #+ecl 72 | (si:system c) 73 | 74 | #+clozure 75 | (ccl::os-command c) 76 | 77 | #+abcl 78 | (ext:run-shell-command c) 79 | 80 | ) 81 | 82 | (defun chmod+x (f) 83 | #+unix 84 | (let ((f (namestring f))) 85 | (when *shell-script?* 86 | (scmxlate-system 87 | (concatenate 'string "chmod +x " f))))) 88 | 89 | (defun compile-file-to-file (fi fo) 90 | (when (not (pathname-type fi)) 91 | (let ((new-fi (concatenate 'string fi "-temp.lisp"))) 92 | (copy-file-to-file fi new-fi) 93 | (setq fi new-fi))) 94 | (compile-file fi :output-file fo) 95 | fo) 96 | 97 | (with-open-file (i (merge-pathnames 98 | (make-pathname :type "scm") *load-pathname*) 99 | :direction :input) 100 | (loop 101 | (let ((x (read i nil :eof-object))) 102 | (when (eql x :eof-object) (return)) 103 | (when (equal x ''eval-in-cl-also) 104 | (eval (scm2cl-sexp (nsublis *predefined-aliases* 105 | (read i)))))))) 106 | 107 | #+allegro (exit) 108 | #+(or clisp cmu ecl sbcl) (quit) 109 | 110 | #-(or allegro clisp cmu ecl sbcl) 111 | (cond ((fboundp 'bye) (bye)) 112 | ((fboundp 'exit) (exit)) 113 | ((fboundp 'quit) (quit)) 114 | (t (format t "~&You may exit CL now!~%"))) 115 | -------------------------------------------------------------------------------- /latex/slatex/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (c) 1990-2002, Dorai Sitaram. 2 | All rights reserved. 3 | 4 | Permission to distribute and use this work for any 5 | purpose is hereby granted provided this copyright 6 | notice is included in the copy. This work is provided 7 | as is, with no warranty of any kind. 8 | -------------------------------------------------------------------------------- /latex/slatex/INSTALL: -------------------------------------------------------------------------------- 1 | INSTALL 2 | SLaTeX Version 2.4 3 | (c) Dorai Sitaram 4 | 5 | Installation instructions for SLaTeX 6 | 7 | - 8 | 9 | 1) Ensure you have the scmxlate program installed on 10 | your system. scmxlate is available at 11 | http://www.ccs.neu.edu/~dorai/scmxlate/scmxlate.html 12 | 13 | 1) Unpack the slatex tarball, creating a directory 14 | called slatex 15 | 16 | 2) Edit the file scmxlate-slatex-src.scm as 17 | suggested in the comments there. 18 | 19 | 3) Invoke your Scheme (or Common Lisp) listener and load 20 | the file scmxlate/scmxlate.scm, using its correct relative 21 | or full pathname. 22 | 23 | (load ".../scmxlate/scmxlate.scm") 24 | 25 | This will configure SLaTeX for your Scheme/CL dialect 26 | and operating system, creating an appropriate 27 | slatex.scm file. A script file (called slatex.bat on 28 | Windows and just slatex on Unix) is also created for 29 | convenient invocation on your operating system command 30 | line. You may need to check slatex[.bat] to see 31 | that it has correct pathnames. 32 | 33 | 4) Copy or move or link slatex.scm into the location 34 | you identified in scmxlate-slatex-src.scm. 35 | 36 | 6) Copy or move or link slatex.sty into a suitable 37 | place, e.g., somewhere in your TEXINPUT(S) path. For 38 | installing on system, place in directory containing 39 | the LaTeX style files. 40 | 41 | 7) (If your platform is a Mac, ignore this.) Copy or move 42 | or link the shellscript slatex or batfile slatex.bat to a 43 | suitable place in your PATH, e.g., your bin or the system 44 | bin. 45 | 46 | 8) Run slatex on slatxdoc.tex for documentation. 47 | (This also checks that slatex does indeed work on your 48 | machine.) Refer to slatxdoc.dvi when befuddled. 49 | 50 | 9) If a shellscript/batfile slatex[.bat] cannot 51 | be meaningfully used on your system, you can use the 52 | file callsla.scm, which is also created by the 53 | configuration process. Load callsla.scm into your 54 | Scheme/CL and call the procedure call-slatex with your 55 | document filename as argument. 56 | -------------------------------------------------------------------------------- /latex/slatex/README: -------------------------------------------------------------------------------- 1 | README 2 | SLaTeX Version 2.4 3 | (c) Dorai Sitaram 4 | dorai@cs.rice.edu 5 | 6 | Read me first 7 | 8 | ... 9 | 10 | 1. A brief description of SLaTeX 11 | 12 | SLaTeX is a Scheme program that allows you to write program 13 | code (or code fragments) "as is" in your LaTeX or TeX 14 | source. SLaTeX is particularly geared to the programming 15 | languages Scheme (R5RS) and other Lisps, e.g., Common Lisp. 16 | The formatting of the code includes assigning appropriate 17 | fonts to the various tokens in the code (keywords, 18 | variables, constants, data), at the same time retaining the 19 | proper indentation when going to the non-monospace 20 | (non-typewriter) fonts provided by TeX. SLaTeX comes with 21 | two databases that recognize the identifier conventions of 22 | Scheme and CL respectively. 23 | 24 | While it is certainly possible to get by with a minimal 25 | knowledge of SLaTeX commands, the package comes with a 26 | variety of features for manipulating output positioning, 27 | modifying/enhancing the database, changing the fonting 28 | defaults, adding special symbols, and selective disabling of 29 | SLaTeX. For a detailed documentation of SLaTeX, run slatex 30 | on the file slatxdoc.tex in the SLaTeX distribution after 31 | finishing the installation process. 32 | 33 | ... 34 | 35 | 2. Obtaining SLaTeX 36 | 37 | SLaTeX is available at the URL 38 | http://www.ccs.neu.edu/~dorai/slatex/slatex.tar.gz. 39 | Ungzipping and untarring produces a directory slatex, 40 | containing the SLaTeX files. (The file "manifest" lists the 41 | files in the distribution -- make sure nothing is missing.) 42 | 43 | ... 44 | 45 | 46 | 3. Installing SLaTeX 47 | 48 | Refer to the file "INSTALL" for configuring SLaTeX to your 49 | dialect and ways of invoking it on your (La)TeX files. 50 | 51 | ... 52 | 53 | 4. Using SLaTeX 54 | 55 | The file slatxdoc.tex is a manual describing "How to Use 56 | SLaTeX". A version of the corresponding .dvi file, 57 | slatxdoc.dvi, is included in the distribution, but you could 58 | create your own (and thereby check that SLaTeX works on your 59 | system). Save the provided slatxdoc.dvi file in case your 60 | setup doesn't work, and type 61 | 62 | slatex slatxdoc 63 | 64 | You may create a file slatxdoc.ind that arranges the index 65 | information from the file slatxdoc.idx generated by LaTeX. 66 | Run LaTeX on slatxdoc another time to sort out the index and 67 | the citations. 68 | 69 | If you have run Scheme (or CL) on config.scm (Sec. 1 of 70 | install) but haven't been able to decide how to set up the 71 | paths or the shell/bat script or the most suitable invoking 72 | method (Sec. 2 and 3 of install), perform the following 73 | actions (in the directory where you unpacked the 74 | distribution) to get slatxdoc.dvi: 75 | 76 | 1) Start up Scheme (or CL). 77 | 78 | 2) Type (load "slatex.scm"). 79 | 80 | 3) Type (slatex::process-main-tex-file "slatxdoc"). 81 | 82 | 4) Exit Scheme (or CL). 83 | 84 | 5) Call latex on slatxdoc.tex. (Use makeindex to generate 85 | slatxdoc.ind, if possible. Call latex a second time to get 86 | the citations right and to generate an index if available.) 87 | 88 | ... 89 | 90 | 6. Bugs, etc 91 | 92 | Email to ds26 at gte dot com 93 | -------------------------------------------------------------------------------- /latex/slatex/callsla.scm: -------------------------------------------------------------------------------- 1 | (define call-slatex (let ((already-loaded? #f)) (lambda (f) (if (not already-loaded?) (begin (load "~/latex/slatex/slatex.scm") (set! already-loaded? #t))) (slatex::process-main-tex-file f) (display "Call (La)TeX on ") (display f) (display " now") (newline)))) 2 | -------------------------------------------------------------------------------- /latex/slatex/cltl.sty: -------------------------------------------------------------------------------- 1 | %cltl.sty 2 | %SLaTeX Version 1.99 3 | %Style file to be used in (La)TeX when using SLaTeX for Common Lisp 4 | %(c) Dorai Sitaram, December 1991, Rice University 5 | 6 | \input slatex.sty 7 | 8 | % The database in this file was generated from CL as follows: 9 | 10 | % (defun canonical-special-form-p (x) 11 | % (and (special-form-p x) (not (macro-function x)))) 12 | 13 | % (defun gather (pred) 14 | % (sort (let ((x '())) 15 | % (do-all-symbols (y) 16 | % (if (funcall pred y) (setq x (cons y x)))) 17 | % x) 18 | % #'string< :key #'symbol-name)) 19 | 20 | % A rather old (1987) version of Ibuki CL was used. So you may want 21 | % to regenerate the keywords using the above functions in _your_ CL. 22 | 23 | % CL sp. forms, i.e., (gather #'canonical-special-form-p) 24 | 25 | \setkeyword{block catch compiler-let declare eval-when flet function 26 | go if labels let let* macrolet multiple-value-call 27 | multiple-value-prog1 progn progv quote return-from setq tagbody the 28 | throw unwind-protect} 29 | 30 | % CL macros, i.e., (gather #'macro-function) 31 | 32 | \setkeyword{and assert compiler::base-used case ccase check-type 33 | compiler::ck-spec compiler::ck-vl clines compiler::cmpck 34 | system::coerce-to-package conditions::conc-name cond ctypecase decf 35 | debugger::def-command defcfun defconstant defentry 36 | system:define-compiler-macro conditions:define-condition 37 | system:define-inline-function define-modify-macro define-setf-method 38 | define-user-stream-type defla defmacro defparameter defsetf defstruct 39 | deftype defun debugger::defun-property defvar do do* do-all-symbols 40 | do-external-symbols do-symbols system::docdoc system::docfun 41 | system::doctype system::docvar dolist compiler::dolist* 42 | compiler::dolist** dotimes compiler::dotimes* compiler::dotimes** 43 | ecase etypecase compiler::get-output-pathname conditions:handler-bind 44 | conditions:handler-case system::if-error conditions:ignore-errors incf 45 | system::inspect-print system::inspect-recursively locally loop 46 | conditions::make-function multiple-value-bind multiple-value-list 47 | multiple-value-setq compiler::next-cfun compiler::next-cmacro 48 | compiler::next-cvar compiler::next-label compiler::next-label* or 49 | conditions::parent-type pop prog prog* prog1 prog2 psetf psetq push 50 | pushnew remf conditions::report-function conditions::resolve-function 51 | conditions:restart-bind conditions:restart-case return rotatef 52 | compiler::safe-compile setf shiftf conditions::slots step time trace 53 | typecase unless untrace when debugger::with-debugger-environment 54 | with-input-from-string conditions::with-keyword-pairs with-open-file 55 | with-open-stream with-output-to-string conditions:with-simple-restart 56 | compiler::wt compiler::wt-go compiler::wt-h compiler::wt-label 57 | compiler::wt-nl compiler::wt-nl1} 58 | -------------------------------------------------------------------------------- /latex/slatex/defun.tex: -------------------------------------------------------------------------------- 1 | \ifx\shipout\UnDeFiNeD\endinput\fi 2 | 3 | % 4 | % definitions (useful in reference manuals) 5 | 6 | \def\defun#1{\def\defuntype{#1}% 7 | \medbreak 8 | \line\bgroup 9 | \hbox\bgroup 10 | \aftergroup\enddefun 11 | \vrule width .5ex \thinspace 12 | \vrule \enspace 13 | \vbox\bgroup\setbox0=\hbox{\defuntype}% 14 | \advance\hsize-\wd0 15 | \advance\hsize-1em 16 | \obeylines 17 | \parindent=0pt 18 | \aftergroup\egroup 19 | \strut 20 | \let\dummy=} 21 | 22 | \def\enddefun{\hfil\defuntype\egroup\smallskip} 23 | 24 | -------------------------------------------------------------------------------- /latex/slatex/dialects/bigloo-slatex-src.scm: -------------------------------------------------------------------------------- 1 | 2 | (scmxlate-include "make-qualified-names.scm") 3 | 4 | (scmxlate-rename 5 | (delete bigloo-delete) 6 | ) 7 | 8 | (define-macro (fluid-let xvxv . ee) 9 | (let ((xx (map car xvxv)) 10 | (vv (map cadr xvxv)) 11 | (old-xx (map (lambda (xv) 12 | (string->symbol 13 | (string-append "%__" 14 | (symbol->string (car xv))))) xvxv)) 15 | (res '%_*_res)) 16 | `(let ,(map (lambda (old-x x) `(,old-x ,x)) old-xx xx) 17 | ,@(map (lambda (x v) 18 | `(set! ,x ,v)) xx vv) 19 | (let ((,res (begin ,@ee))) 20 | ,@(map (lambda (x old-x) `(set! ,x ,old-x)) xx old-xx) 21 | ,res)))) 22 | 23 | 24 | (define flush-output 25 | (lambda z 26 | ;bigloo's flush-output-port always takes 1 arg 27 | (flush-output-port 28 | (if (null? z) (current-output-port) (car z))))) 29 | 30 | (define void 31 | (lambda () 32 | (if #f #f))) 33 | 34 | (scmxlate-postprocess 35 | 36 | (define *scheme-command-name* "bigloo") 37 | 38 | (load "dialects/make-echo-script.scm") 39 | ) 40 | 41 | -------------------------------------------------------------------------------- /latex/slatex/dialects/chez-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-include "make-qualified-names.scm") 2 | 3 | (scmxlate-rename 4 | (flush-output flush-output-port) 5 | ) 6 | 7 | (scmxlate-postprocess 8 | 9 | (define *scheme-command-name* 10 | (if (eqv? *dialect* 'chez) "chez" 11 | "petite")) 12 | 13 | (load "dialects/make-echo-script.scm") 14 | ) 15 | -------------------------------------------------------------------------------- /latex/slatex/dialects/cl-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-eval 2 | (unless (find-package :slatex) 3 | (make-package :slatex)) 4 | ) 5 | 6 | (unless (find-package :slatex) 7 | (make-package :slatex)) 8 | 9 | (in-package :slatex) 10 | 11 | (defvar *operating-system* 12 | #+win32 'windows 13 | #-win32 'unix) 14 | 15 | 16 | (scmxlate-ignore 17 | *operating-system* 18 | ; adjoin 19 | ; delete 20 | delete-if 21 | directory-namestring 22 | ; exit-scheme 23 | mapcan 24 | the-setter-for-of 25 | ; position-char 26 | setf) 27 | 28 | (defun scheme-like-delete (x l eq) 29 | (declare (list l)) 30 | (delete x l :test eq)) 31 | 32 | (defun scheme-like-adjoin (x l eq) 33 | (declare (list l)) 34 | (adjoin x l :test eq)) 35 | 36 | (scmxlate-rename-define 37 | (adjoin #'scheme-like-adjoin) 38 | (delete #'scheme-like-delete) 39 | (exit-slatex #'exit) 40 | (position-char #'position) 41 | ) 42 | 43 | (defmacro defenum (&rest z) 44 | (let ((z z) (i 0) (r '())) 45 | (loop 46 | (when (null z) (return `(progn ,@r))) 47 | (push `(defvar ,(car z) (code-char ,i)) r) 48 | (incf i) 49 | (pop z)))) 50 | 51 | (defmacro defrecord (name &rest fields) 52 | (let ((fields fields) (i 0) (r '())) 53 | (loop 54 | (when (null fields) 55 | (return 56 | `(progn 57 | (defun ,name () (make-array ,i)) 58 | ,@r))) 59 | (push `(defvar ,(car fields) ,i) r) 60 | (pop fields) 61 | (incf i)))) 62 | 63 | (defmacro of (r i &rest z) 64 | (cond ((null z) `(elt ,r ,i)) 65 | ((and (eq i '/) (= (length z) 1)) 66 | `(char ,r ,(car z))) 67 | (t `(of (elt ,r ,i) ,@z)))) 68 | 69 | 70 | (defun lassoc (x l eq) 71 | (declare (list l)) 72 | (assoc x l :test eq)) 73 | 74 | (defun lmember (x l eq) 75 | (declare (list l)) 76 | (member x l :test eq)) 77 | 78 | (defun string-prefix? (s1 s2 i) 79 | (declare (string s1 s2) (integer i)) 80 | (string= s1 s2 :end1 i :end2 i)) 81 | 82 | (defun string-position-right (c s) 83 | (declare (character c) (string s)) 84 | (position c s :test #'char= :from-end t)) 85 | 86 | (defun basename (f) 87 | (let ((f (file-namestring (merge-pathnames 88 | (make-pathname :type "x") f)))) 89 | (subseq f 0 (- (length f) 2)))) 90 | 91 | (defun ignore2 (i ii) 92 | (declare (ignore i ii)) 93 | (values)) 94 | 95 | ;(scmxlate-rename 96 | ; (ignore2 #'ignore2) 97 | ; ) 98 | 99 | (scmxlate-postprocess 100 | (defvar *cl-command-name* "lisp") 101 | 102 | 103 | #+clisp 104 | (setq *cl-command-name* "clisp -q") 105 | 106 | #+clisp 107 | (defun system (s) 108 | (shell s)) 109 | 110 | (if (probe-file "slatex.scm") 111 | (delete-file "slatex.scm")) 112 | 113 | (rename-file "my-slatex-src.scm" "slatex.scm") 114 | 115 | 116 | 117 | #+unix 118 | (with-open-file (o "slatex" :direction :output 119 | :if-exists :supersede) 120 | (format o "echo '~%") 121 | (format o "(load ~s)~%" (or *target-file* "slatex.scm")) 122 | (format o "(slatex::process-main-tex-file \"'$1'\")' | ~a~%" 123 | *cl-command-name*) 124 | (format o "if test -f pltexchk.jnk~%") 125 | (format o "then tex $1; rm pltexchk.jnk~%") 126 | (format o "else latex $1~%") 127 | (format o "fi~%")) 128 | 129 | #+unix 130 | (system "chmod +x slatex") 131 | 132 | #+win32 133 | (with-open-file (o "slatex.bat" :direction :output 134 | :if-exists :supersede) 135 | (format o "@echo off~%") 136 | (format o "echo (load ~s) >> Zslatex.jnk~%" *target-file*) 137 | (format o "echo (slatex::process-main-tex-file \"%1\") >> Zslatex.jnk~%") 138 | (format o "echo (load \"Zslatex.jnk\") | ~a~%" *cl-command-name*) 139 | (format o "del Zslatex.jnk~%") 140 | (format o "if exist pltexchk.jnk goto one~%") 141 | (format o "goto two~%") 142 | (format o ":one~%") 143 | (format o "call tex %1~%") 144 | (format o "del pltexchk.jnk~%") 145 | (format o "goto end~%") 146 | (format o ":two~%") 147 | (format o "call latex %1~%") 148 | (format o ":end~%")) 149 | 150 | (with-open-file 151 | (o "callsla.scm" :direction :output) 152 | (prin1 `(let ((already-loaded-p nil)) 153 | (defun call-slatex (f) 154 | (unless already-loaded-p 155 | (load ,(or *target-file* "slatex.scm")) 156 | (setq already-loaded-p t)) 157 | (slatex::process-main-tex-file f) 158 | (format t "Call (La)TeX on ~a now~%" f) 159 | )) o) 160 | (terpri o)) 161 | ) 162 | -------------------------------------------------------------------------------- /latex/slatex/dialects/dialects-supported.scm: -------------------------------------------------------------------------------- 1 | bigloo 2 | chez 3 | gambit 4 | guile 5 | mitscheme 6 | mzscheme 7 | petite 8 | plt 9 | scsh 10 | sxm 11 | umbscheme 12 | -------------------------------------------------------------------------------- /latex/slatex/dialects/files-to-be-ported.scm: -------------------------------------------------------------------------------- 1 | slatex-src.scm 2 | -------------------------------------------------------------------------------- /latex/slatex/dialects/gambit-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-eval 2 | (define system ##shell-command) 3 | ) 4 | 5 | (scmxlate-include "make-qualified-names.scm") 6 | 7 | (scmxlate-rename 8 | (system ##shell-command) 9 | ) 10 | 11 | (scmxlate-cond 12 | ((eqv? *operating-system* 'unix) 13 | (define delete-file 14 | (lambda (f) 15 | (##shell-command (string-append "rm " f)))) 16 | )) 17 | 18 | (define append! 19 | (lambda (s1 s2) 20 | ;destructively append lists s1 and s2; 21 | ;only two args supported because that's 22 | ;enough for our purposes here 23 | (cond ((null? s1) s2) 24 | ((null? s2) s1) 25 | (else (let loop ((s1 s1)) 26 | (if (null? (cdr s1)) 27 | (set-cdr! s1 s2) 28 | (loop (cdr s1)))) 29 | s1)))) 30 | 31 | (define reverse! 32 | (lambda (s) 33 | ;reverses list s inplace (i.e., destructively) 34 | (let loop ((s s) (r '())) 35 | (if (null? s) r 36 | (let ((d (cdr s))) 37 | (set-cdr! s r) 38 | (loop d s)))))) 39 | 40 | (define-macro fluid-let 41 | (lambda (xvxv . ee) 42 | (let ((xx (map car xvxv)) 43 | (vv (map cadr xvxv)) 44 | (old-xx (map (lambda (xv) 45 | (string->symbol 46 | (string-append "%__" 47 | (symbol->string (car xv))))) xvxv)) 48 | (res '%_*_res)) 49 | `(let ,(map (lambda (old-x x) `(,old-x ,x)) old-xx xx) 50 | ,@(map (lambda (x v) 51 | `(set! ,x ,v)) xx vv) 52 | (let ((,res (begin ,@ee))) 53 | ,@(map (lambda (x old-x) `(set! ,x ,old-x)) xx old-xx) 54 | ,res))))) 55 | 56 | (scmxlate-postprocess 57 | 58 | (define *scheme-command-name* "gsi") 59 | 60 | (load "dialects/make-echo-script.scm") 61 | ) 62 | -------------------------------------------------------------------------------- /latex/slatex/dialects/guile-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-include "make-qualified-names.scm") 2 | 3 | (define void 4 | (lambda () 5 | (if #f #f))) 6 | 7 | (define-macro fluid-let 8 | (lambda (xvxv . ee) 9 | (let ((xx (map car xvxv)) 10 | (vv (map cadr xvxv)) 11 | (old-xx (map (lambda (xv) 12 | (string->symbol 13 | (string-append "%__" 14 | (symbol->string (car xv))))) xvxv)) 15 | (res '%_*_res)) 16 | `(let ,(map (lambda (old-x x) `(,old-x ,x)) old-xx xx) 17 | ,@(map (lambda (x v) 18 | `(set! ,x ,v)) xx vv) 19 | (let ((,res (begin ,@ee))) 20 | ,@(map (lambda (x old-x) `(set! ,x ,old-x)) xx old-xx) 21 | ,res))))) 22 | 23 | (scmxlate-cond 24 | ((eqv? *operating-system* 'unix) 25 | (scmxlate-postprocess 26 | (define *scheme-command-name* "guile") 27 | (load "dialects/make-echo-script.scm")))) 28 | -------------------------------------------------------------------------------- /latex/slatex/dialects/make-callsla.scm: -------------------------------------------------------------------------------- 1 | (call-with-output-file "callsla.scm" 2 | (lambda (o) 3 | (write `(define call-slatex 4 | (let ((already-loaded? #f)) 5 | (lambda (f) 6 | (if (not already-loaded?) 7 | (begin 8 | (load ,(or *target-file* 9 | "slatex.scm")) 10 | (set! already-loaded? #t))) 11 | (slatex::process-main-tex-file f) 12 | (display "Call (La)TeX on ") 13 | (display f) 14 | (display " now") 15 | (newline) 16 | ))) 17 | o) 18 | (newline o))) 19 | 20 | -------------------------------------------------------------------------------- /latex/slatex/dialects/make-echo-script.scm: -------------------------------------------------------------------------------- 1 | (case *dialect* 2 | ((scsh) 3 | (rename-file "my-slatex-src.scm" "slatex.scm") 4 | (delete-file "slatex") 5 | (delete-file "callsla.scm")) 6 | (else 7 | (system "mv my-slatex-src.scm slatex.scm") 8 | (system "rm -f slatex callsla.scm"))) 9 | 10 | 11 | (load "dialects/make-callsla.scm") 12 | 13 | (call-with-output-file "slatex" 14 | (lambda (o) 15 | (display "echo '" o) (newline o) 16 | (display "(load " o) 17 | (write (or *target-file* "slatex.scm") o) 18 | (display ")" o) (newline o) 19 | (display ";check pathname above is correct for you" o) 20 | (newline o) 21 | (display "(slatex" o) 22 | (display (if (eqv? *dialect* 'bigloo) 23 | "$$" 24 | "::") o) 25 | (display "process-main-tex-file \"'$1'\")" o) 26 | (if (eqv? *dialect* 'scsh) 27 | (begin 28 | (newline o) 29 | (display "(exit)" o))) 30 | (display "' | " o) 31 | (display *scheme-command-name* o) 32 | (newline o) 33 | (display "if test -f pltexchk.jnk" o) (newline o) 34 | (display "then tex $1; rm pltexchk.jnk" o) (newline o) 35 | (display "else latex $1" o) (newline o) 36 | (display "fi" o) (newline o))) 37 | 38 | (case *dialect* 39 | ((scsh) (run (chmod "+x" slatex))) 40 | (else (system "chmod +x slatex"))) 41 | 42 | -------------------------------------------------------------------------------- /latex/slatex/dialects/make-qualified-names.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-prefix 2 | (if (eqv? *dialect* 'bigloo) 3 | "slatex$$" 4 | "slatex::") 5 | *slatex-version* 6 | *operating-system* 7 | defenum 8 | defrecord 9 | setf 10 | the-setter-for-of 11 | of 12 | ormapcdr 13 | list-prefix? 14 | string-suffix? 15 | mapcan 16 | lassoc 17 | lmember 18 | delete 19 | adjoin 20 | delete-if 21 | string-prefix? 22 | sublist 23 | position-char 24 | string-position-right 25 | *return* 26 | *tab* 27 | slatex-error 28 | exit-slatex 29 | *slatex-case-sensitive?* 30 | keyword-tokens 31 | variable-tokens 32 | constant-tokens 33 | data-tokens 34 | special-symbols 35 | macro-definers 36 | case-and-ilk 37 | tex-analog 38 | token=? 39 | *slatex-enabled?* 40 | *slatex-reenabler* 41 | *intext-triggerers* 42 | *resultintext-triggerers* 43 | *display-triggerers* 44 | *response-triggerers* 45 | *respbox-triggerers* 46 | *box-triggerers* 47 | *topbox-triggerers* 48 | *input-triggerers* 49 | *region-triggerers* 50 | *math-triggerers* 51 | *slatex-in-protected-region?* 52 | *protected-files* 53 | *include-onlys* 54 | *latex?* 55 | *slatex-separate-includes?* 56 | *tex-calling-directory* 57 | *max-line-length* 58 | make-raw-line 59 | =rtedge 60 | =char 61 | =space 62 | =tab 63 | =notab 64 | make-line 65 | *line1* 66 | *line2* 67 | make-case-frame 68 | =in-ctag-tkn 69 | =in-bktd-ctag-exp 70 | =in-case-exp 71 | make-bq-frame 72 | =in-comma 73 | =in-bq-tkn 74 | =in-bktd-bq-exp 75 | *latex-paragraph-mode?* 76 | *intext?* 77 | *code-env-spec* 78 | *in* 79 | *out* 80 | *in-qtd-tkn* 81 | *in-bktd-qtd-exp* 82 | *in-mac-tkn* 83 | *in-bktd-mac-exp* 84 | *case-stack* 85 | *bq-stack* 86 | display-space 87 | display-tab 88 | display-notab 89 | prim-data-token? 90 | set-keyword 91 | set-constant 92 | set-variable 93 | set-data 94 | set-special-symbol 95 | unset-special-symbol 96 | texify 97 | texify-data 98 | texify-aux 99 | display-begin-sequence 100 | display-end-sequence 101 | display-tex-char 102 | display-token 103 | get-line 104 | peephole-adjust 105 | add-some-tabs 106 | remove-some-tabs 107 | clean-init-spaces 108 | clean-inner-spaces 109 | blank-line? 110 | flush-comment-line? 111 | display-tex-line 112 | display-scm-line 113 | do-all-lines 114 | scheme2tex 115 | do-token 116 | output-token 117 | directory-namestring 118 | basename 119 | *texinputs* 120 | *texinputs-list* 121 | *path-separator* 122 | *directory-mark* 123 | *directory-mark-string* 124 | *file-hider* 125 | path-to-list 126 | find-some-file 127 | file-extension 128 | full-texfile-name 129 | full-styfile-name 130 | full-clsfile-name 131 | full-scmfile-name 132 | subjobname 133 | primary-aux-file-count 134 | new-primary-aux-file 135 | new-secondary-aux-file 136 | new-aux-file 137 | eat-till-newline 138 | read-ctrl-seq 139 | eat-tabspace 140 | eat-whitespace 141 | eat-tex-whitespace 142 | chop-off-whitespace 143 | read-grouped-latexexp 144 | read-filename 145 | read-schemeid 146 | read-delimed-commaed-filenames 147 | read-grouped-commaed-filenames 148 | read-bktd-commaed-filenames 149 | read-grouped-schemeids 150 | eat-delimed-text 151 | eat-bktd-text 152 | eat-grouped-text 153 | ignore2 154 | disable-slatex-temply 155 | enable-slatex-again 156 | add-to-slatex-db 157 | add-to-slatex-db-basic 158 | add-to-slatex-db-special 159 | process-slatex-alias 160 | decide-latex-or-tex 161 | process-include-only 162 | process-documentstyle 163 | process-documentclass 164 | process-case-info 165 | seen-first-command? 166 | process-main-tex-file 167 | dump-intext 168 | dump-display 169 | debug? 170 | process-tex-file 171 | process-scheme-file 172 | trigger-scheme2tex 173 | trigger-region 174 | inline-protected-files 175 | inline-protected 176 | ) 177 | -------------------------------------------------------------------------------- /latex/slatex/dialects/mitscheme-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-postprocess 2 | (define *scheme-command-name* "scheme") 3 | 4 | (load "dialects/make-echo-script.scm") 5 | 6 | ) 7 | -------------------------------------------------------------------------------- /latex/slatex/dialects/mzscheme-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-include "make-qualified-names.scm") 2 | 3 | (scmxlate-cond 4 | ((eqv? *operating-system* 'unix) 5 | (scmxlate-postprocess 6 | (define *scheme-command-name* "mzscheme") 7 | (load "dialects/make-echo-script.scm") 8 | ))) 9 | -------------------------------------------------------------------------------- /latex/slatex/dialects/operating-systems-supported.scm: -------------------------------------------------------------------------------- 1 | unix 2 | windows 3 | -------------------------------------------------------------------------------- /latex/slatex/dialects/other-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-include "make-qualified-names.scm") 2 | 3 | (define file-exists? 4 | (lambda (f) #t)) 5 | 6 | (define delete-file 7 | (lambda (f) 8 | #t)) 9 | 10 | (define force-output 11 | (lambda z 12 | #t)) 13 | -------------------------------------------------------------------------------- /latex/slatex/dialects/petite-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-include "chez-slatex-src.scm") 2 | -------------------------------------------------------------------------------- /latex/slatex/dialects/plt-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-insert 2 | "(module slatex mzscheme 3 | (provide slatex::process-main-tex-file) 4 | " ;) 5 | ) 6 | 7 | (scmxlate-include "make-qualified-names.scm") 8 | 9 | (define-syntax setf 10 | (lambda (so) 11 | (datum->syntax-object so 12 | (let ((so-d (syntax-object->datum so))) 13 | (let ((l (cadr so-d)) 14 | (r (caddr so-d))) 15 | (if (symbol? l) `(set! ,l ,r) 16 | (let ((a (car l))) 17 | (if (eq? a 'list-ref) 18 | `(set-car! (list-tail ,@(cdr l)) ,r) 19 | `(,(cond ((eq? a 'string-ref) 'string-set!) 20 | ((eq? a 'vector-ref) 'vector-set!) 21 | ((eq? a 'of) 'the-setter-for-of) 22 | (else 23 | (error "setf ~s ~s is ill-formed~%" l r))) 24 | ,@(cdr l) ,r))))))))) 25 | 26 | (scmxlate-postamble) 27 | 28 | (scmxlate-insert 29 | ;( 30 | ") 31 | " 32 | ) 33 | 34 | (scmxlate-cond 35 | ((eqv? *operating-system* 'unix) 36 | (scmxlate-postprocess 37 | (define *scheme-command-name* "mzscheme") 38 | 39 | (system "mv my-slatex-src.scm slatex.ss") 40 | 41 | (printf "Generated module file slatex.ss~%") 42 | 43 | (system "rm -f slatex callsla.scm") 44 | 45 | (when *target-file* 46 | (let ((n (string-length *target-file*))) 47 | (when (and (>= n 4) (string=? (substring *target-file* (- n 4) n) ".scm")) 48 | (set! *target-file* 49 | (string-append (substring *target-file* 0 (- n 4)) ".ss"))))) 50 | 51 | (call-with-output-file "slatex" 52 | (lambda (o) 53 | (display "echo '" o) (newline o) 54 | (display "(require (file " o) 55 | (write (or *target-file* "slatex.ss") o) 56 | (display "))" o) (newline o) 57 | (display ";check pathname above is correct for you" o) 58 | (newline o) 59 | (display "(slatex::process-main-tex-file \"'$1'\")" o) 60 | (if (eqv? *dialect* 'scsh) 61 | (begin 62 | (newline o) 63 | (display "(exit)" o))) 64 | (display "' | " o) 65 | (display *scheme-command-name* o) 66 | (newline o) 67 | (display "if test -f pltexchk.jnk" o) (newline o) 68 | (display "then tex $1; rm pltexchk.jnk" o) (newline o) 69 | (display "else latex $1" o) (newline o) 70 | (display "fi" o) (newline o))) 71 | 72 | (system "chmod +x slatex") 73 | 74 | ))) 75 | -------------------------------------------------------------------------------- /latex/slatex/dialects/scm-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-postprocess 2 | (define *scheme-command-name* "scm") 3 | 4 | (load "dialects/make-echo-script.scm") 5 | ) 6 | 7 | -------------------------------------------------------------------------------- /latex/slatex/dialects/scsh-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-include "make-qualified-names.scm") 2 | 3 | (define *int-corresp-to-nul* 4 | (- (char->integer #\a) 97)) 5 | 6 | (define scsh-int-to-char 7 | (lambda (n) 8 | (integer->char 9 | (+ n *int-corresp-to-nul*)))) 10 | 11 | (define scsh-char-to-int 12 | (lambda (c) 13 | (- (char->integer c) 14 | *int-corresp-to-nul*))) 15 | 16 | (scmxlate-rename 17 | (integer->char scsh-int-to-char) 18 | (char->integer scsh-char-to-int)) 19 | 20 | 21 | (define-macro fluid-let 22 | (lambda (xvxv . ee) 23 | (let ((xx (map car xvxv)) 24 | (vv (map cadr xvxv)) 25 | (old-xx (map (lambda (xv) 26 | (string->symbol 27 | (string-append "%__" 28 | (symbol->string (car xv))))) xvxv)) 29 | (res '%_*_res)) 30 | `(let ,(map (lambda (old-x x) `(,old-x ,x)) old-xx xx) 31 | ,@(map (lambda (x v) 32 | `(set! ,x ,v)) xx vv) 33 | (let ((,res (begin ,@ee))) 34 | ,@(map (lambda (x old-x) `(set! ,x ,old-x)) xx old-xx) 35 | ,res))))) 36 | 37 | (define void 38 | (lambda () 39 | (if #f #f))) 40 | 41 | (define flush-output force-output) 42 | 43 | (scmxlate-cond 44 | ((eqv? *operating-system* 'unix) 45 | (scmxlate-postprocess 46 | (define *scheme-command-name* "scsh") 47 | 48 | (load "dialects/make-echo-script.scm") 49 | ))) 50 | 51 | -------------------------------------------------------------------------------- /latex/slatex/dialects/sxm-slatex-src.scm: -------------------------------------------------------------------------------- 1 | ;sxm issues warnings for forward-references, 2 | ;which can't all be removed anyway 3 | 4 | (warning-handler (lambda zzz #f)) 5 | 6 | (scmxlate-include "make-qualified-names.scm") 7 | 8 | (scmxlate-rename 9 | (flush-output flush-output-port) 10 | ) 11 | 12 | (scmxlate-cond 13 | ((eqv? *operating-system* 'unix) 14 | (scmxlate-postprocess 15 | (define *scheme-command-name* "sxi") 16 | (load "dialects/make-echo-script.scm")))) 17 | 18 | -------------------------------------------------------------------------------- /latex/slatex/dialects/umbscheme-slatex-src.scm: -------------------------------------------------------------------------------- 1 | (scmxlate-include "make-qualified-names.scm") 2 | 3 | (define *operating-system* 'unix) 4 | 5 | (define append! 6 | (lambda (s1 s2) 7 | ;destructively append lists s1 and s2; 8 | ;only two args supported because that's 9 | ;enough for our purposes here 10 | (cond ((null? s1) s2) 11 | ((null? s2) s1) 12 | (else (let loop ((s1 s1)) 13 | (if (null? (cdr s1)) 14 | (set-cdr! s1 s2) 15 | (loop (cdr s1)))) 16 | s1)))) 17 | 18 | (define reverse! 19 | (lambda (s) 20 | ;reverses list s inplace (i.e., destructively) 21 | (let loop ((s s) (r '())) 22 | (if (null? s) r 23 | (let ((d (cdr s))) 24 | (set-cdr! s r) 25 | (loop d s)))))) 26 | 27 | (defmacro fluid-let (xvxv . ee) 28 | (let ((xx (map car xvxv)) 29 | (vv (map cadr xvxv)) 30 | (old-xx (map (lambda (xv) 31 | (string->symbol 32 | (string-append "%__" 33 | (symbol->string (car xv))))) xvxv)) 34 | (res '%_*_res)) 35 | `(let ,(map (lambda (old-x x) `(,old-x ,x)) old-xx xx) 36 | ,@(map (lambda (x v) 37 | `(set! ,x ,v)) xx vv) 38 | (let ((,res (begin ,@ee))) 39 | ,@(map (lambda (x old-x) `(set! ,x ,old-x)) xx old-xx) 40 | ,res)))) 41 | 42 | (scmxlate-cond 43 | ((eqv? *operating-system* 'unix) 44 | (scmxlate-postprocess 45 | (define *scheme-command-name* "umb-scheme") 46 | 47 | (load "dialects/make-echo-script.scm") 48 | ))) 49 | -------------------------------------------------------------------------------- /latex/slatex/history: -------------------------------------------------------------------------------- 1 | Sept 30, 2009 2 | 3 | \schemecodehook should affect only displays, not in-text code. Phil 4 | Bewig. 5 | 6 | Sept 28, 2009 7 | 8 | datum->syntax etc spelling changes. Phil Bewig. 9 | 10 | June 9, 2005 11 | 12 | \dq redefined to include \tt or \ttfamily. John Clements. 13 | 14 | Bump *max-line-length* to 300 (from 200). John Clements. 15 | 16 | 2.4z2a 17 | 18 | Nov 23, 2002 19 | 20 | Updated scmxlate confign. 21 | 22 | 2.4z2 23 | 24 | Nov 1, 2002 25 | 26 | Dialect `plt' creates slatex module (as opposed to 27 | dialect `mzscheme', which just creates a file of 28 | definitions). (John Clements) 29 | 30 | For `plt' module to work, setf macro shouldn't rely on 31 | slatex-error at expansion-time. (John Clements) 32 | 33 | slatex.sty message modification to allow for 34 | version disparity between slatex.sty (TeX code) and 35 | slatex.scm (Scheme code). (John Clements) 36 | 37 | 2.4z1 38 | 39 | Oct 31, 2002 40 | 41 | Replaced define-macro by define-syntax 42 | 43 | Oct 28, 2002 44 | 45 | Added missing \enableslatex in slatxdoc.tex 46 | 47 | 2.4z 48 | 49 | Mar 17, 2002 50 | 51 | Modernize configuration to be more in line 52 | with my other programs (tex2page, etc). 53 | 54 | Port to scsh, sxm. petite == chez. 55 | 56 | 2.4y3 57 | 58 | Mar 2, 2002 59 | 60 | Use \CR instead of \cr in \m@ketabbox defn because it 61 | appears to somehow (how?) clash with LaTeX's 62 | {tabular}. Based on bug report by Greg Sullivan 63 | showing that {schemebox} inside a {tabular} was 64 | erroring. 65 | 66 | 2.4y2 67 | 68 | Dec 24, 2001 69 | 70 | Make full SLaTeX doc online-browsable. 71 | 72 | Dec 23, 2001 73 | 74 | Accept MzScheme v200 (in addition to previous 75 | versions). 76 | 77 | Nov 10, 2001 78 | 79 | \+ in slatex.sty clashing with url.sty. Reported by 80 | Francois-Rene Rideau. Corrected by changing \+ to 81 | \tabalignaux. 82 | 83 | 2.4y1 84 | 85 | Feb 19, 2001 86 | 87 | \ZZZZinput definition fixed so that 88 | reasonable redefinitions of \input won't 89 | cause it to fail. 90 | 91 | 2.4y 92 | 93 | Dec 23, 2000 94 | 95 | Opening string " at the very end of a line caused 96 | problems. Problem reported by Matthias Felleisen 97 | (PLT bug number 1802) 98 | 99 | 2.4x 100 | 101 | Feb 19, 2000 102 | 103 | {schemetopbox}, like {schemebox} but aligns 104 | them using their tops. Code added by 105 | John Brinckerhoff Clements and Robby Findler. 106 | 107 | 2.4w 108 | 109 | 9 Oct 1999 110 | 111 | Read cr before lf when reading files on Windows (Shriram report) 112 | 113 | Token delimitation strengthened (John Clements bug 114 | report). 115 | 116 | CL set-dispatch-macro-character arg should be uppercase 117 | character because CLISP doesn't automatically upcase 118 | it as standard suggests 119 | 120 | 2.4v 121 | 122 | 8 Mar 1999 123 | 124 | Comma'd forms inside backquote should get the right font 125 | assignment even if preceded by quote. (Shriram bug report) 126 | 127 | 2.4u 128 | 129 | 15 Jan 1999 130 | 131 | Use require-library instead of reference-library. 132 | 133 | pathproc.scm: *path-separator*, *directory-mark*, 134 | *file-hider* have approp values for OS = Windows. 135 | 136 | MzScheme/Win95 slatex.bat should contain Windows-style 137 | line termination. 138 | 139 | Config file for CLISP on Win 95. 140 | 141 | Jun 8, 1998 142 | 143 | 2.4t 144 | 145 | distribution mishap fix 146 | 147 | May 1, 1998 148 | 149 | 2.4s 150 | 151 | Port to STk 152 | 153 | Apr 21, 1998 154 | 155 | 2.4r 156 | 157 | Port to Allegro Common Lisp for Linux. Minor config 158 | bugs nixed. 159 | 160 | Apr 1998 161 | 162 | 2.4q 163 | 164 | Ports to Windows 95, Gambit, MIT Scheme. 165 | 166 | Apr 1997 167 | 168 | 2.4 p 169 | 170 | {schemeregion} should not collapse lines with TeX comments 171 | into one (nor should it eat the comment character). 172 | 173 | v. 2.4o 174 | 175 | Fixed indentation bug caused by implicit space after \\ 176 | in tab environment. 177 | 178 | Feb 1997 179 | v. 2.4n 180 | 181 | Fixed bug that caused \begin{schemebox} to produce space at 182 | paragraph begin (Matthias Felleisen). 183 | 184 | Ported to Bigloo, thanks to Christian Queinnec. 185 | 186 | * typesets as \ast. (* "as is" is too high.) 187 | 188 | Ported to Guile. 189 | 190 | May 1996 191 | v 2.4m 192 | 193 | Ported to MzScheme. 194 | 195 | Check that config.dat has right number of answers. 196 | Eliminates common typos while setting up config.dat 197 | (Shriram's sugg.). 198 | 199 | Accommodate Schemes that allow loading of files mentioned on 200 | the command-line, but using an option such as -load or -f 201 | (Shriram's sugg). 202 | 203 | Changed names in preproc.scm to avoid collision with 204 | existing Scheme procs, if any. (Shriram Krishnamurthi's 205 | idea.) 206 | 207 | Ported to GCL (Linux). 208 | Changes to package system -- uses CL's package sys in CL. 209 | dump-display made more efficient. 210 | Cleaned up bat config. 211 | 212 | Feb 1996 213 | v 2.4l 214 | 215 | Ported to Macintosh Common Lisp. 216 | 217 | Version number reported on invocation and whilst loading 218 | slatex.sty (to enable trenchant bug reporting). 219 | 220 | No longer requires "system" procedure spec from user via 221 | config.dat. Other config info should be sufficient to 222 | deduce this. One less confusion. 223 | 224 | v 2.4k 225 | 226 | -- and --- in Scheme tokens are treated as minuses rather 227 | than en- and em-dash. Mike Ernst's idea. 228 | 229 | v 2.4j 230 | 231 | Now recognizes :keywords as data in CL. 232 | 233 | Left margin error in indented {schemedisplay}s corrected 234 | 235 | Package system made more robust 236 | 237 | Apr 1995 238 | v 2.4 239 | Support for OS/2, both FAT and HPFS. 240 | 241 | Included sample Rexx script (for OS/2 + emTeX + scm) 242 | that has robust TEXINPUT recognition. 243 | 244 | Fixed paragraph indentation bug after {schemedisplay} 245 | within {schemeregion}. 246 | 247 | Recognizes LaTeX2e files in addition to LaTeX2.09. 248 | 249 | Sentence-ending space doesn't follow null?, set!, etc. 250 | 251 | Documentation converted to plain TeX. 252 | 253 | Added {schemeresponse}, {schemeresponsebox}, and their 254 | corresponding \defscheme*token and \undefscheme*token. 255 | 256 | Fixed bug related to quoted special symbols; 257 | quoted math escapes; and quoted strings. 258 | 259 | Added \setdata in analogy with \setkeyword, 260 | \setvariable, and \setconstant. 261 | \schemeresult, etc., distinguish between constant and 262 | data -- data items are set in \datafont; everything 263 | else in \constantfont. 264 | 265 | Removed bogus \ignorespaces from \slatexdisable. 266 | 267 | Typeset code is now frenchspaced (instead of using 268 | \null's) to avoid sentence-ending spaces after ! and ?. 269 | Mark Krentel's idea. 270 | 271 | Added config code for Matthias Blume's VSCM. 272 | 273 | Jan 1994 274 | v 2.3 275 | 276 | The Dark Years 277 | Several bug fixes 278 | 279 | Dec 1991 280 | First major update 281 | 282 | Mar 1991 283 | First public release 284 | 285 | 1990 286 | First Rice PLT release 287 | -------------------------------------------------------------------------------- /latex/slatex/makefile: -------------------------------------------------------------------------------- 1 | clean: 2 | rm -f *~ *.bak 3 | cd dialects; rm -f *~ *.bak 4 | -------------------------------------------------------------------------------- /latex/slatex/manifest: -------------------------------------------------------------------------------- 1 | ;manifest 2 | ;SLaTeX Version 2.4 3 | ;List of files provided in the SLaTeX distribution 4 | ;(c) Dorai Sitaram 5 | ;ds26@gte.com 6 | 7 | COPYING 8 | README 9 | INSTALL 10 | history 11 | manifest 12 | version.tex 13 | makefile 14 | 15 | ;documentation 16 | slatxdoc.tex 17 | slatxdoc.bib 18 | slatxdoc.t2p 19 | 20 | tex2page.tex 21 | defun.tex 22 | 23 | ;style files 24 | slatex.sty 25 | cltl.sty 26 | 27 | slatex-src.scm 28 | 29 | ;configure 30 | scmxlate-slatex-src.scm 31 | dialects/*.scm 32 | -------------------------------------------------------------------------------- /latex/slatex/scmxlate-slatex-src.scm: -------------------------------------------------------------------------------- 1 | ;The argument of scmxlate-target-file is the full 2 | ;pathname you intend to give to the generated 3 | ;slatex.scm file. Supply it as a Scheme (or Common 4 | ;Lisp) string. Note that initially the configuration 5 | ;process will produce slatex.scm in the current 6 | ;directory. You will then have to move it (possibly 7 | ;after assuming root status) to the path you mention 8 | ;here. 9 | 10 | ;Slashification note for Windows users: In general, 11 | ;Scheme (or CL) dialects on these OSes accept 12 | ;Unix-style pathnames. But if they don't, you will 13 | ;have to use the backslash (\) where on Unix you'd use 14 | ;the forward slash (/). When rendering such pathnames 15 | ;as Scheme strings, you will have to use escapes. 16 | 17 | (scmxlate-eval 18 | ;on denali 19 | ;(define *target-file* "/home/dorai/.www/slatex/slatex.scm") 20 | 21 | ;on mac 22 | (define *target-file* "~/latex/slatex/slatex.scm") 23 | ) 24 | 25 | ;You may define slatex::*texinputs* here. Eg, 26 | 27 | 28 | ;(define slatex::*texinputs* "c:/bin;c:/lib/emtex/texinput") ;Windows 29 | 30 | ;(define slatex::*texinputs* 31 | ;"/home/dorai/tex:/usr/local/lib/tex/macros") ;in Unix 32 | 33 | ;(define slatex::*texinputs* (getenv "TEXINPUTS")) 34 | 35 | ;Unfortunately, that last one is not really as convenient as 36 | ;it seems, even if your Scheme has a getenv procedure. 37 | ;This is because the TEXINPUTS uses abbreviations that may 38 | ;not be readily translatable into a list of directories 39 | ;by Scheme. 40 | 41 | ;Luckily, normal ppl never rely on TEXINPUTS to retrieve 42 | ;their document files (as opposed to style files). Thus, 43 | ;not setting slatex::*texinputs* (or setting it to the emptry 44 | ;string, as I have done here) is probably quite OK. 45 | 46 | ;NB: Use slatex$$*texinputs* instead of 47 | ;slatex::*texinputs* in Bigloo. 48 | 49 | ;on Bigloo 50 | ;(define slatex$$*texinputs* "") 51 | 52 | ;on non-Bigloo (including CL) 53 | ;(define slatex::*texinputs* "") 54 | 55 | ;compile? 56 | 57 | (scmxlate-compile #f) 58 | -------------------------------------------------------------------------------- /latex/slatex/slatex: -------------------------------------------------------------------------------- 1 | echo ' 2 | (load "~/latex/slatex/slatex.scm") 3 | ;check pathname above is correct for you 4 | (slatex::process-main-tex-file "'$1'")' | petite 5 | if test -f pltexchk.jnk 6 | then tex $1; rm pltexchk.jnk 7 | else latex $1 8 | fi 9 | -------------------------------------------------------------------------------- /latex/slatex/slatex.sty: -------------------------------------------------------------------------------- 1 | % slatex.sty 2 | % SLaTeX v. 2.4 3 | % style file to be used in (La)TeX when using SLaTeX 4 | % (c) Dorai Sitaram, Rice U., 1991, 1999 5 | 6 | \def\slatexversion{20090930} % last modified 7 | 8 | % This file (or a soft link to it) should be in some 9 | % directory in your TEXINPUTS path (i.e., the one 10 | % (La)TeX scours for \input or \documentstyle option 11 | % files). 12 | 13 | % Do not attempt to debug this file, since the results 14 | % are not transparent just to (La)TeX. The Scheme part 15 | % of SLaTeX depends on information laid out here -- so 16 | % (La)TeX-minded debugging of this file will almost 17 | % inevitably sabotage SLaTeX. 18 | 19 | % It's possible you don't find the default style set 20 | % out here appealing: e.g., you may want to change the 21 | % positioning of displayed code; change the fonts for 22 | % keywords, constants, and variables; add new keywords, 23 | % constants, and variables; use your names instead of 24 | % the provided \scheme, [\begin|\end]{schemedisplay}, 25 | % [\begin|\end]{schemebox}, (or \[end]schemedisplay, 26 | % \[end]schemebox for TeX), which might be seem too 27 | % long or unmnemonic, and many other things. The clean 28 | % way to do these things is outlined in the 29 | % accompanying manual, slatxdoc.tex. This way is both 30 | % easier than messing with this .sty file, and safer 31 | % since you will not unwittingly break SLaTeX. 32 | 33 | %%% 34 | 35 | % to prevent loading slatex.sty more than once 36 | 37 | \ifx\slatexignorecurrentfile\UNDEFINED 38 | \else\endinput\fi 39 | 40 | % use \slatexignorecurrentfile to disable slatex for 41 | % the current file. (Unstrangely, the very definition 42 | % disables slatex for the rest of _this_ file, slatex.sty.) 43 | 44 | \def\slatexignorecurrentfile{} 45 | 46 | % checking whether we're using LaTeX or TeX? 47 | 48 | \newif\ifusinglatex 49 | \ifx\newenvironment\UNDEFINED\usinglatexfalse\else\usinglatextrue\fi 50 | 51 | % make @ a letter for TeX 52 | \ifusinglatex\relax\else 53 | \edef\atcatcodebeforeslatex{\the\catcode`\@ } 54 | \catcode`\@11 55 | \fi 56 | 57 | % identification of TeX/LaTeX style for schemedisplay. 58 | % Do \defslatexenvstyle{tex} to get TeX environment 59 | % style in LaTeX 60 | \def\defslatexenvstyle#1{\gdef\slatexenvstyle{#1}} 61 | 62 | \ifusinglatex\defslatexenvstyle{latex}\else\defslatexenvstyle{tex}\fi 63 | 64 | % TeX doesn't have sans-serif; use roman instead 65 | \ifx\sf\UNDEFINED\let\sf\rm\fi 66 | 67 | % tabbing from plain TeX 68 | % 69 | \newif\ifus@ \newif\if@cr 70 | \newbox\tabs \newbox\tabsyet \newbox\tabsdone 71 | % 72 | \def\cleartabs{\global\setbox\tabsyet\null \setbox\tabs\null} 73 | \def\settabs{\setbox\tabs\null \futurelet\next\sett@b} 74 | \let\tabalignaux=\relax % in case this file is being read in twice 75 | \def\sett@b{\ifx\next\tabalignaux\let\next\relax 76 | \def\next{\afterassignment\s@tt@b\let\next}% 77 | \else\let\next\s@tcols\fi\next} 78 | \def\s@tt@b{\let\next\relax\us@false\m@ketabbox} 79 | \def\tabalign{\us@true\m@ketabbox} % non-\outer version of \tabalignaux 80 | \outer\def\tabalignaux{\tabalign} 81 | \def\s@tcols#1\columns{\count@#1 \dimen@\hsize 82 | \loop\ifnum\count@>\z@ \@nother \repeat} 83 | \def\@nother{\dimen@ii\dimen@ \divide\dimen@ii\count@ 84 | \setbox\tabs\hbox{\hbox to\dimen@ii{}\unhbox\tabs}% 85 | \advance\dimen@-\dimen@ii \advance\count@\m@ne} 86 | % 87 | \def\m@ketabbox{\begingroup 88 | \global\setbox\tabsyet\copy\tabs 89 | \global\setbox\tabsdone\null 90 | \def\CR{\@crtrue\crcr\egroup\egroup 91 | \ifus@\unvbox\z@\lastbox\fi\endgroup 92 | \setbox\tabs\hbox{\unhbox\tabsyet\unhbox\tabsdone}}% 93 | \setbox\z@\vbox\bgroup\@crfalse 94 | \ialign\bgroup&\t@bbox##\t@bb@x\crcr} 95 | % 96 | \def\t@bbox{\setbox\z@\hbox\bgroup} 97 | \def\t@bb@x{\if@cr\egroup % now \box\z@ holds the column 98 | \else\hss\egroup \global\setbox\tabsyet\hbox{\unhbox\tabsyet 99 | \global\setbox\@ne\lastbox}% now \box\@ne holds its size 100 | \ifvoid\@ne\global\setbox\@ne\hbox to\wd\z@{}% 101 | \else\setbox\z@\hbox to\wd\@ne{\unhbox\z@}\fi 102 | \global\setbox\tabsdone\hbox{\box\@ne\unhbox\tabsdone}\fi 103 | \box\z@} 104 | % finished (re)defining TeX's tabbing macros 105 | 106 | % above from plain.tex; was disabled in lplain.tex. Do 107 | % not modify above unless you really know what you're 108 | % up to. Make all changes you want to following code. 109 | % The new env is preferable to LaTeX's tabbing env 110 | % since latter accepts only a small number of tabs 111 | 112 | % following retrieves something like LaTeX's tabbing 113 | % env without the above problem (it also creates a box 114 | % for easy manipulation!) 115 | 116 | \def\lat@xtabbing{\begingroup 117 | \def\={\cleartabs&} \def\>{&}% 118 | \def\\{\CR\tabalign\lat@xtabbingleftmost}% 119 | \tabalign\lat@xtabbingleftmost} 120 | \def\endlat@xtabbing{\CR\endgroup} 121 | \let\lat@xtabbingleftmost\relax 122 | 123 | % stuff for formating Scheme code 124 | 125 | \newskip\par@nlen \newskip\brack@tlen \newskip\quot@len 126 | \newskip\h@lflambda 127 | 128 | \newbox\garb@ge 129 | \def\s@ttowidth#1#2{\setbox\garb@ge\hbox{#2}#1\wd\garb@ge\relax} 130 | 131 | \s@ttowidth\par@nlen{$($} % size of paren 132 | \s@ttowidth\brack@tlen{$[$} % size of bracket 133 | \s@ttowidth\quot@len{'} % size of quote indentation 134 | \s@ttowidth\h@lflambda{ii} % size of half of lambda indentation 135 | 136 | \def\PRN{\hskip\par@nlen} % these are used by SLaTeX's codesetter 137 | \def\BKT{\hskip\brack@tlen} 138 | \def\QUO{\hskip\quot@len} 139 | \def\HL{\hskip\h@lflambda} 140 | 141 | \newskip\abovecodeskip \newskip\belowcodeskip 142 | \newskip\leftcodeskip \newskip\rightcodeskip 143 | 144 | % the following default assignments give a flushleft 145 | % display 146 | 147 | \abovecodeskip=\medskipamount \belowcodeskip=\medskipamount 148 | \leftcodeskip=0pt \rightcodeskip=0pt 149 | 150 | % adjust above,below,left,right codeskip's to personal 151 | % taste 152 | 153 | % for centered displays 154 | % 155 | % \leftcodeskip=0pt plus 1fil 156 | % \rightcodeskip=0pt plus 1fil 157 | % 158 | % if \rightcodeskip != 0pt, pagebreaks within Scheme 159 | % blocks in {schemedisplay} are disabled 160 | 161 | \let\checkforfollpar1 162 | \def\noindentifnofollpar{\ifx\checkforfollpar0\let\next\relax 163 | \else\ifusinglatex\let\next\@endparenv 164 | \else\let\next\noindentifnofollparI\fi\fi\next} 165 | \def\noindentifnofollparI{\futurelet\next\noindentifnofollparII} 166 | \def\noindentifnofollparII{\ifx\next\par\else\noindent\ignorespaces\fi} 167 | 168 | % the following are the default font assignments for 169 | % words in code. Change them to suit personal taste 170 | 171 | \def\keywordfont#1{{\bf #1}} 172 | \def\variablefont#1{{\it #1\/}} 173 | \def\constantfont#1{{\sf #1}} 174 | \def\datafont#1{\constantfont{#1}} 175 | 176 | \let\schemecodehook\relax 177 | \let\ZZZZschemecodehook\relax 178 | 179 | %program listings that allow page breaks but 180 | %can't be centered 181 | 182 | \def\ZZZZschemedisplay{\edef\thez@skip{\the\z@skip}% 183 | \edef\@tempa{\the\rightcodeskip}% 184 | \ifx\@tempa\thez@skip\let\next\ZZZZschemeprogram 185 | \else\let\next\ZZZZschemeprogramII\fi\next} 186 | 187 | \def\endZZZZschemedisplay{\edef\thez@skip{\the\z@skip}% 188 | \edef\@tempa{\the\rightcodeskip}% 189 | \ifx\@tempa\thez@skip\let\next\endZZZZschemeprogram 190 | \else\let\next\endZZZZschemeprogramII\fi\next} 191 | 192 | \def\ZZZZschemeprogram{\vskip\abovecodeskip 193 | \begingroup 194 | \schemecodehook\ZZZZschemecodehook 195 | \frenchspacing 196 | \let\sy=\keywordfont \let\cn=\constantfont 197 | \let\va=\variablefont \let\dt=\datafont 198 | \def\lat@xtabbingleftmost{\hskip\leftskip\hskip\leftcodeskip\relax}% 199 | \lat@xtabbing} 200 | 201 | \def\endZZZZschemeprogram{\endlat@xtabbing 202 | \endgroup 203 | \vskip\belowcodeskip 204 | \noindentifnofollpar} 205 | 206 | \def\ZZZZschemeprogramII{\vskip\abovecodeskip 207 | \begingroup 208 | \noindent 209 | %\ZZZZschemecodehook\schemecodehook %\ZZZZschemebox already has it 210 | \hskip\leftcodeskip 211 | \ZZZZschemebox} 212 | 213 | \def\endZZZZschemeprogramII{\endZZZZschemebox 214 | \hskip\rightcodeskip 215 | \endgroup 216 | \vskip\belowcodeskip 217 | \noindentifnofollpar} 218 | 219 | \def\ZZZZschemeresponse{\ZZZZschemecodehookforresult 220 | \ZZZZschemedisplay} 221 | \let\endZZZZschemeresponse\endZZZZschemedisplay 222 | 223 | % 224 | 225 | \def\ZZZZschemebox{% 226 | \leavevmode\hbox\bgroup\vbox\bgroup 227 | \schemecodehook\ZZZZschemecodehook 228 | \frenchspacing 229 | \let\sy=\keywordfont \let\cn=\constantfont 230 | \let\va=\variablefont \let\dt=\datafont 231 | \lat@xtabbing} 232 | \def\endZZZZschemebox{\endlat@xtabbing 233 | \egroup\egroup\ignorespaces} 234 | 235 | % schemetopbox : added by robby/jbc 2000 236 | 237 | \def\ZZZZschemetopbox{% 238 | \leavevmode\hbox\bgroup\vtop\bgroup 239 | \schemecodehook\ZZZZschemecodehook 240 | \frenchspacing 241 | \let\sy=\keywordfont \let\cn=\constantfont 242 | \let\va=\variablefont \let\dt=\datafont 243 | \lat@xtabbing} 244 | \def\endZZZZschemetopbox{\endlat@xtabbing 245 | \egroup\egroup\ignorespaces} 246 | 247 | \def\ZZZZschemeresponsebox{\ZZZZschemecodehookforresult 248 | \ZZZZschemebox} 249 | \let\endZZZZschemeresponsebox\endZZZZschemebox 250 | 251 | %in-text 252 | 253 | \def\ZZZZschemecodeintext{\begingroup 254 | %\schemecodehook 255 | \ZZZZschemecodehook 256 | \frenchspacing 257 | \let\sy\keywordfont \let\cn\constantfont 258 | \let\va\variablefont \let\dt\datafont} 259 | 260 | \def\endZZZZschemecodeintext{\endgroup\ignorespaces} 261 | 262 | \def\ZZZZschemeresultintext{\ZZZZschemecodehookforresult 263 | \ZZZZschemecodeintext} 264 | 265 | \let\endZZZZschemeresultintext\endZZZZschemecodeintext 266 | 267 | % 268 | 269 | \def\ZZZZschemecodehookforresult{% 270 | \gdef\ZZZZschemecodehook{\let\keywordfont\constantfont 271 | \let\variablefont\constantfont 272 | \global\let\ZZZZschemecodehook\relax}} 273 | 274 | % \comm@nt...text... comments out 275 | % TeX source analogous to 276 | % \verb...text.... Sp. case: 277 | % \comm@nt{...text...} == \comm@nt}...text...} 278 | 279 | \def\@makeother#1{\catcode`#112\relax} 280 | 281 | \def\comm@nt{% 282 | \begingroup 283 | \let\do\@makeother \dospecials 284 | \@comm} 285 | 286 | \begingroup\catcode`\<1 \catcode`\>2 287 | \catcode`\{12 \catcode`\}12 288 | \long\gdef\@comm#1<% 289 | \if#1{\long\def\@tempa ##1}<\endgroup>\else 290 | \long\def\@tempa ##1#1<\endgroup>\fi 291 | \@tempa> 292 | \endgroup 293 | 294 | % like LaTeX2e's \InputIfFileExists 295 | 296 | \ifx\InputIfFileExists\UNDEFINED 297 | \def\InputIfFileExists#1#2#3{% 298 | \immediate\openin0=#1\relax 299 | \ifeof0\relax\immediate\closein0\relax#3% 300 | \else\immediate\closein0\relax#2\input#1\relax\fi}% 301 | \fi 302 | 303 | \def\ZZZZinput#1{\input#1 \relax} 304 | 305 | % you may replace the above by 306 | % 307 | % \def\ZZZZinput#1{\InputIfFileExists{#1}{}{}} 308 | % 309 | % if you just want to call (La)TeX on your text 310 | % ignoring the portions that need to be SLaTeX'ed 311 | 312 | %use \subjobname rather than \jobname to generate 313 | %slatex's temp files --- this allows us to change 314 | %\subjobname for more control, if necessary. 315 | 316 | \let\subjobname\jobname 317 | 318 | % counter for generating temp file names 319 | 320 | \newcount\sch@mefilenamecount 321 | \sch@mefilenamecount=-1 322 | 323 | % To produce displayed Scheme code: 324 | % in LaTeX: 325 | % \begin{schemedisplay} 326 | % ... indented program (with sev'l lines) ... 327 | % \end{schemedisplay} 328 | % 329 | % in TeX: 330 | % \schemedisplay 331 | % ... indented program (with sev'l lines) ... 332 | % \endschemedisplay 333 | 334 | \begingroup\catcode`\|=0 \catcode`\[=1 \catcode`\]=2 335 | \catcode`\{=12 \catcode`\}=12 \catcode`\\=12 336 | |gdef|defschemedisplaytoken#1[% 337 | |long|expandafter|gdef|csname ZZZZcomment#1|endcsname[% 338 | |begingroup 339 | |let|do|@makeother |dospecials 340 | |csname ZZZZcomment|slatexenvstyle II#1|endcsname]% 341 | |long|expandafter|gdef|csname ZZZZcommentlatexII#1|endcsname##1\end{#1}[% 342 | |endgroup|end[#1]]% 343 | |long|expandafter|gdef|csname ZZZZcommenttexII#1|endcsname##1\end#1[% 344 | |endgroup|csname end#1|endcsname]% 345 | |long|expandafter|gdef|csname #1|endcsname[% 346 | |csname ZZZZcomment#1|endcsname]% 347 | |long|expandafter|gdef|csname end#1|endcsname[% 348 | |global|advance|sch@mefilenamecount by 1 349 | |let|checkforfollpar0% 350 | |ZZZZinput[|filehider Z|number|sch@mefilenamecount|subjobname.tex]% 351 | |let|checkforfollpar1% 352 | |noindentifnofollpar]]% 353 | |endgroup 354 | 355 | \def\undefschemedisplaytoken#1{% 356 | \expandafter\gdef\csname#1\endcsname{\UNDEFINED}} 357 | 358 | % like {schemedisplay}, but displays output from a 359 | % Scheme evaluation. I.e., keywords and variables 360 | % appear in the data font 361 | 362 | \let\defschemeresponsetoken\defschemedisplaytoken 363 | \let\undefschemeresponsetoken\undefschemedisplaytoken 364 | 365 | % \scheme|...program fragment...| produces Scheme code 366 | % in-text. Sp. case: \scheme{...} == \scheme}...} 367 | 368 | \def\defschemetoken#1{% 369 | \long\expandafter\def\csname#1\endcsname{% 370 | \global\advance\sch@mefilenamecount by 1 371 | \ZZZZinput{\filehider Z\number\sch@mefilenamecount\subjobname.tex}% 372 | \comm@nt}} 373 | 374 | \let\undefschemetoken\undefschemedisplaytoken 375 | 376 | % \schemeresult|...program fragment...| produces a 377 | % Scheme code result in-text: i.e. keyword or variable 378 | % fonts are replaced by the data font. Sp. case: 379 | % \schemeresult{...} == \schemeresult}...} 380 | 381 | \let\defschemeresulttoken\defschemetoken 382 | \let\undefschemeresulttoken\undefschemetoken 383 | 384 | % To produce a box of Scheme code: 385 | % in LaTeX: 386 | % \begin{schemebox} 387 | % ... indented program (with sev'l lines) ... 388 | % \end{schemebox} 389 | % 390 | % in TeX: 391 | % \schemebox 392 | % ... indented program (with sev'l lines) ... 393 | % \endschemebox 394 | 395 | \begingroup\catcode`\|=0 \catcode`\[=1 \catcode`\]=2 396 | \catcode`\{=12 \catcode`\}=12 \catcode`\\=12 397 | |gdef|defschemeboxtoken#1[% 398 | |long|expandafter|gdef|csname ZZZZcomment#1|endcsname[% 399 | |begingroup 400 | |let|do|@makeother |dospecials 401 | |csname ZZZZcomment|slatexenvstyle II#1|endcsname]% 402 | |long|expandafter|gdef|csname ZZZZcommentlatexII#1|endcsname##1\end{#1}[% 403 | |endgroup|end[#1]]% 404 | |long|expandafter|gdef|csname ZZZZcommenttexII#1|endcsname##1\end#1[% 405 | |endgroup|csname end#1|endcsname]% 406 | |long|expandafter|gdef|csname #1|endcsname[% 407 | |global|advance|sch@mefilenamecount by 1 408 | |ZZZZinput[|filehider Z|number|sch@mefilenamecount|subjobname.tex]% 409 | |csname ZZZZcomment#1|endcsname]% 410 | |long|expandafter|gdef|csname end#1|endcsname[]]% 411 | |endgroup 412 | 413 | \let\undefschemeboxtoken\undefschemedisplaytoken 414 | 415 | % like {schemeresponse}, but in a box 416 | 417 | \let\defschemeresponseboxtoken\defschemeboxtoken 418 | \let\undefschemeresponseboxtoken\undefschemeboxtoken 419 | 420 | \let\defschemetopboxtoken\defschemeboxtoken 421 | \let\undefschemetopboxtoken\undefschemeboxtoken 422 | 423 | % for wholesale dumping of all-Scheme files into TeX (converting 424 | % .scm files to .tex), 425 | % use 426 | % \schemeinput{} 427 | % .scm, .ss, .s extensions optional 428 | 429 | \def\defschemeinputtoken#1{% 430 | \long\expandafter\gdef\csname#1\endcsname##1{% 431 | \global\advance\sch@mefilenamecount by 1 432 | \ZZZZinput{\filehider Z\number\sch@mefilenamecount\subjobname.tex}}} 433 | 434 | \def\undefschemeinputtoken#1{% 435 | \expandafter\gdef\csname#1\endcsname{\UNDEFINED}} 436 | 437 | % delineating a region that features typeset code 438 | % not usually needed, except when using \scheme and schemedisplay 439 | % inside macro-args and macro-definition-bodies 440 | % in LaTeX: 441 | % \begin{schemeregion} 442 | % ... 443 | % \end{schemeregion} 444 | % 445 | % in TeX: 446 | % \schemeregion 447 | % ... 448 | % \endschemeregion 449 | 450 | \let\defschemeregiontoken\defschemeboxtoken 451 | \let\undefschemeregiontoken\undefschemeboxtoken 452 | 453 | % the SLaTeX tokens 454 | 455 | \defschemedisplaytoken{schemedisplay} 456 | \defschemetoken{scheme} 457 | \defschemeboxtoken{schemebox} 458 | \defschemetopboxtoken{schemetopbox} 459 | \defschemeresulttoken{schemeresult} 460 | \defschemeresponsetoken{schemeresponse} 461 | \defschemeresponseboxtoken{schemeresponsebox} 462 | \defschemeinputtoken{schemeinput} 463 | \defschemeregiontoken{schemeregion} 464 | 465 | % introducing new code-tokens to the keyword, variable and constant 466 | % categories 467 | 468 | \def\comm@ntII{% 469 | \begingroup 470 | \let\do\@makeother \dospecials 471 | \@commII} 472 | 473 | \begingroup\catcode`\[1 \catcode`\]2 474 | \catcode`\{12 \catcode`\}12 475 | \long\gdef\@commII{[% 476 | \long\def\@tempa ##1}[\endgroup]\@tempa]% 477 | \endgroup 478 | 479 | \let\setkeyword\comm@ntII 480 | \let\setvariable\comm@ntII 481 | \let\setconstant\comm@ntII 482 | \let\setdata\comm@ntII 483 | 484 | % \defschememathescape makes the succeeding grouped character an 485 | % escape into latex math from within Scheme code; 486 | % this character can't be } 487 | 488 | \let\defschememathescape\comm@ntII 489 | \let\undefschememathescape\comm@ntII 490 | 491 | % telling SLaTeX that a certain Scheme identifier is to 492 | % be replaced by the specified LaTeX expression. 493 | % Useful for generating ``mathematical''-looking 494 | % typeset code even though the corresponding Scheme 495 | % code is ascii as usual and doesn't violate 496 | % identifier-naming rules 497 | 498 | \def\setspecialsymbol{% 499 | \begingroup 500 | \let\do\@makeother \dospecials 501 | \@commIII} 502 | 503 | \begingroup\catcode`\[1 \catcode`\]2 504 | \catcode`\{12 \catcode`\}12 505 | \long\gdef\@commIII{[% 506 | \long\def\@tempa ##1}[\endgroup\@gobbleI]\@tempa]% 507 | \endgroup 508 | 509 | \def\@gobbleI#1{} 510 | 511 | % \unsetspecialsymbol strips Scheme identifier(s) of 512 | % any ``mathematical'' look lent by the above 513 | 514 | \let\unsetspecialsymbol\comm@ntII 515 | 516 | % enabling/disabling slatex 517 | 518 | \def\slatexdisable#1{\expandafter\gdef\csname#1\endcsname{}} 519 | 520 | % \schemecasesensitive takes either true or false as 521 | % argument 522 | 523 | \def\schemecasesensitive#1{} 524 | 525 | %for latex only: use \slatexseparateincludes before the 526 | %occurrence of any Scheme code in your file, if you 527 | %want the various \include'd files to have their own 528 | %pool of temporary slatex files. This lets you juggle 529 | %your \include's in successive runs of LaTeX without 530 | %having to worry that the temp. files may interfere. 531 | %By default, only a single pool of temp files is used. 532 | %Warning: On DOS, if your \include'd files have fairly 533 | %similar names, avoid \slatexseparateincludes since the 534 | %short filenames on DOS will likely confuse the temp 535 | %file pools of different \include files. 536 | 537 | \def\slatexseparateincludes{% 538 | \gdef\include##1{{\def\subjobname{##1}% 539 | \sch@mefilenamecount=-1 540 | \@include##1 }}} 541 | 542 | % convenient abbreviations for characters 543 | 544 | \begingroup 545 | \catcode`\|=0 546 | |catcode`|\=12 547 | |gdef|ttbackslash{{|tt|catcode`|\=12 \}} 548 | |endgroup 549 | \mathchardef\lt="313C 550 | \mathchardef\gt="313E 551 | \begingroup 552 | \catcode`\@12 553 | \global\let\atsign@% 554 | \endgroup 555 | %\chardef\dq=`\" 556 | \ifusinglatex 557 | \def\dq{\ttfamily\char`\"}% 558 | \else 559 | \def\dq{\tt\char`\"}% 560 | \fi 561 | 562 | % leading character of slatex filenames: . for unix to 563 | % keep them out of the way 564 | 565 | \def\filehider{.} 566 | 567 | % since the above doesn't work of dos, slatex on dos 568 | % will use a different character, and make the 569 | % redefinition available through the following 570 | 571 | \InputIfFileExists{xZfilhid.tex}{}{} 572 | 573 | % @ is no longer a letter for TeX 574 | 575 | \ifusinglatex\relax\else 576 | \catcode`\@\atcatcodebeforeslatex 577 | \fi 578 | 579 | \message{*** Check: Are you sure you called SLaTeX 580 | \slatexversion\space or later? ***} 581 | -------------------------------------------------------------------------------- /latex/slatex/slatxdoc.bib: -------------------------------------------------------------------------------- 1 | 2 | @book{sicp, 3 | author = "Harold Abelson and Gerald Jay {Sussman with Julie Sussman}", 4 | title = "\urlp{Structure and Interpretation of 5 | Computer Programs (``SICP'')}{http://mitpress.mit.edu/sicp/full-text/book/book.html}", 6 | edition = "2nd", 7 | publisher = "MIT Press", 8 | year = 1996, 9 | } 10 | 11 | @book{tls, 12 | author = "Daniel P Friedman and Matthias Felleisen", 13 | title = "\urlh{http://www.ccs.neu.edu/~matthias/BTLS}{The Little Schemer}", 14 | publisher = "MIT Press", 15 | year = 1996, 16 | edition = "4th", 17 | } 18 | 19 | @book{tss, 20 | author = "Daniel P Friedman and Matthias Felleisen", 21 | title = "\urlh{http://www.ccs.neu.edu/~matthias/BTSS}{The Seasoned Schemer}", 22 | publisher = "MIT Press", 23 | year = 1996, 24 | } 25 | 26 | @book{tex, 27 | author = "Donald E Knuth", 28 | title = "\urlh{http://cseng.aw.com/book/0,3828,0201134489,00.html}{The 29 | TeXbook}", 30 | publisher = "Addison-Wesley", 31 | year = 1993, 32 | } 33 | 34 | @book{latex, 35 | author = "Leslie Lamport", 36 | title = "\urlh{http://cseng.aw.com/book/0,3828,0201529831,00.html}{LaTeX: A Document Preparation System}", 37 | publisher = "Addison-Wesley", 38 | year = 1994, 39 | edition = "2nd", 40 | } 41 | 42 | @misc{lisp2tex, 43 | author = "Christian Queinnec", 44 | title = 45 | "\urlp{l2t}{http://pagesperso-systeme.lip6.fr/Christian.Queinnec/WWW/l2t.html}", 46 | } 47 | 48 | @misc{schemeweb, 49 | author = "John Ramsdell", 50 | title = 51 | "\urlp{SchemeWeb}{http://www.ctan.org/tex-archive/web/schemeweb2}", 52 | } 53 | -------------------------------------------------------------------------------- /latex/slatex/slatxdoc.t2p: -------------------------------------------------------------------------------- 1 | 2 | \cssblock 3 | /* 4 | .scheme .variable { 5 | font-style: italic; 6 | }*/ 7 | 8 | \endcssblock 9 | 10 | \dontuseimgforhtmlmath 11 | \slatexlikecomments 12 | 13 | \def\re#1{% 14 | \evalh{(do-end-para)}% 15 | \rawhtml 16 |
\endrawhtml 17 | {\obeylines#1}% 18 | \rawhtml
\endrawhtml 19 | \par} 20 | 21 | 22 | % Redefine \section so that it starts a fresh page 23 | 24 | %\let\ORIGsection\section 25 | %\def\section{\vfill\eject\ORIGsection} 26 | 27 | \imgpreamble 28 | \input slatex.sty 29 | \magnification\magstep2 30 | \endimgpreamble 31 | 32 | \scmkeyword{setq} 33 | 34 | \imgdef\lambda{$\lambda$} 35 | \imgdef\land{$\land$} 36 | \imgdef\subseteq{$\subseteq$} 37 | \imgdef\supseteq{$\supseteq$} 38 | \imgdef\equiv{$\equiv$} 39 | \imgdef\ne{$\ne$} 40 | \imgdef\top{$\top$} 41 | \imgdef\bot{$\bot$} 42 | 43 | 44 | -------------------------------------------------------------------------------- /latex/slatex/tex2page.tex: -------------------------------------------------------------------------------- 1 | % tex2page.tex 2 | % Dorai Sitaram 3 | 4 | % TeX files using these macros 5 | % can be converted by the program 6 | % tex2page into HTML 7 | 8 | \ifx\shipout\UnDeFiNeD\endinput\fi 9 | 10 | \message{version 20090506} % last change 11 | 12 | \let\texonly\relax 13 | \let\endtexonly\relax 14 | 15 | \let\htmlonly\iffalse 16 | \let\endhtmlonly\fi 17 | 18 | \edef\atcatcodebeforetexzpage{% 19 | \noexpand\catcode`\noexpand\@=\the\catcode`\@} 20 | \catcode`\@11 21 | 22 | % 23 | 24 | \def\verbwritefile{% 25 | \ifx\verbwritefileQport\UnDeFiNeD 26 | \expandafter\csname newwrite\endcsname\verbwritefileQport 27 | \else\immediate\closeout\verbwritefileQport 28 | \fi 29 | \futurelet\verbwritefileQnext\verbwritefileQcheckchar} 30 | 31 | \def\verbwritefileQcheckchar{% 32 | \ifx\verbwritefileQnext\bgroup 33 | \let\verbwritefileQnext\verbwritefileQbracedfile 34 | \else 35 | \let\verbwritefileQnext\verbwritefileQspacedfile 36 | \fi\verbwritefileQnext} 37 | 38 | \def\verbwritefileQspacedfile#1 {% 39 | \immediate\openout\verbwritefileQport #1 40 | } 41 | 42 | \def\verbwritefileQbracedfile#1{% 43 | \verbwritefileQspacedfile #1 44 | } 45 | 46 | \def\verbwrite{% 47 | \ifx\verbwritefileQport\UnDeFiNeD 48 | \verbwritefile \jobname.txt \fi 49 | \begingroup 50 | \def\do##1{\catcode`##1=12 }\dospecials 51 | \catcode`\{=1 \catcode`\}=2 52 | \catcode`\^^M=12 \newlinechar=`\^^M% 53 | \futurelet\verbwriteQopeningchar\verbwriteQii} 54 | 55 | \def\verbwriteQii{\ifx\verbwriteQopeningchar\bgroup 56 | \let\verbwriteQiii\verbwriteQbrace\else 57 | \let\verbwriteQiii\verbwriteQnonbrace\fi 58 | \verbwriteQiii} 59 | 60 | \def\verbwriteQbrace#1{\immediate 61 | \write\verbwritefileQport{#1}\endgroup} 62 | 63 | \def\verbwriteQnonbrace#1{% 64 | \catcode`\{12 \catcode`\}12 65 | \def\verbwriteQnonbraceQii##1#1{% 66 | \immediate\write\verbwritefileQport{##1}\endgroup}% 67 | \verbwriteQnonbraceQii} 68 | 69 | \ifx\slatexignorecurrentfile\UnDeFiNeD\relax\fi 70 | 71 | % 72 | 73 | \def\defcsactive#1{\defnumactive{`#1}} 74 | 75 | \def\defnumactive#1{\catcode#1\active 76 | \begingroup\lccode`\~#1% 77 | \lowercase{\endgroup\def~}} 78 | 79 | % gobblegobblegobble 80 | 81 | \def\gobblegroup{\bgroup 82 | \def\do##1{\catcode`##1=9 }\dospecials 83 | \catcode`\{1 \catcode`\}2 \catcode`\^^M=9 84 | \gobblegroupQii} 85 | 86 | \def\gobblegroupQii#1{\egroup} 87 | 88 | % \verb 89 | % Usage: \verb{...lines...} or \verb|...lines...| 90 | % In the former case, | can be used as escape char within 91 | % the verbatim text 92 | 93 | \let\verbhook\relax 94 | 95 | \def\verbfont{\tt} 96 | %\hyphenchar\tentt-1 97 | 98 | \def\verbsetup{\frenchspacing 99 | \def\do##1{\catcode`##1=12 }\dospecials 100 | \catcode`\|=12 % needed? 101 | \verbfont 102 | \edef\verbQoldhyphenchar{\the\hyphenchar\font}% 103 | \hyphenchar\font-1 104 | \def\verbQendgroup{\hyphenchar\font\verbQoldhyphenchar\endgroup}% 105 | } 106 | 107 | \def\verbavoidligs{% avoid ligatures 108 | \defcsactive\`{\relax\lq}% 109 | \defcsactive\ {\leavevmode\ }% 110 | \defcsactive\^^I{\leavevmode\ \ \ \ \ \ \ \ }% 111 | \defcsactive\^^M{\leavevmode\endgraf}% 112 | \ifx\noncmttQspecific\UnDeFiNeD\else\noncmttQspecific\fi} 113 | 114 | \def\verbinsertskip{% 115 | \let\firstpar y% 116 | \defcsactive\^^M{\ifx\firstpar y% 117 | \let\firstpar n% 118 | \verbdisplayskip 119 | \parskip 0pt 120 | \aftergroup\verbdisplayskip 121 | \aftergroup\noindent % to get automatic noindent after display 122 | \aftergroup\ignorespaces % ,, 123 | \else\leavevmode\fi\endgraf}% 124 | \verbhook} 125 | 126 | %\def\verb{\begingroup 127 | % \verbsetup\verbQii} 128 | 129 | \ifx\verb\UnDeFiNeD\else % save away LaTeX's \verb 130 | \let\LaTeXverb\verb 131 | \fi 132 | 133 | \def\verb{\begingroup 134 | \verbsetup\verbavoidligs\verbQcheckstar}% 135 | 136 | \def\verbQcheckstar{% 137 | \futurelet\verbQcheckstarQnext\verbQcheckstarQii} 138 | 139 | \def\verbQcheckstarQii{% 140 | \if\verbQcheckstarQnext*% 141 | \let\verbQcheckstarQnext\verbQcheckstarQiii 142 | \else 143 | \let\verbQcheckstarQnext\verbQii 144 | \fi 145 | \verbQcheckstarQnext} 146 | 147 | \def\verbQcheckstarQiii#1{% 148 | \defcsactive\ {\relax\char`\ }% 149 | \verbQii} 150 | 151 | \newcount\verbbracebalancecount 152 | 153 | \def\verblbrace{\char`\{} 154 | \def\verbrbrace{\char`\}} 155 | 156 | \ifx\verbatimescapechar\UnDeFiNeD 157 | % don't clobber Eplain's \verbatimescapechar 158 | \def\verbatimescapechar#1{% 159 | \def\@makeverbatimescapechar{\catcode`#1=0 }}% 160 | \fi 161 | \let\verbescapechar\verbatimescapechar 162 | 163 | \verbatimescapechar\| 164 | 165 | {\catcode`\[1 \catcode`\]2 166 | \catcode`\{12 \catcode`\}12 167 | \gdef\verbQii#1[%\verbavoidligs 168 | \verbinsertskip\verbhook 169 | %\edef\verbQoldhyphenchar{\the\hyphenchar\tentt}% 170 | %\hyphenchar\tentt=-1 171 | %\def\verbQendgroup{\hyphenchar\tentt\verbQoldhyphenchar\endgroup}% 172 | %\let\verbQendgroup\endgroup% 173 | \if#1{\@makeverbatimescapechar 174 | \def\{[\char`\{]% 175 | \def\}[\char`\}]% 176 | \def\|[\char`\|]% 177 | \verbbracebalancecount0 178 | \defcsactive\{[\advance\verbbracebalancecount by 1 179 | \verblbrace]% 180 | \defcsactive\}[\ifnum\verbbracebalancecount=0 181 | \let\verbrbracenext\verbQendgroup\else 182 | \advance\verbbracebalancecount by -1 183 | \let\verbrbracenext\verbrbrace\fi 184 | \verbrbracenext]\else 185 | \defcsactive#1[\verbQendgroup]\fi 186 | \verbQiii 187 | ]] 188 | 189 | \def\verbQiii{\futurelet\verbQiiinext\verbQiv} 190 | 191 | {\catcode`\^^M\active% 192 | \gdef\verbQiv{\ifx\verbQiiinext^^M\else% 193 | \defcsactive\^^M{\leavevmode\ }\fi}} 194 | 195 | \let\verbdisplayskip\medbreak 196 | 197 | % \verbatiminput FILENAME 198 | % displays contents of file FILENAME verbatim. 199 | 200 | %\def\verbatiminput#1 {{\verbsetup\verbavoidligs\verbhook 201 | % \input #1 }} 202 | 203 | % ^ original \verbatiminput 204 | 205 | \ifx\verbatiminput\UnDeFiNeD 206 | % LaTeX's (optional) verbatim package defines a \verbatiminput -- 207 | % don't clobber it 208 | \def\verbatiminput{% 209 | \futurelet\verbatiminputQnext\verbatiminputQcheckchar}% 210 | \fi 211 | 212 | \def\verbatiminputQcheckchar{% 213 | \ifx\verbatiminputQnext\bgroup 214 | \let\verbatiminputQnext\verbatiminputQbracedfile 215 | \else 216 | \let\verbatiminputQnext\verbatiminputQspacedfile 217 | \fi\verbatiminputQnext} 218 | 219 | \def\verbatiminputQbracedfile#1{\verbatiminputQdoit{#1}} 220 | 221 | \def\verbatiminputQspacedfile#1 {\verbatiminputQdoit{#1}} 222 | 223 | \def\verbatiminputQdoit#1{{\verbsetup 224 | \verbavoidligs\verbhook 225 | \input #1 }} 226 | 227 | % \url{URL} becomes 228 | % URL in HTML, and 229 | % URL in DVI. 230 | 231 | % A-VERY-VERY-LONG-URL in a .bib file 232 | % could be split by BibTeX 233 | % across a linebreak, with % before the newline. 234 | % To accommodate this, %-followed-by-newline will 235 | % be ignored in the URL argument of \url and related 236 | % macros. 237 | 238 | \ifx\url\UnDeFiNeD 239 | \def\url{\bgroup\urlsetup\let\dummy=}% 240 | \fi 241 | 242 | \def\urlsetup{\verbsetup\urlfont\verbavoidligs 243 | \catcode`\{1 \catcode`\}2 244 | \defcsactive\%{\urlQpacifybibtex}% 245 | \defcsactive\ {\relax}% 246 | \defcsactive\^^M{\relax}% 247 | \defcsactive\.{\discretionary{}{\char`\.}{\char`\.}}% 248 | \defcsactive\/{\discretionary{\char`\/}{}{\char`\/}}% 249 | \defcsactive\`{\relax\lq}} 250 | 251 | \let\urlfont\relax 252 | 253 | \def\urlQpacifybibtex{\futurelet\urlQpacifybibtexQnext\urlQpacifybibtexQii} 254 | 255 | \def\urlQpacifybibtexQii{\ifx\urlQpacifybibtexQnext^^M% 256 | \else\%\fi} 257 | 258 | % \urlh{URL}{TEXT} becomes 259 | % TEXT in HTML, and 260 | % TEXT in DVI. 261 | 262 | % If TEXT contains \\, the part after \\ appears in 263 | % the DVI only. If, further, this part contains \1, 264 | % the latter is replaced by a fixed-width representation 265 | % of URL. 266 | 267 | \def\urlh{\bgroup\urlsetup 268 | \afterassignment\urlhQii 269 | \gdef\urlhQurlarg} 270 | 271 | \def\urlhQii{\egroup 272 | \bgroup 273 | \let\\\relax 274 | \def\1{{\urlsetup\urlhQurlarg}}% 275 | \let\dummy=} 276 | 277 | \def\urlp#1{{#1} \bgroup\urlsetup 278 | \afterassignment\urlpQwrapparens 279 | \gdef\urlpQurlarg} 280 | 281 | \def\urlpQwrapparens{\egroup 282 | {\rm(}{\urlsetup\urlpQurlarg}{\rm)}} 283 | 284 | % \urlhd{URL}{HTML-TEXT}{DVI-TEXT} becomes 285 | % HTML-TEXT in HTML, and 286 | % DVI-TEXT in DVI 287 | 288 | \def\urlhd{\bgroup 289 | \def\do##1{\catcode`##1=12 }\dospecials 290 | \catcode`\{1 \catcode`\}2 291 | \urlhdQeaturlhtmlargs} 292 | 293 | \def\urlhdQeaturlhtmlargs#1#2{\egroup} 294 | 295 | \ifx\href\UnDeFiNeD 296 | \let\href\urlh 297 | \fi 298 | 299 | % \path is like \verb except that its argument 300 | % can break across lines at `.' and `/'. 301 | 302 | \ifx\path\UnDeFiNeD 303 | \def\path{\begingroup\verbsetup 304 | \pathfont 305 | \defcsactive\.{\discretionary{\char`\.}{}{\char`\.}}% 306 | \defcsactive\/{\discretionary{\char`\/}{}{\char`\/}}% 307 | \verbQii}% 308 | \fi 309 | 310 | \let\pathfont\relax 311 | 312 | % Scheme 313 | 314 | \let\scm\verb 315 | \let\scminput\verbatiminput 316 | \let\lispinput\verbatiminput 317 | \let\scmdribble\scm 318 | 319 | % Images 320 | 321 | \let\imgdef\def 322 | 323 | \let\makehtmlimage\relax 324 | 325 | \def\mathg{$\bgroup\aftergroup\closemathg\let\dummy=} 326 | \def\closemathg{$} 327 | 328 | \let\mathp\mathg 329 | 330 | \def\mathdg{$$\bgroup\aftergroup\closemathdg\let\dummy=} 331 | \def\closemathdg{$$} 332 | 333 | % 334 | 335 | \ifx\label\UnDeFiNeD 336 | \else 337 | \def\xrtag#1#2{\@bsphack 338 | \protected@write\@auxout{}% 339 | {\string\newlabel{#1}{{#2}{\thepage}}}% 340 | \@esphack}% 341 | %\let\tagref\ref 342 | \fi 343 | 344 | \ifx\definexref\UnDeFiNeD 345 | \else 346 | \def\xrtag#1#2{\definexref{#1}{#2}{}}% 347 | \fi 348 | 349 | \ifx\IfFileExists\UnDeFiNeD 350 | \def\IfFileExists#1#2#3{% 351 | \openin0 #1 % 352 | \ifeof0 % 353 | #3% 354 | \else 355 | #2\fi 356 | \closein0 }% 357 | \fi 358 | 359 | \ifx\InputIfFileExists\UnDeFiNeD 360 | \def\InputIfFileExists#1#2#3{% 361 | \IfFileExists{#1}{#2\input #1 }{#3}}% 362 | \fi 363 | 364 | \InputIfFileExists{eval4tex}{}{}% 365 | 366 | \ifx\futurenonspacelet\UnDeFiNeD 367 | \ifx\@futurenonspacelet\UnDeFiNeD 368 | % 369 | \def\futurenonspaceletQpickupspace/{% 370 | \global\let\futurenonspaceletQspacetoken= }% 371 | \futurenonspaceletQpickupspace/ % 372 | % 373 | \def\futurenonspacelet#1{\def\futurenonspaceletQargQi{#1}% 374 | \afterassignment\futurenonspaceletQstepQone 375 | \let\futurenonspaceletQargQii=}% 376 | % 377 | \def\futurenonspaceletQstepQone{% 378 | \expandafter\futurelet\futurenonspaceletQargQi 379 | \futurenonspaceletQstepQtwo}% 380 | % 381 | \def\futurenonspaceletQstepQtwo{% 382 | \expandafter\ifx\futurenonspaceletQargQi\futurenonspaceletQspacetoken 383 | \let\futurenonspaceletQnext=\futurenonspaceletQstepQthree 384 | \else\let\futurenonspaceletQnext=\futurenonspaceletQargQii 385 | \fi\futurenonspaceletQnext}% 386 | % 387 | \def\futurenonspaceletQstepQthree{% 388 | \afterassignment\futurenonspaceletQstepQone 389 | \let\futurenonspaceletQnext= }% 390 | % 391 | \else\let\futurenonspacelet\@futurenonspacelet 392 | \fi 393 | \fi 394 | 395 | \ifx\slatexversion\UnDeFiNeD 396 | % SLaTeX compat 397 | \let\scmkeyword\gobblegroup 398 | \let\scmbuiltin\gobblegroup 399 | \let\scmconstant\scmbuiltin 400 | \let\scmvariable\scmbuiltin 401 | \let\setbuiltin\scmbuiltin 402 | \let\setconstant\scmbuiltin 403 | \let\setkeyword\scmkeyword 404 | \let\setvariable\scmvariable 405 | \def\schemedisplay{\begingroup 406 | \verbsetup\verbavoidligs 407 | \verbinsertskip 408 | \schemedisplayI}% 409 | \def\schemeresponse{\begingroup 410 | \verbsetup\verbavoidligs 411 | \verbinsertskip 412 | \schemeresponseI}% 413 | {\catcode`\|0 |catcode`|\12 414 | |long|gdef|schemedisplayI#1\endschemedisplay{% 415 | #1|endgroup}% 416 | |long|gdef|schemeresponseI#1\endschemeresponse{% 417 | #1|endgroup}}% 418 | \fi 419 | 420 | % STOP LOADING HERE FOR LATEX 421 | 422 | \ifx\section\UnDeFiNeD 423 | \let\maybeloadfollowing\relax 424 | \else 425 | \atcatcodebeforetexzpage 426 | \let\maybeloadfollowing\endinput 427 | \fi\maybeloadfollowing 428 | 429 | \newwrite\sectionQscratchfileport 430 | 431 | % Title 432 | 433 | \def\subject{% 434 | \immediate\openout\sectionQscratchfileport Z-sec-temp 435 | \begingroup 436 | \def\do##1{\catcode`##1=11 }\dospecials 437 | \catcode`\{=1 \catcode`\}=2 438 | \subjectI} 439 | 440 | \def\subjectI#1{\endgroup 441 | \immediate\write\sectionQscratchfileport {#1}% 442 | \immediate\closeout\sectionQscratchfileport 443 | $$\vbox{\bf \def\\{\cr}% 444 | \halign{\hfil##\hfil\cr 445 | \input Z-sec-temp 446 | \cr}}$$% 447 | \medskip} 448 | 449 | \let\title\subject 450 | 451 | % toc 452 | 453 | \let\tocactive0 454 | 455 | \newcount\tocdepth 456 | 457 | %\tocdepth=10 458 | \tocdepth=3 459 | 460 | \def\tocoutensure{\ifx\tocout\UnDeFiNeD 461 | \csname newwrite\endcsname\tocout\fi} 462 | 463 | \def\tocactivate{\ifx\tocactive0% 464 | \tocoutensure 465 | \tocsave 466 | \openout\tocout \jobname.toc 467 | \global\let\tocactive1\fi} 468 | 469 | \def\tocspecials{\def\do##1{\catcode`##1=12 }\dospecials} 470 | 471 | \def\tocsave{\openin0=\jobname.toc 472 | \ifeof0 \closein0 \else 473 | \openout\tocout Z-T-\jobname.tex 474 | \let\tocsaved 0% 475 | \loop 476 | \ifeof0 \closeout\tocout 477 | \let\tocsaved1% 478 | \else{\tocspecials 479 | \read0 to \tocsaveline 480 | \edef\temp{\write\tocout{\tocsaveline}}\temp}% 481 | \fi 482 | \ifx\tocsaved0% 483 | \repeat 484 | \fi 485 | \closein0 } 486 | 487 | \def\tocentry#1#2{% 488 | %#1=depth #2=secnum 489 | \def\tocentryQsecnum{#2}% 490 | \ifnum#1=1 491 | \ifnum\tocdepth>2 492 | \medbreak\begingroup\bf 493 | \else\begingroup\fi 494 | \else\begingroup\fi 495 | \vtop\bgroup\raggedright 496 | \noindent\hskip #1 em 497 | \ifx\tocentryQsecnum\empty 498 | \else\qquad\llap{\tocentryQsecnum}\enspace\fi 499 | \bgroup 500 | \aftergroup\tocentryQii 501 | %read section title 502 | \let\dummy=} 503 | 504 | \def\tocentryQii#1{% 505 | %#1=page nr 506 | , #1\strut\egroup 507 | \endgroup\par 508 | } 509 | 510 | % allow {thebibliography} to be used directly 511 | % in (plain-TeX) source document without 512 | % generating it via BibTeX 513 | 514 | \ifx\thebibliography\UnDeFiNeD 515 | \def\thebibliography#1{\vskip-\lastskip 516 | \begingroup 517 | \def\endthebibliography{\endgroup\endgroup}% 518 | \def\input##1 ##2{\relax}% 519 | \setbox0=\hbox{\biblabelcontents{#1}}% 520 | \biblabelwidth=\wd0 521 | \@readbblfile}% 522 | \fi 523 | 524 | % 525 | 526 | \def\italiccorrection{\futurelet\italiccorrectionI 527 | \italiccorrectionII} 528 | 529 | \def\italiccorrectionII{% 530 | \if\noexpand\italiccorrectionI,\else 531 | \if\noexpand\italiccorrectionI.\else 532 | \/\fi\fi} 533 | 534 | \def\em{\it\ifmmode\else\aftergroup\italiccorrection\fi} 535 | 536 | \def\emph{\bgroup\it 537 | \ifmmode\else\aftergroup\italiccorrection\fi 538 | \let\dummy=} 539 | 540 | \def\begin#1{\begingroup 541 | \def\end##1{\csname end#1\endcsname\endgroup}% 542 | \csname #1\endcsname} 543 | 544 | \ifx\TM\undefined 545 | % using fontch names 546 | \def\TM{\ifmmode^{\rm TM}\else$^{\rm TM}$\fi} 547 | \def\degree{\ifmmode^\circ\else$^\circ$\fi} 548 | \fi 549 | 550 | % STOP LOADING HERE FOR EPLAIN 551 | 552 | \ifx\eplain\UnDeFiNeD 553 | \let\maybeloadfollowing\relax 554 | \else 555 | \atcatcodebeforetexzpage 556 | \let\maybeloadfollowing\endinput 557 | \fi\maybeloadfollowing 558 | % 559 | 560 | % Index generation 561 | % 562 | % Your TeX source contains \index{NAME} to 563 | % signal that NAME should be included in the index. 564 | % Check the makeindex documentation to see the various 565 | % ways NAME can be specified, eg, for subitems, for 566 | % explicitly specifying the alphabetization for a name 567 | % involving TeX control sequences, etc. 568 | % 569 | % The first run of TeX will create \jobname.idx. 570 | % makeindex on \jobname[.idx] will create the sorted 571 | % index \jobname.ind. 572 | % 573 | % Use \inputindex (without arguments) to include this 574 | % sorted index, typically somewhere to the end of your 575 | % document. This will produce the items and subitems. 576 | % It won't produce a section heading however -- you 577 | % will have to typeset one yourself. 578 | 579 | %\def\sanitizeidxletters{\def\do##1{\catcode`##1=11 }% 580 | % \dospecials 581 | % \catcode`\{=1 \catcode`\}=2 \catcode`\ =10 } 582 | 583 | \def\sanitizeidxletters{\def\do##1{\catcode`##1=11 }% 584 | \do\\\do\$\do\&\do\#\do\^\do\_\do\%\do\~% 585 | \do\@\do\"\do\!\do\|\do\-\do\ \do\'} 586 | 587 | \def\index{%\unskip 588 | \ifx\indexout\UnDeFiNeD 589 | \csname newwrite\endcsname\indexout 590 | \openout\indexout \jobname.idx\fi 591 | \begingroup 592 | \sanitizeidxletters 593 | \indexQii} 594 | 595 | \def\indexQii#1{\endgroup 596 | \write\indexout{\string\indexentry{#1}{\folio}}% 597 | \ignorespaces} 598 | 599 | % The following index style indents subitems on a 600 | % separate lines 601 | 602 | \def\theindex{\begingroup 603 | \parskip0pt \parindent0pt 604 | \def\indexitem##1{\par\hangindent30pt \hangafter1 605 | \hskip ##1 }% 606 | \def\item{\indexitem{0em}}% 607 | \def\subitem{\indexitem{2em}}% 608 | \def\subsubitem{\indexitem{4em}}% 609 | \def\see{{\it see} \bgroup\aftergroup\gobblegroup\let\dummy=}% 610 | \let\indexspace\medskip} 611 | 612 | \def\endtheindex{\endgroup} 613 | 614 | \def\inputindex{% 615 | \openin0 \jobname.ind 616 | \ifeof0 \closein0 617 | \message{\jobname.ind missing.}% 618 | \else\closein0 619 | \begingroup 620 | \def\begin##1{\csname##1\endcsname}% 621 | \def\end##1{\csname end##1\endcsname}% 622 | \input\jobname.ind 623 | \endgroup\fi} 624 | 625 | % Cross-references 626 | 627 | % \openxrefout loads all the TAG-VALUE associations in 628 | % \jobname.xrf and then opens \jobname.xrf as an 629 | % output channel that \xrtag can use 630 | 631 | \def\openxrefout{% 632 | \openin0=\jobname.xrf 633 | \ifeof0 \closein0 634 | \else \closein0 {\catcode`\\0 \input \jobname.xrf }% 635 | \fi 636 | \expandafter\csname newwrite\endcsname\xrefout 637 | \openout\xrefout=\jobname.xrf 638 | } 639 | 640 | % I'd like to call \openxrefout lazily, but 641 | % unfortunately it produces a bug in MiKTeX. 642 | % So let's call it up front. 643 | 644 | \openxrefout 645 | 646 | % \xrtag{TAG}{VALUE} associates TAG with VALUE. 647 | % Hereafter, \ref{TAG} will output VALUE. 648 | % \xrtag stores its associations in \xrefout. 649 | % \xrtag calls \openxrefout if \jobname.xrf hasn't 650 | % already been opened 651 | 652 | \def\xrtag#1#2{\ifx\xrefout\UnDeFiNeD\openxrefout\fi 653 | {\let\folio0% 654 | \edef\temp{% 655 | \write\xrefout{\string\expandafter\string\gdef 656 | \string\csname\space XREF#1\string\endcsname 657 | {#2}\string\relax}}% 658 | \temp}\ignorespaces} 659 | 660 | % \xrdef, as in Eplain 661 | 662 | \def\xrdef#1{\xrtag{#1}{\folio}} 663 | 664 | % \ref{TAG} outputs VALUE, assuming \xrtag put such 665 | % an association into \xrefout. \ref calls 666 | % \openxrefout if \jobname.xrf hasn't already 667 | % been opened 668 | 669 | \def\ref#1{\ifx\xrefout\UnDeFiNeD\openxrefout\fi 670 | \expandafter\ifx\csname XREF#1\endcsname\relax 671 | %\message or \write16 ? 672 | \message{\the\inputlineno: Unresolved label `#1'.}?\else 673 | \csname XREF#1\endcsname\fi} 674 | 675 | % 676 | 677 | \def\writenumberedtocline#1#2#3{% 678 | %#1=depth 679 | %#2=secnum 680 | %#3=title 681 | \tocactivate 682 | \edef\@currentlabel{#2}% 683 | {\let\folio0% 684 | \edef\writetotocQtemp{\write\tocout 685 | {\string\tocentry{#1}{#2}{#3}{\folio}}}% 686 | \writetotocQtemp}} 687 | 688 | \def\tableofcontents{% 689 | \ifx\tocactive0% 690 | \openin0 \jobname.toc 691 | \edef\QatcatcodebeforeToC{% 692 | \noexpand\catcode`\noexpand\@=\the\catcode`\@}% 693 | \catcode`\@=11 694 | \ifeof0 \closein0 \else 695 | \closein0 \input \jobname.toc 696 | \fi 697 | \QatcatcodebeforeToC 698 | \tocoutensure 699 | \openout\tocout \jobname.toc 700 | \global\let\tocactive1% 701 | \else 702 | \input Z-T-\jobname.tex 703 | \fi} 704 | 705 | % plain's \beginsection splits pages too easily, and also doesn't allow 706 | % verbatim macros in its arg 707 | 708 | \def\beginsection{\vskip-\lastskip 709 | \vskip1.5\bigskipamount 710 | \goodbreak 711 | \noindent 712 | \begingroup 713 | \def\par{\endgraf\endgroup\nobreak\noindent}% 714 | \bf} 715 | 716 | \ifx\twelvebf\UnDeFiNeD 717 | \def\fontstem#1{\expandafter\fontstemQii\fontname#1 \end}% 718 | \def\fontstemQii#1 #2\end{#1 }% 719 | \font\twelvebf \fontstem\tenbf at 12pt 720 | \fi 721 | 722 | \def\beginchapter#1 #2 \par{% 723 | \edef\beginchapterQnr{#1}% 724 | % space before \par ensures trailing space not picked 725 | % up. 726 | % (We don't worry about verbatim text in header.) 727 | % Some vert space in print 728 | \vskip 2.5\bigskipamount 729 | \goodbreak 730 | \noindent 731 | \global\footnotenumber=0 732 | \writenumberedtocline{1}{\beginchapterQnr}{#2}% 733 | \noindent\bgroup\twelvebf \baselineskip=14.4pt 734 | \ifx\beginchapterQnr\empty\else 735 | \beginchapterQnr\enspace\fi 736 | #2% 737 | \egroup\medskip\nobreak\noindent} 738 | 739 | \ifx\bull\UnDeFiNeD 740 | % from manmac 741 | \def\bull{\vrule height .9ex width .8ex depth -.1ex } % square bullet 742 | \fi 743 | 744 | \ifx\frac\UnDeFiNeD 745 | \def\frac#1/#2{\leavevmode\kern.1em 746 | \raise.5ex\hbox{\the\scriptfont0 #1}\kern-.1em 747 | /\kern-.15em\lower.25ex\hbox{\the\scriptfont0 #2}} 748 | \fi 749 | 750 | \def\obeywhitespace{% 751 | \defcsactive\^^M{\endgraf\leavevmode}% 752 | \obeyspaces} 753 | 754 | % 755 | % Numbered footnotes 756 | 757 | \ifx\plainfootnote\UnDeFiNeD 758 | \let\plainfootnote\footnote 759 | \fi 760 | 761 | \newcount\footnotenumber 762 | 763 | \def\numberedfootnote{\global\advance\footnotenumber 1 764 | \bgroup\csname footnotehook\endcsname 765 | \plainfootnote{$^{\the\footnotenumber}$}\bgroup 766 | \aftergroup\egroup 767 | \let\dummy=} 768 | 769 | % 770 | 771 | \def\sidemargin{\afterassignment\sidemarginQadjustoffset 772 | \hoffset} 773 | 774 | \def\sidemarginQadjustoffset{% 775 | \advance\hoffset -1true in 776 | \advance\hsize -2\hoffset} 777 | 778 | % fluff 779 | 780 | \let\p\verb 781 | \let\q\scm 782 | 783 | \atcatcodebeforetexzpage 784 | 785 | % end of file 786 | -------------------------------------------------------------------------------- /latex/slatex/version.tex: -------------------------------------------------------------------------------- 1 | 20090928%last modified 2 | -------------------------------------------------------------------------------- /latex/title.tex: -------------------------------------------------------------------------------- 1 | \thispagestyle{empty} 2 | 3 | \begin{fullwidth} 4 | \rmfamily 5 | \itshape 6 | \noindent\fontsize{20}{24}\selectfont 7 | \thanklessauthor 8 | 9 | \vspace{10.5pc}% 10 | 11 | \upshape 12 | \noindent\fontsize{36}{38}\selectfont 13 | \nohyphenation 14 | %\thanklesstitle 15 | Playing with \\\noindent Relational Interpreters 16 | 17 | \normalsize 18 | 19 | ~\vfill 20 | 21 | \end{fullwidth} 22 | -------------------------------------------------------------------------------- /latex/tufte-book.cls: -------------------------------------------------------------------------------- 1 | \NeedsTeXFormat{LaTeX2e}[1994/06/01] 2 | 3 | \ProvidesClass{tufte-book}[2009/12/11 v3.5.0 Tufte-book class] 4 | 5 | %% 6 | % Declare we're tufte-book 7 | \newcommand{\@tufte@class}{book}% the base LaTeX class (defaults to the article/handout style) 8 | \newcommand{\@tufte@pkgname}{tufte-book}% the name of the package (defaults to tufte-handout) 9 | 10 | %% 11 | % Load the common style elements 12 | \input{tufte-common.def} 13 | 14 | 15 | %% 16 | % Set up any book-specific stuff now 17 | 18 | %% 19 | % The front matter in Tufte's /Beautiful Evidence/ contains everything up 20 | % to the opening page of Chapter 1. The running heads, when they appear, 21 | % contain only the (arabic) page number in the outside corner. 22 | %\newif\if@mainmatter \@mainmattertrue 23 | \renewcommand\frontmatter{% 24 | \cleardoublepage% 25 | \@mainmatterfalse% 26 | \pagenumbering{arabic}% 27 | %\pagestyle{plain}% 28 | \fancyhf{}% 29 | \ifthenelse{\boolean{@tufte@twoside}}% 30 | {\fancyhead[LE,RO]{\thepage}}% 31 | {\fancyhead[RE,RO]{\thepage}}% 32 | } 33 | 34 | 35 | %% 36 | % The main matter in Tufte's /Beautiful Evidence/ doesn't restart the page 37 | % numbering---it continues where it left off in the front matter. 38 | \renewcommand\mainmatter{% 39 | \cleardoublepage% 40 | \@mainmattertrue% 41 | \fancyhf{}% 42 | \ifthenelse{\boolean{@tufte@twoside}}% 43 | {% two-side 44 | \renewcommand{\chaptermark}[1]{\markboth{##1}{}}% 45 | \fancyhead[LE]{\thepage\quad\smallcaps{\newlinetospace{\plaintitle}}}% book title 46 | \fancyhead[RO]{\smallcaps{\newlinetospace{\leftmark}}\quad\thepage}% chapter title 47 | }% 48 | {% one-side 49 | \fancyhead[RE,RO]{\smallcaps{\newlinetospace{\plaintitle}}\quad\thepage}% book title 50 | }% 51 | } 52 | 53 | 54 | %% 55 | % The back matter contains appendices, indices, glossaries, endnotes, 56 | % biliographies, list of contributors, illustration credits, etc. 57 | \renewcommand\backmatter{% 58 | \if@openright% 59 | \cleardoublepage% 60 | \else% 61 | \clearpage% 62 | \fi% 63 | \@mainmatterfalse% 64 | } 65 | 66 | %% 67 | % Only show the chapter titles in the table of contents 68 | \setcounter{tocdepth}{0} 69 | 70 | %% 71 | % If there is a `tufte-book-local.sty' file, load it. 72 | 73 | \IfFileExists{tufte-book-local.tex} 74 | {\input{tufte-book-local} 75 | \TufteInfoNL{Loading tufte-book-local.tex}} 76 | {} 77 | 78 | %% 79 | % End of file 80 | \endinput 81 | -------------------------------------------------------------------------------- /latex/urib-prelude.tex: -------------------------------------------------------------------------------- 1 | \newcommand{\bookkeywords}[0]{miniKanren, Relational Programming, Logic Programming} 2 | 3 | \newcommand{\wspace}{{\vspace{1em}}} 4 | 5 | \usepackage{morefloats} 6 | 7 | \usepackage{alltt} 8 | \usepackage{amsfonts} 9 | \usepackage{amsmath} 10 | \usepackage{amssymb} 11 | 12 | % For the XeLaTeX symbol 13 | \usepackage{xltxtra} 14 | 15 | % Creative Commons license icons 16 | \usepackage{ccicons} 17 | 18 | \usepackage{comment} 19 | 20 | \usepackage{float} 21 | 22 | % Load Palatino-like fonts 23 | % from http://tex.stackexchange.com/questions/50586/how-to-use-palatino-like-math-fonts-in-xelatex 24 | \usepackage{fontspec} 25 | \defaultfontfeatures{Ligatures=TeX} % makes this a feature for all selected fonts 26 | \usepackage{mathpazo} 27 | \setmainfont 28 | [ BoldFont = texgyrepagella-bold.otf , 29 | ItalicFont = texgyrepagella-italic.otf , 30 | BoldItalicFont = texgyrepagella-bolditalic.otf ] 31 | {texgyrepagella-regular.otf} 32 | 33 | \usepackage{hanging} 34 | 35 | % Careful: mathbbol apparently doesn't like 11pt 36 | % The stmryrd error about 11pt is actually caused by mathbbol 37 | % See http://www.latex-community.org/forum/viewtopic.php?f=4&t=2099 38 | % 10pt or 12pt are apparently okay, though. 39 | %\usepackage[cspex,bbgreekl]{mathbbol} 40 | 41 | \usepackage{natbib} 42 | 43 | \usepackage{slatex} 44 | \usepackage{stmaryrd} 45 | \usepackage{textcomp} 46 | 47 | % Uncomment to use author-date citation format 48 | %\bibpunct();A{}, 49 | %\let\cite=\citep 50 | 51 | \newcommand{\RfiveRS}{$R^{5}\!RS$} 52 | \newcommand{\RfiveRSsp}{$R^{5}\!RS$ } 53 | 54 | \newcommand{\RsixRS}{$R^{6}\!RS$} 55 | \newcommand{\RsixRSsp}{$R^{6}\!RS$ } 56 | 57 | \newcommand{\lambdaProlog}{{$\lambda$Prolog}} 58 | 59 | \newcommand{\Godel}{{G{\"o}del}} 60 | 61 | 62 | 63 | %-------------------------------------------- 64 | 65 | %%% SLaTeX stuff 66 | 67 | % Fake using the Computer Modern font within SLaTeX. 68 | \newcommand{\cmr}{\fontfamily{lmr}\selectfont} 69 | 70 | \def\keywordfont#1{{\cmr{\textbf{#1}}}} 71 | \def\variablefont#1{{\cmr{\textit{#1}}}} 72 | \def\constantfont#1{{\cmr{\textsf{#1}}}} 73 | \let\datafont\constantfont 74 | 75 | \defschememathescape{$} % $ 76 | \def\schemecodehook{\setlength{\baselineskip}{0.5\baselineskip}} 77 | 78 | % Scheme/mk typesetting 79 | \setspecialsymbol{lambda}{{\cmr{$\lambda$}}} 80 | \setspecialsymbol{=>}{$\Rightarrow$} 81 | 82 | \def\plusosymbol{$+^{o}$} 83 | \setspecialsymbol{+o}{{\plusosymbol}} 84 | 85 | \def\timesosymbol{$*^{o}$} 86 | \setspecialsymbol{*o}{{\timesosymbol}} 87 | 88 | \def\divosymbol{$/^{o}$} 89 | \setspecialsymbol{/o}{{\divosymbol}} 90 | 91 | 92 | \def\evalosymbol{{eval$^{\thinspace o}$}} 93 | \setspecialsymbol{evalo}{{\variablefont{\evalosymbol}}} 94 | -------------------------------------------------------------------------------- /latex/urib.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webyrd/untitled-relational-interpreter-book/247e29afd224586c39c1983e042524c7cc9fe17b/latex/urib.pdf -------------------------------------------------------------------------------- /latex/urib.tex: -------------------------------------------------------------------------------- 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2 | % This file is a modified version of the 3 | % 4 | % Tufte-Style Book (Minimal Template) 5 | % LaTeX Template 6 | % Version 1.0 (5/1/13) 7 | % 8 | % downloaded from: http://www.LaTeXTemplates.com 9 | % 10 | % The license for *this LaTeX file only* (and the original template) is: 11 | % CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/) 12 | % 13 | % All files for this book, other than this file, and the 14 | % 'tufte-book.cls' and 'tufte-common.cls' files, are covered under the 15 | % license: 16 | % CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/) 17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 | 19 | % Letterspacing is apparently busted in the latest Tufte template. 20 | % If you see the error message 21 | % 22 | % ! Argument of \MakeTextUppercase has an extra }. 23 | % 24 | % you can disable letterspacing by adding [nols]: 25 | % 26 | \documentclass[nols]{tufte-book} 27 | %\documentclass{tufte-book} % Use the tufte-book class which in turn uses the tufte-common class 28 | 29 | \hypersetup{colorlinks} % Comment this line if you don't wish to have colored links 30 | 31 | %\usepackage{microtype} % Improves character and word spacing 32 | 33 | \usepackage{booktabs} % Better horizontal rules in tables 34 | 35 | \usepackage{graphicx} % Needed to insert images into the document 36 | \graphicspath{{graphics/}} % Sets the default location of pictures 37 | \setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio} % Improves figure scaling 38 | 39 | \usepackage{fancyvrb} % Allows customization of verbatim environments 40 | \fvset{fontsize=\normalsize} % The font size of all verbatim text can be changed here 41 | 42 | \newcommand{\hangp}[1]{\makebox[0pt][r]{(}#1\makebox[0pt][l]{)}} % New command to create parentheses around text in tables which take up no horizontal space - this improves column spacing 43 | \newcommand{\hangstar}{\makebox[0pt][l]{*}} % New command to create asterisks in tables which take up no horizontal space - this improves column spacing 44 | 45 | \usepackage{xspace} % Used for printing a trailing space better than using a tilde (~) using the \xspace command 46 | 47 | \newcommand{\monthyear}{\ifcase\month\or January\or February\or March\or April\or May\or June\or July\or August\or September\or October\or November\or December\fi\space\number\year} % A command to print the current month and year 48 | 49 | \newcommand{\openepigraph}[2]{ % This block sets up a command for printing an epigraph with 2 arguments - the quote and the author 50 | \begin{fullwidth} 51 | \sffamily\large 52 | \begin{doublespace} 53 | \noindent\allcaps{#1}\\ % The quote 54 | \noindent\allcaps{#2} % The author 55 | \end{doublespace} 56 | \end{fullwidth} 57 | } 58 | 59 | \newcommand{\blankpage}{\newpage\hbox{}\thispagestyle{empty}\newpage} % Command to insert a blank page 60 | 61 | \usepackage{makeidx} % Used to generate the index 62 | \makeindex % Generate the index which is printed at the end of the document 63 | 64 | \input{urib-prelude.tex} 65 | 66 | %---------------------------------------------------------------------------------------- 67 | % BOOK META-INFORMATION 68 | %---------------------------------------------------------------------------------------- 69 | 70 | \title{Playing with Relational Interpreters} 71 | 72 | \author{William E. Byrd} 73 | 74 | %\publisher{Publisher Name} 75 | 76 | 77 | \begin{document} 78 | \begin{schemeregion} 79 | 80 | \frontmatter 81 | %\pagenumbering{roman} % Tufte-Style Book uses Arabic numbering for front matter 82 | 83 | 84 | %% Overridden!! 85 | % Produces a full title page 86 | 87 | \renewcommand{\maketitlepage}[0]{% 88 | \cleardoublepage% 89 | {% 90 | \rmfamily% 91 | \begin{fullwidth}% 92 | % \fontsize{30}{34}\selectfont\par\noindent\textcolor{darkgray}{\thanklesstitle}% 93 | \fontsize{36}{38}\selectfont\par\noindent\textcolor{darkgray}{Playing with \\\noindent Relational Interpreters}% 94 | \vspace{3pc}% 95 | \sffamily% 96 | \fontsize{20}{22}\selectfont\par\noindent\textcolor{darkgray}{\allcaps{\thanklessauthor}}% 97 | \vfill% 98 | \fontsize{14}{16}\selectfont\par\noindent\allcaps{\thanklesspublisher}% 99 | \end{fullwidth}% 100 | } 101 | 102 | \thispagestyle{empty}% 103 | \clearpage% 104 | } 105 | 106 | \maketitle % Print the title page 107 | 108 | \blankpage 109 | 110 | \blankpage 111 | 112 | \blankpage 113 | 114 | \blankpage 115 | 116 | \blankpage 117 | 118 | % internal title page 119 | \include{title} 120 | 121 | %---------------------------------------------------------------------------------------- 122 | % COPYRIGHT PAGE 123 | %---------------------------------------------------------------------------------------- 124 | 125 | \newpage 126 | 127 | \begin{fullwidth} 128 | ~\vfill 129 | \thispagestyle{empty} 130 | \setlength{\parindent}{0pt} 131 | \setlength{\parskip}{\baselineskip} 132 | \large 133 | \noindent 134 | \textcopyright~2014 William E. Byrd 135 | 136 | \noindent 137 | Typeset by the author in \XeLaTeX, using Tufte-Style Book (\url{http://www.LaTeXTemplates.com}). 138 | 139 | \today\xspace version. \\ The latest version of this book, along with all files necessary to typeset it, can be found at: \\ \url{https://github.com/webyrd/untitled-relational-interpreter-book} 140 | 141 | \noindent 142 | \huge 143 | \ccLogo 144 | \ccAttribution 145 | \large 146 | 147 | \noindent 148 | This work is licensed under a Creative Commons Attribution 4.0 International License. 149 | (CC BY 4.0) \\ 150 | \url{http://creativecommons.org/licenses/by/4.0/} 151 | \normalsize 152 | \end{fullwidth} 153 | 154 | 155 | \tableofcontents 156 | 157 | 158 | %---------------------------------------------------------------------------------------- 159 | % DEDICATION PAGE 160 | %---------------------------------------------------------------------------------------- 161 | 162 | \cleardoublepage 163 | \thispagestyle{empty} 164 | \begin{fullwidth} 165 | ~\vfill 166 | \begin{doublespace} 167 | \noindent\fontsize{18}{22}\selectfont\itshape 168 | \nohyphenation 169 | \begin{tabular}{ll} 170 | For my H211 students: \\ Indiana University, Fall 2010 \& 2011, and Team pw0ni3. 171 | \end{tabular} 172 | \end{doublespace} 173 | \begin{flushright} 174 | \Large 175 | \textit{Learning with always trumps learning from.} 176 | 177 | \wspace 178 | 179 | ---Woodie Flowers 180 | \normalsize 181 | \end{flushright} 182 | \vfill 183 | \vfill 184 | \end{fullwidth} 185 | 186 | 187 | \blankpage 188 | 189 | 190 | \include{preface} 191 | 192 | \mainmatter 193 | %\pagenumbering{arabic} 194 | 195 | \include{introduction} 196 | 197 | %\include{language} 198 | 199 | %\include{automata} 200 | 201 | \include{interpreters} 202 | 203 | \include{conclusion} 204 | 205 | %---------------------------------------------------------------------------------------- 206 | 207 | % description of appendix vs. backmatter ordering: 208 | % http://tex.stackexchange.com/questions/20538/what-is-the-right-order-when-using-frontmatter-tableofcontents-mainmatter 209 | 210 | %\appendix 211 | 212 | \backmatter 213 | 214 | %---------------------------------------------------------------------------------------- 215 | % BIBLIOGRAPHY 216 | %---------------------------------------------------------------------------------------- 217 | 218 | \bibliography{urib} 219 | \bibliographystyle{abbrvnat} 220 | 221 | %---------------------------------------------------------------------------------------- 222 | 223 | \printindex % Print the index at the very end of the document 224 | 225 | \end{schemeregion} 226 | \end{document} 227 | -------------------------------------------------------------------------------- /latex/xeslatex: -------------------------------------------------------------------------------- 1 | echo ' 2 | (load "./slatex/slatex.scm") 3 | (slatex::process-main-tex-file "'$1'")' | petite 4 | 5 | if test -f pltexchk.jnk 6 | then xetex $1; rm pltexchk.jnk 7 | else xelatex $1 8 | fi 9 | -------------------------------------------------------------------------------- /old-outlines/most-recent-outline.txt: -------------------------------------------------------------------------------- 1 | *** CRITICAL DECISIONS *** 2 | 3 | =============== 4 | 5 | PRIMARY GOAL: Get the reader to the point where they can start modifying, experimenting with, extending the relational interpreter. 6 | 7 | SECONDARY GOAL: Inspire the reader, making them want to to explore/play with the relational interpreter, relational programming, miniKanren. 8 | 9 | I want to maintain laser-like focus on these goals. Divergence from these goals is permissible only in footnotes. 10 | 11 | =============== 12 | 13 | BOOK SIZE: Thin. Everything in the book has to advance the relational interpreter story. 14 | 15 | The point of the book is to teach the reader what they need to know to start working with/playing with/extending the relational interpreter on their own. The point of the book is *not* to teach the reader everything I know about relational interpreters, relational programming, miniKanren, programming languages, whatever. 16 | 17 | =============== 18 | 19 | AUDIENCE: As wide as possible. 20 | 21 | I'm *not* going to assume the audience knows Scheme, interpreters, logic programming, functional programming, or miniKanren. 22 | 23 | =============== 24 | 25 | GUIDING PRINCIPLE: Keep the scope narrow and the audience wide. 26 | 27 | =============== 28 | 29 | LANGUAGE: Scheme 30 | 31 | It's the language I know best, the language I use, the language of most of the research papers and TRS. It's a very small language, and compatible with Racket. Should be easy for Clojurers and others to pick up. 32 | 33 | =============== 34 | 35 | WRITING STYLE: Begin with a bang. 36 | 37 | Remove the boring/irrelevant parts. 38 | 39 | Should be able to stamp the cover with: "All non-awesomeness has been removed from this book." 40 | 41 | Introduce Scheme/PL/mk/interpreter concepts just-in-time when possible. 42 | 43 | Get to the mind-blowing stuff as soon as possible. 44 | 45 | Make the excitement and enthusiasm I feel personally shine through. 46 | 47 | =============== 48 | 49 | THINGS TO INCLUDE IN THE BOOK: So the reader can stand on their own when investigating relational interpreters. 50 | 51 | * Just enough Scheme 52 | * Just enough logic programming 53 | * Just enough PL theory 54 | 55 | =============== 56 | 57 | THINGS *NOT* TO INCLUDE IN THE BOOK: (Unless I directly relate them to the relational interpreter.) 58 | 59 | * Sodoku 60 | * SEND MORE MONEY 61 | * CLP(FD) 62 | * Zebra 63 | * conda/condu/once/project 64 | * C311/PL material not absolutely required 65 | * general logic programming 66 | * Prolog, Curry, Mercury, Godel, Oz, etc. 67 | 68 | =============== 69 | 70 | WORKING TITLE: Playing with Relational Interpreters 71 | 72 | 'Play' is the critical aspect. Can I capture the feeling of play that I enjoy so much? 73 | 74 | =============== 75 | 76 | 77 | High Level 78 | ----------- 79 | 80 | The relational interpreter is the really amazing thing, which can apparently be pushed much further. First-class macros, use the Chez macro expander to expand to the core language rewrite the relational interp to primitives in the environment, specialization, effects, monads, program synthesis, symbolic execution, test generation, other languages, etc. 81 | 82 | Cool examples of the relational interpreter at work: 83 | 84 | * Quines 85 | 86 | * programs that evaluate to (I love you) 87 | 88 | * programs that evaluate to 6 89 | 90 | * example-based synthesis 91 | 92 | * running 'append' in the relational interpreter 93 | 94 | * mutually-recursive functions encoding a state machine, in the relational interpreter 95 | 96 | * theorem prover, from running a proof checker in the relational interpreter 97 | 98 | * higher-order Scheme interpreter (3x5 card from C311), in the relational interpreter 99 | 100 | * symbolic/concolic execution 101 | 102 | * test generation 103 | 104 | These things are what I want to show off, talk about, explore. 105 | 106 | Want to show the reader *how* to write relational interpreters. 107 | 108 | 109 | 110 | More Detail 111 | ----------- 112 | 113 | Start with a bang -- try to immediately start showing what the 114 | rel. interp. can do. How can I show this off to a non-expert in way 115 | a they can immediately appreciate? 116 | 117 | Show the reader something jaw-dropping. Promise that they will be 118 | able to understand and contribute to the state of the art of research 119 | in this area by the time they finish the book. As a side-effect they 120 | will also know something about Scheme, FP, LP, RP, interpreters, 121 | PL/DSL implementation, etc. These are bonuses -- the main focus is 122 | the rel. interp. 123 | 124 | Teach minimal mk and Scheme needed to play with the rel. interp. The 125 | playing should come first. Really only need to teach 'run' and the 126 | call to 'evalo' to get fairly far with the rel. interp. Can introduce 127 | ==, =/=, fresh, etc., later. 128 | 129 | Probably want to provide an equivalent Scheme interp, to "normalize" 130 | over the 'eval' interface, so we can keep the language of 131 | rel. interp. and of Scheme in synch. Then we can make sure calls to 132 | 'eval' mirror calls to 'evalo', the same language is supported, etc. 133 | 134 | Could try to teach Scheme through this interp. Then can introduce 135 | re. interp. whenever it feels right. The start playing. 136 | 137 | 138 | 139 | [ Meta comment: Celeste mentioned the "snowflake" approach to an 140 | outline - go all the way through at a high level, go back and do 141 | another pass that adds details, repeat. ] 142 | 143 | 144 | 145 | Even More Detail 146 | ---------------- 147 | 148 | What would be awesome: Scheme interp, mk interp matches the same 149 | language, which is the language I teach, and also the language used to 150 | impl. the Scheme interp. *and* the mk impl. 151 | 152 | After learning Scheme and a tiny bit of mk by playing with the 153 | rel. interp, show how to write a Scheme interp. No need to teach how 154 | to impl. 'append', or other examples of Scheme programming, since we 155 | learned all this by playing with the interpreter!! 156 | 157 | After we impl the standard interp, time to learn mk. I think we'll 158 | need to learn 'appendo', translation, etc. However, before hand we 159 | can have played with 'append' in the rel interp, for example. Once we 160 | know how to write 'append', we can run it in the regular interp and 161 | play with it in the mk interp. 162 | 163 | After we have learned enough mk programming, start writing the rel 164 | interp. Might start first with environ helpers or whatever. 165 | 166 | Could potentially play w/Scheme interp implemented in the rel interp 167 | before trying to implement 'evalo'! 168 | 169 | How would I put the above into practice? 170 | 171 | This all depends on the pieces fitting together, which I'm not sure I 172 | can pull off. 173 | 174 | [figure] 175 | 176 | I would certainly keep myself honest if I wrote the Scheme interp 177 | first (using primitives stored in the environment, probably), then ran 178 | the Scheme interp in the Scheme interp, used *that* interp to impl mk 179 | (perhaps as an interpreter??), then used mk to impl the rel interp, 180 | which is then used to impl the Scheme interp. 181 | 182 | For example (where all 'Scheme interp' are identical impls of the same 183 | language): 184 | 185 | --------------------- 186 | | Scheme interp | 187 | --------------------- 188 | | 189 | --------------------- 190 | | Scheme interp | 191 | --------------------- 192 | | 193 | --------------------- 194 | | mk impl | 195 | --------------------- 196 | | 197 | --------------------- 198 | | rel Scheme interp | 199 | --------------------- 200 | | 201 | --------------------- 202 | | Scheme interp | 203 | --------------------- 204 | | 205 | --------------------- 206 | | Scheme expr | 207 | --------------------- 208 | 209 | 210 | At the possible cost of not keeping ourselves honest, we can simplify 211 | this picture by removing the second Schem interp: 212 | 213 | --------------------- 214 | | Scheme interp | 215 | --------------------- 216 | | 217 | --------------------- 218 | | mk impl | 219 | --------------------- 220 | | 221 | --------------------- 222 | | rel Scheme interp | 223 | --------------------- 224 | | 225 | --------------------- 226 | | Scheme interp | 227 | --------------------- 228 | | 229 | --------------------- 230 | | Scheme expr | 231 | --------------------- 232 | 233 | We might want to make the mk impl an interp, which conceptually would 234 | keep the book, and this nested models, about interpreters all the way 235 | through. 236 | 237 | We may need to use partial evaluation to speed up this stack. 238 | However, to some extent we are just trying to show the relationship 239 | between these pieces, so it probably doesn't matter that this would 240 | run super slow. 241 | 242 | 243 | 244 | Could we impl mk as an interp? And if we can, what happens when we rn 245 | the mk interp in the rel Scheme interp? This sounds awesome and worth 246 | doing. 247 | 248 | We would end up with something like this: 249 | 250 | --------------------- 251 | | Scheme | 252 | --------------------- 253 | | 254 | ----------------------- 255 | | mk interp in Scheme | 256 | ----------------------- 257 | | 258 | --------------------- 259 | | rel Scheme interp | 260 | --------------------- 261 | | 262 | ----------------------- 263 | | mk interp in Scheme | 264 | ----------------------- 265 | | 266 | --------------------- 267 | | mk expr | 268 | --------------------- 269 | 270 | We should end up with higher-order predicates in the mk interp running 271 | in the relational Scheme interp. Really, could also keep the 272 | top-level mk as the usual embedding: 273 | 274 | 275 | --------------------- 276 | | Scheme | 277 | --------------------- 278 | | 279 | ----------------------- 280 | | usual mk embedding | 281 | ----------------------- 282 | | 283 | --------------------- 284 | | rel Scheme interp | 285 | --------------------- 286 | | 287 | ----------------------- 288 | | mk interp in Scheme | 289 | ----------------------- 290 | | 291 | --------------------- 292 | | mk expr | 293 | --------------------- 294 | 295 | 296 | What would be involved in writing an mk interp? Can we write 297 | something minimal, in the C311 Scheme interp spirit? We would 298 | probably need: 299 | 300 | fresh 301 | conde 302 | == 303 | =/= 304 | symbolo 305 | absento (possibly restricted to a ground atom as first arg) 306 | run 307 | 308 | and the reifier... 309 | 310 | Could we get away without numbero? Do we need project? 311 | 312 | 313 | Seems like the viability of this entire approach rests on the ability 314 | to write an interpreter for mk, using a small enough subset of Scheme 315 | that itself can be expressed in the rel Scheme interp. 316 | 317 | Could try the Nada "tag everything and just use ==" approach to 318 | writing relational Scheme interps. This would have the advantage of 319 | only requiring the impl of ==, rather than also =/=, symbolo, absento, 320 | and maybe numbero. I wonder what the corresponding fully-tagged 321 | Scheme interp would look like. 322 | 323 | Could potentially disallow shadowing of built-ins in both Scheme 324 | interps and rel interp, although this doesn't seem very classy. I'd 325 | prefer to put primitives in the environment. 326 | -------------------------------------------------------------------------------- /old-outlines/outline-big.org: -------------------------------------------------------------------------------- 1 | OUTLINE FOR 'BIG' BOOK--WHAT I KNOW ABOUT RELATIONAL PROGRAMMING 2 | 3 | 4 | look at: dissertation, papers, summer school, miniKanren.org, blog 5 | posts, core.logic pages, tutorials, videos of talks I've given, etc. 6 | 7 | also create an outline for a minimal book, just introducing the quines-generating interpreter 8 | 9 | think about how I normally present these ideas to people 10 | 11 | what exercises do I want? 12 | 13 | figure out which examples, and what code, goes where 14 | 15 | figure out where I 16 | 17 | [where to put? these] 18 | 19 | 20 | History of miniKanren 21 | 22 | miniKanren resources 23 | 24 | miniKanren design decisions and tradeoffs 25 | 26 | 27 | ** Preface 28 | *** Audience 29 | *** The Language 30 | *** Goal 31 | *** Running the code 32 | *** Typographical conventions 33 | [can massage the typographical conventions text from my dissertation (section 1.5)] 34 | *** Margin notes 35 | *** Acknowledgements 36 | * Part I: Introduction to miniKanren 37 | ** Core miniKanren 38 | *** == 39 | *** run 40 | *** fresh 41 | *** conde 42 | *** Properties of reified answers 43 | *** Simple examples 44 | ** Scheme as a host language 45 | *** Values 46 | *** Fun with recursion 47 | *** Mixing Scheme and miniKanren 48 | ** Translating simple Scheme functions to miniKanren relations [hand-wavy approach] 49 | *** append 50 | hello world of logic programming 51 | example of append in Scheme 52 | add an 'o' to the name 53 | add an 'out' argument (and why this is not the best name) 54 | cond becomes conde 55 | (null? l) becomes (== '()) 56 | values that were previously returned are now 57 | run it forward 58 | run it backwards, sideways, etc 59 | divergence! 60 | reordering of goals 61 | *** rember [aka, surpriseo!] 62 | *** member 63 | **** Rules for translating a predicate 64 | When translating a predicate, is is usually best to represent true as success, and false as failure 65 | This means no 'out' argument. Also, conde clauses that fail can be removed 66 | member shows similar behavior to rember/surpriseo 67 | Is is possible to use an 'out' argument to explicitly represent true and false; 68 | this may be slower, and may make the code longer and more complicated, but has 69 | the advantage of being able to synthesize input values that result in false 70 | *** [a couple other examples using only core miniKanren] 71 | *** Translating impure Scheme programs 72 | **** Errors are represented as failure 73 | *** An informal algorithm for translating Scheme programs to miniKanren 74 | ** Additional constraints 75 | *** =/= 76 | **** rember reconsidered 77 | can fix member in a similar fashion 78 | *** symbolo and numbero 79 | *** absento 80 | *** eigen 81 | ** Divergence and negation 82 | *** Different types of divergence [based on Chapter 5 in my dissertation ('A Slight Divergence')] 83 | [need to make sure this section very clearly focuses on divergence vs. finite failure; I'm not sure organization based on 'A Slight Divergence' works best, especially since it depends on detailed knowledge of the implementation, which hasn't been presented yet. Although the topics discussed in that chapter are important, and should appear in the book] 84 | could include margin note on how reification can diverge is we allow circularities by removing the occur check in unification 85 | could then point out how unification could be extended to handle 'rational' trees, in which both unification and the reifier allow circularities without a problem 86 | also could include margin note on depth-first search being incomplete, and showing an example where that causes divergence 87 | **** run* with an unbounded number of answers 88 | **** run n where there are fewer than n answers 89 | ***** Finite failure vs. divergence 90 | (run 1 (q) (fresh () alwayso fail)) is the canonical example 91 | *** Techniques and tricks for apparently divergent queries 92 | ** Representing numbers in miniKanren 93 | *** Peano arithmetic 94 | *** Oleg numbers 95 | *** CLP(fd) 96 | [do we even have an implementation of mK with the other constraints, which also has CLP(fd)? sigh] 97 | *** Choosing which number system to use 98 | [stupid reification of CLP(fd) is part of the problem here--our reifier is too eager] 99 | ** Hueristics for translating Scheme to miniKanren 100 | **** Non-overlapping principle 101 | **** Conde clauses that always fail can be removed (which may improve divergence behavior for some queries) 102 | **** Translating predicates 103 | **** Recursive goals should come last in a fresh or run, or within a conde clause 104 | **** Non-recursive clauses should come first in a conde 105 | ***** An exception: intentional generating "erroneous" inputs 106 | ** A more mechanical approach 107 | **** A-Normal form 108 | **** Defunctionalization 109 | **** Pattern matching 110 | ***** Enforcing non-overlapping 111 | **** Handling negation 112 | ***** =/= and other constraints 113 | ***** Helper relations 114 | **** Examples 115 | ***** append 116 | ***** [more interesting examples, including at least one with negation] 117 | ** Nominal Logic Programming 118 | *** The notion of alpha-equivalence 119 | *** Nominal unification 120 | *** The notion of freshness 121 | *** alphaKanren 122 | *** Example: implementing capture-avoiding substitution 123 | ** Impure operators 124 | *** What it means to be impure 125 | *** conda and condu 126 | relationship with Prolog's cut 127 | using to define 'onceo' 128 | *** project 129 | utility in printing the current state of the substitution 130 | *** copy-termo 131 | should be defined in the alphaLeanTAP paper 132 | *** Example: Translating simple Prolog code into miniKanren 133 | *** When are impure operators useful? 134 | *** Avoiding impure operators 135 | ** Debugging miniKanren programs 136 | * Part II: Exploring the Chomsky Hierarchy 137 | ** Regular expression matching 138 | ** Deterministic finite automata 139 | ** Relational exploration of programming languages fundamentals 140 | *** Lexical scope 141 | *** Relational program transformations 142 | ** Relational interpreters 143 | *** Relational Scheme interpreter 144 | **** Generating Quines 145 | ** Type inference 146 | *** Type inhabitation 147 | * Part III: Implementation 148 | ** Unification and substitutions 149 | ** Reification 150 | ** microKanren 151 | ** Building miniKanren on top of microKanren 152 | ** Alternate run interfaces 153 | ** Tabling 154 | ** Adding constraints other than unification 155 | *** Example 1: Adding disequality constraints 156 | *** Example 2: Adding symbolo and numbero 157 | *** Adding other constraints 158 | -------------------------------------------------------------------------------- /old-src/matche.scm: -------------------------------------------------------------------------------- 1 | ; new version of matche 2 | ; fixes depth related issues, and works with dots 3 | ; 4 | ; https://github.com/calvis/cKanren/blob/dev/cKanren/matche.rkt#L54 5 | 6 | (define syntax->list 7 | (lambda (e) 8 | (syntax-case e () 9 | [() '()] 10 | [(x . r) (cons #'x (syntax->list #'r))]))) 11 | 12 | (define-syntax defmatche 13 | (lambda (stx) 14 | (syntax-case stx () 15 | [(defmatche (name args ...) clause ...) 16 | #'(define (name args ...) 17 | (matche (args ...) clause ...))]))) 18 | 19 | (define-syntax lambdae 20 | (syntax-rules () 21 | ((_ (x ...) c c* ...) 22 | (lambda (x ...) (matche (x ...) c c* ...))))) 23 | 24 | (define-syntax matche 25 | (lambda (stx) 26 | (syntax-case stx () 27 | [(matche (v ...) ([pat ...] g ...) ...) 28 | (let () 29 | (define remove-duplicates 30 | (lambda (ls eq-pred) 31 | (cond 32 | [(null? ls) '()] 33 | [(memp (lambda (x) (eq-pred (car ls) x)) (cdr ls)) 34 | (remove-duplicates (cdr ls) eq-pred)] 35 | [else (cons (car ls) (remove-duplicates (cdr ls) eq-pred))]))) 36 | (define parse-pattern 37 | (lambda (args pat) 38 | (syntax-case #`(#,args #,pat) () 39 | [(() ()) #'(() () ())] 40 | [((a args ...) [p pat ...]) 41 | (with-syntax ([(p^ (c ...) (x ...)) 42 | (parse-patterns-for-arg #'a #'p)]) 43 | (with-syntax ([([pat^ ...] (c^ ...) (x^ ...)) 44 | (parse-pattern #'(args ...) #'[pat ...])]) 45 | #'([p^ pat^ ...] (c ... c^ ...) (x ... x^ ...))))] 46 | [x (error 'parse-pattern "bad syntax ~s ~s" args pat)]))) 47 | (define parse-patterns-for-arg 48 | (lambda (v pat) 49 | (define loop 50 | (lambda (pat) 51 | (syntax-case pat (unquote ?? ?) ; ?? is the new _, since _ isn't legal in R6 52 | [(unquote ??) 53 | (with-syntax ([_new (generate-temporary #'?_)]) 54 | #'((unquote _new) () (_new)))] 55 | [(unquote x) 56 | (when (free-identifier=? #'x v) 57 | (error 'matche "argument ~s appears in pattern at an invalid depth" 58 | (syntax->datum #'x))) 59 | #'((unquote x) () (x))] 60 | [(unquote (? c x)) 61 | (when (free-identifier=? #'x v) 62 | (error 'matche "argument ~s appears in pattern at an invalid depth" 63 | (syntax->datum #'x))) 64 | #'((unquote x) ((c x)) (x))] 65 | [(a . d) 66 | (with-syntax ([((pat1 (c1 ...) (x1 ...)) 67 | (pat2 (c2 ...) (x2 ...))) 68 | (map loop (syntax->list #'(a d)))]) 69 | #'((pat1 . pat2) (c1 ... c2 ...) (x1 ... x2 ...)))] 70 | [x #'(x () ())]))) 71 | (syntax-case pat (unquote ?) 72 | [(unquote u) 73 | (cond 74 | [(and (identifier? #'u) 75 | (free-identifier=? v #'u)) 76 | #'((unquote u) () ())] 77 | [else (loop pat)])] 78 | [(unquote (? c u)) 79 | (cond 80 | [(and (identifier? #'u) 81 | (free-identifier=? v #'u)) 82 | #'((unquote u) ((c x)) ())] 83 | [else (loop pat)])] 84 | [else (loop pat)]))) 85 | (unless 86 | (andmap (lambda (y) (= (length (syntax->list #'(v ...))) (length y))) 87 | (syntax->list #'([pat ...] ...))) 88 | (error 'matche "pattern wrong length blah")) 89 | (with-syntax ([(([pat^ ...] (c ...) (x ...)) ...) 90 | (map (lambda (y) (parse-pattern #'(v ...) y)) 91 | (syntax->list #'([pat ...] ...)))]) 92 | (with-syntax ([((x^ ...) ...) 93 | (map (lambda (ls) 94 | (remove-duplicates (syntax->list ls) free-identifier=?)) 95 | (syntax->list #'((x ...) ...)))]) 96 | (with-syntax ([body 97 | #'(conde 98 | [(fresh (x^ ...) c ... (== `[pat^ ...] ls) g ...)] 99 | ...)]) 100 | #'(let ([ls (list v ...)]) body)))))] 101 | [(matche v (pat g ...) ...) 102 | #'(matche (v) ([pat] g ...) ...)]))) 103 | -------------------------------------------------------------------------------- /old-src/pmatch.scm: -------------------------------------------------------------------------------- 1 | ;; This is a new version of pmatch (August 8, 2012). 2 | ;; It has two important new features: 3 | ;; 1. It allows for a name to be given to the pmatch if an error ensues. 4 | ;; 2. A line from the specification has been removed. (see below). Without 5 | ;; that line removed, it was impossible for a pattern to be (quote ,x), 6 | ;; which might be worth having especially when we write an interpreter 7 | ;; for Scheme, which includes quote as a language form. 8 | 9 | ;;; Code written by Oleg Kiselyov 10 | ;; (http://pobox.com/~oleg/ftp/) 11 | ;;; 12 | ;;; Taken from leanTAP.scm 13 | ;;; http://kanren.cvs.sourceforge.net/kanren/kanren/mini/leanTAP.scm?view=log 14 | 15 | ; A simple linear pattern matcher 16 | ; It is efficient (generates code at macro-expansion time) and simple: 17 | ; it should work on any R5RS (and R6RS) Scheme system. 18 | 19 | ; (pmatch exp ...[]) 20 | ; ::= ( exp ...) 21 | ; ::= (else exp ...) 22 | ; ::= boolean exp | () 23 | ; :: = 24 | ; ,var -- matches always and binds the var 25 | ; pattern must be linear! No check is done 26 | ; _ -- matches always 27 | ; 'exp -- comparison with exp (using equal?) REMOVED (August 8, 2012) 28 | ; exp -- comparison with exp (using equal?) 29 | ; ( ...) -- matches the list of patterns 30 | ; ( . ) -- ditto 31 | ; () -- matches the empty list 32 | 33 | (define-syntax pmatch 34 | (syntax-rules (else guard) 35 | ((_ v (e ...) ...) 36 | (pmatch-aux #f v (e ...) ...)) 37 | ((_ v name (e ...) ...) 38 | (pmatch-aux name v (e ...) ...)))) 39 | 40 | (define-syntax pmatch-aux 41 | (syntax-rules (else guard) 42 | ((_ name (rator rand ...) cs ...) 43 | (let ((v (rator rand ...))) 44 | (pmatch-aux name v cs ...))) 45 | ((_ name v) 46 | (begin 47 | (if 'name 48 | (printf "pmatch ~s failed\n~s\n" 'name v) 49 | (printf "pmatch failed\n ~s\n" v)) 50 | (error 'pmatch "match failed"))) 51 | ((_ name v (else e0 e ...)) (begin e0 e ...)) 52 | ((_ name v (pat (guard g ...) e0 e ...) cs ...) 53 | (let ((fk (lambda () (pmatch-aux name v cs ...)))) 54 | (ppat v pat (if (and g ...) (begin e0 e ...) (fk)) (fk)))) 55 | ((_ name v (pat e0 e ...) cs ...) 56 | (let ((fk (lambda () (pmatch-aux name v cs ...)))) 57 | (ppat v pat (begin e0 e ...) (fk)))))) 58 | 59 | (define-syntax ppat 60 | (syntax-rules (? comma unquote) 61 | ((_ v ? kt kf) kt) 62 | ((_ v () kt kf) (if (null? v) kt kf)) 63 | ; ((_ v (quote lit) kt kf) (if (equal? v (quote lit)) kt kf)) 64 | ((_ v (unquote var) kt kf) (let ((var v)) kt)) 65 | ((_ v (x . y) kt kf) 66 | (if (pair? v) 67 | (let ((vx (car v)) (vy (cdr v))) 68 | (ppat vx x (ppat vy y kt kf) kf)) 69 | kf)) 70 | ((_ v lit kt kf) (if (equal? v (quote lit)) kt kf)))) 71 | -------------------------------------------------------------------------------- /old-src/test-check.scm: -------------------------------------------------------------------------------- 1 | (define-syntax test 2 | (syntax-rules () 3 | ((_ title tested-expression expected-result) 4 | (begin 5 | (printf "Testing ~s\n" title) 6 | (let* ((expected expected-result) 7 | (produced tested-expression)) 8 | (or (equal? expected produced) 9 | (printf "Failed: ~a~%Expected: ~a~%Computed: ~a~%" 10 | 'tested-expression expected produced))))))) 11 | --------------------------------------------------------------------------------