From bd9733926076885e3417b74de76e4c9c7bc56254 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 20 Feb 2017 00:05:28 -0800 Subject: Import Upstream version 2c7 --- ANNOUNCE | 110 +- Bev2slib.scm | 58 +- ChangeLog | 520 ++- FAQ | 20 +- Makefile | 126 +- README | 17 +- RScheme.init | 282 ++ STk.init | 248 ++ Template.scm | 28 +- alistab.scm | 15 +- arraymap.scm | 2 +- batch.scm | 151 +- bigloo.init | 248 ++ chap.scm | 6 +- charplot.scm | 26 +- chez.init | 605 ++- collect.scm | 10 +- comlist.scm | 22 +- cring.scm | 99 +- dbrowse.scm | 16 +- debug.scm | 6 +- elk.init | 27 +- factor.scm | 199 +- fft.scm | 70 + fluidlet.scm | 43 +- format.scm | 149 +- formatst.scm | 18 +- gambit.init | 42 +- glob.scm | 246 +- htmlform.scm | 278 +- lineio.scm | 68 +- macscheme.init | 26 +- mbe.scm | 323 +- mitscheme.init | 32 +- mklibcat.scm | 11 +- mwexpand.scm | 46 +- mwsynrul.scm | 20 +- nclients.scm | 385 ++ objdoc.txi | 238 ++ object.scm | 97 + paramlst.scm | 7 +- primes.scm | 187 - printf.scm | 198 +- pscheme.init | 202 + queue.scm | 2 +- randinex.scm | 96 +- random.scm | 167 +- rdms.scm | 42 +- recobj.scm | 55 + require.scm | 67 +- root.scm | 66 + sc4sc3.scm | 2 +- scanf.scm | 2 +- scheme2c.init | 29 +- scheme48.init | 31 +- schmooz.scm | 108 +- scsh.init | 12 +- sierpinski.scm | 2 +- slib.info | 11240 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ slib.texi | 1154 +++--- sort.scm | 2 +- strcase.scm | 2 +- strsrch.scm | 15 +- struct.scm | 6 +- t3.init | 31 +- timezone.scm | 13 +- tzfile.scm | 2 +- umbscheme.init | 263 ++ vscm.init | 29 +- wttree.scm | 32 +- yasos.scm | 299 -- yasyn.scm | 201 + 72 files changed, 16859 insertions(+), 2638 deletions(-) create mode 100644 RScheme.init create mode 100644 STk.init create mode 100644 bigloo.init create mode 100644 fft.scm create mode 100644 nclients.scm create mode 100644 objdoc.txi create mode 100644 object.scm delete mode 100644 primes.scm create mode 100644 pscheme.init create mode 100644 recobj.scm create mode 100644 slib.info create mode 100644 umbscheme.init delete mode 100644 yasos.scm create mode 100644 yasyn.scm diff --git a/ANNOUNCE b/ANNOUNCE index 3545637..3f94e63 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,93 +1,53 @@ -This message announces the availability of Scheme Library release -slib2c3. - -New in slib2c3 are filename matching (a la Bash glob) and `Schmooz', a -lightweight markup language for interspersing Texinfo documentation -with Scheme source code. - - * slib.texi (Filenames): documented pattern strings. - * Makefile: Added $srcdir to TEXINPUTS for TeX. - * slib.texi (Schmooz): Added documentation. - * Makefile (info htmlform.txi): made smarter about when to run - schmooz. - * slib.texi (Format): documentation moved to fmtdoc.txi. - * glob.scm (filename:match?? filename:match-ci??): aliases added. - * primes.scm (primes:prngs): added to reduce likelyhood of - reentrant random calls. - * random.scm: rewritten using new seedable RNG. - * randinex.scm (random:uniform): Rewritten for new RNG. - * primes.scm (primes:dbsp?): Now requires 'root and uses - integer-sqrt for sqrt on platforms not supporting inexacts. - * record.scm (rtd-name): Fixed so record rtds print. - * cring.scm (*): Number distribution requires separate treatment. - * factor.scm (prime:factor): (factor 0) now returns '(0) rather - than infinite-looping. - * cring.scm (*): Added check for (* -1 (- )) case. - * prec.scm (prec:warn): now takes arbitrary number of arguments. - (prec:nofix): - (prec:postfix): extra arguments are appended to the rules list; - not bound. - * qp.scm (qp:qp): *qp-width* set to #f now the same as *qp-width* - set to 0 -- the full expressions are printed. - * prec.scm (prec:nofix): Added . binds args, which are combined - with *syn-rules*. - - From: Radey Shouman - - * glob.scm: Added. - * schmooz.scm (schmooz): Added @args markup command. - * schmooz.scm (schmooz): Now tries harder to determine whether a - definition is of a procedure or non-procedure variable. - Recognizes DEFMACRO, DEFINE-SYNTAX. - * schmooz.scm (scheme-args->macros): Now passed either a symbol, - for variable definition, or a possibly improper list, for - function/macro definition. For the variable definition case - generates @var{... for @0 instead of @code{... Now uses APPEND to - be more readable. - -SLIB is a portable scheme library meant to provide compatibiliy and -utility functions for all standard scheme implementations. - -SLIB includes initialization files for Chez, ELK 2.1, GAMBIT, -MacScheme, MITScheme, scheme->C, Scheme48, SCM, scsh, T3.1, and VSCM. +This message announces the availability of Scheme Library release slib2c7. + +New in slib2c7: + + * charplot.scm (charplot:number->string): printf %g gets rid of + microscopic fractions. + * printf.scm (%g): Make precision threshold work for both + fractions and integers. + * nclients.scm (browse-url-netscape): Try running netscape in + background. + * batch.scm (write-batch-line): Added slib:warn. + * paramlst.scm (check-parameters): Improved warning. + * batch.scm (batch:command): Renamed from batch:system. + (batch:try-command): Renamed from batch:try-system. + (batch:try-chopped-command): Added. + (batch:apply-chop-to-fit): Removed. + * glob.scm (replace-suffix): Now works. + * slib.texi: Put description and URL into slib_toc.html. + +SLIB is a portable Scheme library providing compatibiliy and utility +functions for all standard Scheme implementations. + +SLIB includes initialization files for Bigloo, Chez, ELK, GAMBIT, +MacScheme, MITScheme, PocketScheme, RScheme Scheme->C, Scheme48, SCM, +SCSH, T3.1, UMB-Scheme, and VSCM. Documentation includes a manifest, installation instructions, and coding standards for the library. Documentation of each library package is supplied. SLIB Documentation is online at: - http://www-swiss.ai.mit.edu/~jaffer/SLIB.html + http://swissnet.ai.mit.edu/~jaffer/SLIB.html -SLIB is a portable Scheme library: - ftp-swiss.ai.mit.edu:pub/scm/slib2c3.tar.gz - prep.ai.mit.edu:pub/gnu/jacal/slib2c3.tar.gz +SLIB source is available from: + http://swissnet.ai.mit.edu/ftpdir/scm/slib2c7.zip + ftp.gnu.org:pub/gnu/jacal/slib2c7.zip (FTP instructions follow) SLIB-PSD is a portable debugger for Scheme (requires emacs editor): - ftp-swiss.ai.mit.edu:pub/scm/slib-psd1-3.tar.gz - prep.ai.mit.edu:pub/gnu/jacal/slib-psd1-3.tar.gz + http://swissnet.ai.mit.edu/ftpdir/scm/slib-psd1-3.zip + ftp.gnu.org:pub/gnu/jacal/slib-psd1-3.zip SCHELOG is an embedding of Prolog in Scheme+SLIB: http://www.cs.rice.edu/CS/PLT/packages/schelog/ Programs for printing and viewing TexInfo documentation (which SLIB has) come with GNU Emacs or can be obtained via ftp from: -prep.ai.mit.edu:pub/gnu/texinfo-3.1.tar.gz + ftp.gnu.org:pub/gnu/texinfo/texinfo-4.0.tar.gz -Files in these directories are compressed with patent-free gzip (no -relation to zip). The program to uncompress them is available from - prep.ai.mit.edu:pub/gnu/gzip-1.2.4.tar - prep.ai.mit.edu:pub/gnu/gzip-1.2.4.shar - prep.ai.mit.edu:pub/gnu/gzip-1.2.4.msdos.exe + -=-=- - ftp ftp-swiss.ai.mit.edu (anonymous) + ftp ftp.gnu.org (anonymous) bin - cd pub/scm - get slib2c3.tar.gz -or - ftp prep.ai.mit.edu (anonymous) cd pub/gnu/jacal - bin - get slib2c3.tar.gz - - `slib2c3.tar.gz' is a compressed tar file of a Scheme Library. - -Remember to use binary mode when transferring the *.tar.gz files. + get slib2c5.zip diff --git a/Bev2slib.scm b/Bev2slib.scm index 1198842..24a7c68 100644 --- a/Bev2slib.scm +++ b/Bev2slib.scm @@ -1,45 +1,21 @@ -;; Copyright (C) 1997 Free Software Foundation, Inc. -;; -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 2, or (at your option) -;; any later version. -;; -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. -;; -;; You should have received a copy of the GNU General Public License -;; along with this software; see the file COPYING. If not, write to -;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. -;; -;; As a special exception, the Free Software Foundation gives permission -;; for additional uses of the text contained in its release of GUILE. -;; -;; The exception is that, if you link the GUILE library with other files -;; to produce an executable, this does not by itself cause the -;; resulting executable to be covered by the GNU General Public License. -;; Your use of that executable is in no way restricted on account of -;; linking the GUILE library code into it. -;; -;; This exception does not however invalidate any other reasons why -;; the executable file might be covered by the GNU General Public License. -;; -;; This exception applies only to the code released by the -;; Free Software Foundation under the name GUILE. If you copy -;; code from other Free Software Foundation releases into a copy of -;; GUILE, as the General Public License permits, the exception does -;; not apply to the code that you add in this way. To avoid misleading -;; anyone as to the status of such modified files, you must delete -;; this exception notice from them. -;; -;; If you write modifications of your own for GUILE, it is your choice -;; whether to permit this exception to apply to your modifications. -;; If you do not wish that, delete this exception notice. - ;;;; "Bev2slib.scm" Build SLIB catalogs for Stephen Bevan's libraries. -;;; Author: Aubrey Jaffer. +;Copyright (C) 1998 Aubrey Jaffer +; +;Permission to copy this software, to redistribute it, and to use it +;for any purpose is granted, subject to the following restrictions and +;understandings. +; +;1. Any copy made of this software must include this copyright notice +;in full. +; +;2. I have made no warrantee or representation that the operation of +;this software will be error-free, and I am under no obligation to +;provide any services, by way of maintenance, update, or otherwise. +; +;3. In conjunction with products arising from the use of this +;material, there shall be no use of my name in any advertising, +;promotional, or sales literature without prior written consent in +;each case. ;;; Put this file into the implementation-vicinity directory for your ;;; scheme implementation. diff --git a/ChangeLog b/ChangeLog index b7dee8c..e56d1fa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,471 @@ +Sun Dec 5 19:54:35 EST 1999 Aubrey Jaffer + + * require.scm (*SLIB-VERSION*): Bumped from 2c6 to 2c7. + +1999-12-04 Aubrey Jaffer + + * charplot.scm (charplot:number->string): printf %g gets rid of + microscopic fractions. + + * printf.scm (%g): Make precision threshold work for both + fractions and integers. + +1999-12-03 Aubrey Jaffer + + * nclients.scm (browse-url-netscape): Try running netscape in + background. + +1999-11-14 Aubrey Jaffer + + * batch.scm (write-batch-line): Added slib:warn. + +1999-11-01 Aubrey Jaffer + + * paramlst.scm (check-parameters): Improved warning. + +1999-10-31 Aubrey Jaffer + + * batch.scm (batch:command): Renamed from batch:system. + (batch:try-command): Renamed from batch:try-system. + (batch:try-chopped-command): Added. + (batch:apply-chop-to-fit): Removed. + +1999-09-29 Radey Shouman + + * glob.scm (replace-suffix): Now works. + +1999-09-17 Aubrey Jaffer + + * slib.texi: Put description and URL into slib_toc.html. + +Sun Sep 12 22:45:01 EDT 1999 Aubrey Jaffer + + * require.scm (*SLIB-VERSION*): Bumped from 2c5 to 2c6. + +1999-07-08 Aubrey Jaffer + + * format.scm (format:string-capitalize-first): Renamed from + string-capitalize-first. + (format:list-head): Renamed from list-head. + (string-index): Removed. + +1999-06-07 Radey Shouman + + * printf.scm (stdio:parse-float): Now handles strings representing + complex numbers in polar form. + + (stdio:parse-float): Now parses non-real numbers written in + rectangular form. + + (stdio:iprintf): Inexact formats work on non-real numbers assuming + NUMBER->STRING outputs a rectangular format. + + Inexact formats given a string or symbol rather than a number + output "???" if the string cannot be parsed as an inexact number. + +1999-06-06 Aubrey Jaffer + + * fft.scm (fft fft-1): Added. + +1999-06-05 Radey Shouman + + * glob.scm (glob:substitute??): (glob:substitute-ci??): Now accept + a procedure or string as template argument, for more general + transformations. + +1999-05-28 Gary T. Leavens + + * chez.init: Updated for Chez Scheme 6.0a. + + * bigloo.init: Added. + +1999-05-18 Aubrey Jaffer + + * printf.scm (stdio:iprintf): Extra arguments are *not* a bug. + +1999-05-08 Aubrey Jaffer + + * lineio.scm (read-line!): fixed to eat trailing newline when line + length equals string length. + +1999-05-08 Ben Goetter + + * pscheme.init: String-ports added for version Pscheme 0.3.6. + +1999-05-07 + + * charplot.scm (plot-function): Added. + (charplot:plot!): Now will accept array argument. + +1999-05-02 Jim Blandy + + * format.scm (format:format): If the first argument is the format + string, stick a #f on the front of it, so it is now a valid CL + format argument list. This is easier than changing everyplace + else (like the error formatter) that expects it to be in CL form. + The other clause which explicitly tests for this case is now dead + code; remove it. + (format:format-work): Allow `@' and `:' in either order, as per + modern CL behavior. + (format:num->cardinal): Don't assume that an elseless if returns + '() when the condition is false. + +1999-04-22 Radey Shouman + + * root.scm (secant:find-root): Replaced hack to decide on + accepting regula-falsi step with a modified regula-falsi in which + the weight of an "old" function value is repeatedly decreased each + time it is retained. + +1999-04-13 Radey Shouman + + * root.scm (secant:find-root): Now checks that a step is actually + of nonzero length, otherwise small tolerances lead to not + stopping. Tuned for the case that one starting point is much + closer to the root than the other. + +1999-04-08 Ben Goetter + + * pscheme.init: updated with defmacro for version 0.3.3. + +1999-04-04 Aubrey Jaffer + + * lineio.scm: Fixed @args command in documentation-comment. + +1999-03-27 Aubrey Jaffer + + * strsrch.scm (find-string-from-port?): Fixed so procedure + argument is called at most once per character. + +1999-03-11 Radey Shouman + + * fluidlet.scm: Added (require 'common-list-functions), for + MAKE-LIST. + +1999-03-08 Aubrey Jaffer + + * RScheme.init, STk.init, Template.scm, chez.init, elk.init, + gambit.init, macscheme.init, mitscheme.init, pscheme.init, + scheme2c.init, scheme48.init, scsh.init, t3.init, vscm.init: Added + scheme-implementation-home-page definition + +1999-03-04 radey + + * root.scm (secant:find-bracketed-root): Added, requires (f x0) + and (f x1) to have opposite signs. + +1999-03-03 Radey Shouman + + * printf.scm (stdio:printf): Tweaks to %k format so that the + precision indicates the number of significant digits, as in %g + format. + +1999-03-02 Radey Shouman + + * printf.scm (stdio:printf): %k format now uses %f instead of %g + to format the scaled number. + + * root.scm (secant:find-root): Added. + +1999-02-25 Radey Shouman + + * printf.scm (stdio:iprintf): Fixed bug in %f format, + (printf "%.1f" 0.001) printed "0", now prints "0.0" + +1999-02-12 Hakan L. Younes + + * batch.scm, slib.texi: amiga-gcc port. + +1999-02-10 Radey Shouman + + * printf.scm (stdio:iprintf): K format now prints no prefix if + exponent is beyond the range of the specified prefixes. + + (stdio:iprintf): Added and corrected SI prefixes, ref + http://physics.nist.gov/cuu/Units/prefixes.html . + + (stdio:iprintf): Added numerical format specifiers %K and %k, + which format like %g, except that an SI prefix is output after the + number, which is scaled accordingly. %K outputs a space between + number and prefix, %k does not. It would be good to allow %f and + %e like formatting, but it's not clear how to fit this into the + format string syntax. + +1999-02-09 Aubrey Jaffer + + * rdms.scm (domains:init-data): added number domain. + +1999-01-30 Matthew Flatt + + * mbe.scm (hyg:untag-quasiquote): Added to fix quasiquote in output. + +1999-01-30 Dorai Sitaram + + * mbe.scm (mbe:ellipsis-sub-envs, mbe:append-map): Modified to fix + multiple ellipses problem. + +1999-01-26 Erick Gallesio + + * STk.init: The actual file. + +1999-01-25 Aubrey Jaffer + + * RScheme.init: added; content is from + http://www.rscheme.org/rs/pg1/RScheme.scm + +1999-01-24 Aubrey Jaffer + + * STk.init: added; content is from + http://kaolin.unice.fr/STk/FAQ/FAQ-1.html#ss1.9 + +1999-01-23 Aubrey Jaffer + + * alistab.scm (open-base): Check file exists before opening it. + +1999-01-21 Aubrey Jaffer + + * htmlform.scm (html:start-page): Extra arguments printed in HEAD + (for META tags). + +1999-01-20 Aubrey Jaffer + + * htmlform.scm (make-atval make-plain): use object->string for + non-atomic arguments. + +1999-01-19 Radey Shouman + + * printf.scm (stdio:iprintf): Now reports wrong number of + arguments instead of silently ignoring extra arguments or taking + the CAR of the empty list. + +Sun Jan 17 12:33:31 EST 1999 Aubrey Jaffer + + * require.scm (*SLIB-VERSION*): Bumped from 2c4 to 2c5. + +1999-01-12 Aubrey Jaffer + + * mitscheme.init (char-code-limit): Added. Builtin + char-code-limit is 65536 (NOT!) in MITScheme Version 8.0. + +1999-01-11 Aubrey Jaffer + + * batch.scm (batch:apply-chop-to-fit): fixed off-by-1 error. + +1999-01-10 Aubrey Jaffer + + * randinex.scm: moved (schmooz) documentation here from scm.texi. + (random:uniform1): Renamed from random:uniform. + (random:uniform): Added (takes optional state argument). + (random:normal): Made reentrant. + + * random.scm: moved (schmooz) documentation here from scm.texi. + +1999-01-09 Aubrey Jaffer + + * random.scm (seed->random-state): added. + +1999-01-08 Aubrey Jaffer + + * mitscheme.init (object->limited-string): Added. + + * random.scm (random:random): Fixed embarrassingly stupid bug. + +1999-01-07 Aubrey Jaffer + + * alistab.scm (supported-key-type?): number now allowed. + +1998-12-22 Radey Shouman + + * printf.scm (stdio:round-string): Makes sure result has at least + STRIP-0S characters after the implied decimal point if STRIP-0S is + not false. Fixes bug associated with engineering notation in SCM. + +1998-12-18 Aubrey Jaffer + + * schmooz.scm (schmooz): Converted from replace-suffix to + filename:substitute??. + +1998-12-16 Radey Shouman + + * glob.scm (glob:make-substituter): Made to handle cases where + PATTERN and TEMPLATE have different numbers of literal sections. + + * glob.scm (glob:pattern->tokens): (glob:make-matcher): + (glob:make-substituter): Fixed to accept null strings as literals + to match, for REPLACE-SUFFIX. There is no way to write a glob + pattern that produces such a token, should there be? + +1998-12-15 Radey Shouman + + * glob.scm (glob:substitute??) renamed from glob:transform?? + (filename:substitute??) identical to glob:substitute?? + +1998-12-14 Radey Shouman + + * glob.scm (glob:pattern->tokens): Separated from + GLOB:MAKE-MATCHER. + (glob:make-transformer): + (glob:transform??): + (glob:transform-ci??): Added. + (replace-suffix): Rewritten using GLOB:TRANSFORM?? + +1998-12-09 Aubrey Jaffer + + * yasyn.scm: Restored to SLIB. yasos.scm removed. + * object.scm: Restored to SLIB + * recobj.scm: Restored to SLIB + +1998-12-08 Aubrey Jaffer + + * slib.texi (Copyrights): Added HTML anchor for Copying information. + (Installation): Added HTML anchor for Installation instructions. + +1998-12-02 Aubrey Jaffer + + * fluidlet.scm (fluid-let): Rewritten as defmacro. + +1998-11-30 Radey Shouman + + * fluidlet.scm (fluid-let): Changed macro definition so that it + doesn't depend on being able to combine input from two different + ellipsis patterns. Now produces a nice expansion with + macro-by-example so that one can see exactly what goes wrong. + +1998-11-29 Aubrey Jaffer + + * htmlform.scm (table->html): Table conversion functions added. + +1998-11-27 Aubrey Jaffer + + * nclients.scm (glob-pattern?): Added. + +1998-11-24 Aubrey Jaffer + + * htmlform.scm (html:href-heading): simplified. + +1998-11-16 Aubrey Jaffer + + * htmlform.scm (html:comment): No longer puts `>' alone on line. + (make-plain make-atval): renamed from html:plain and html:atval; + html: functions now all output HTML. + + * nclients.scm (user-email-address): Ported to W95 and WNT. + (make-directory): added. + + * dbrowse.scm (browse:display-table): Column-foreigns restored. + + * htmlform.scm (html:atval html:plain): Now accept numbers. + (html:pre): Added. + (html:start-page html:end-page): Updated to HTML 3.2. HTML header + added. + + * rdms.scm (make-relational-system): column-foreign-list split + into column-foreign-check-list and column-foreign-list. + +1998-11-12 Aubrey Jaffer + + * lineio.scm (display-file): added. Schmoozed docs. + +1998-11-12 Radey Shouman + + * schmooz.scm (schmooz-top): No longer emits @defun lines for + definitions not separated by blank lines unless they have + associated @body comment lines. + +1998-11-11 Radey Shouman + + * fluidlet.scm (fluid-let): Redone to restore variable values even + if a continuation captured in the body is invoked. Now agrees + with MIT Scheme documentation. + +1998-11-11 Aubrey Jaffer + + * nclients.scm: Added net-clients. + + * require.scm (vicinity:suffix?): Abstracted from + program-vicinity. + +1998-11-04 Aubrey Jaffer + + * comlist.scm (remove-duplicates): added. + (adjoin): memq -> memv. + +Tue Nov 3 17:47:32 EST 1998 Aubrey Jaffer + + * require.scm (*SLIB-VERSION*): Bumped from 2c3 to 2c4. + +1998-10-24 Aubrey Jaffer + + * cring.scm: Added procedures to create and manipulate rulesets. + + * cring.scm (cring:db): Distributing / over + led to infinite + loops. Now only distribute *. + +1998-10-19 amu@mit.edu + + * timezone.scm (tzfile:vicinity): Linux RH 5.x moved zoneinfo to + /usr/share and didn't bother to leave a symlink behind. This + caused ctime to print out things in GMT, instead of using the + local time. + +1998-10-01 Aubrey Jaffer + + * factor.scm: Moved documentation to schmooz format. + (prime:prime< prime:prime>): written. + (prime:prngs): added. + (Solovay-Strassen??): No longer tries `1'. + (prime:products): Added list of prime products smaller than + most-positive-fixnum. + (prime:sieve): added to test for primes smaller than largest prime + in prime:products. + (prime:factor): wrapper rewritten. Code cleaned up. + + * primes.scm: removed. + +1998-09-29 Aubrey Jaffer + + * paramlst.scm (check-parameters): Now generates slib:warn when + parameter is wrong type. + + * debug.scm (for-each-top-level-definition-in-file): Now discards + `magic-number' first line of files when first character is `#'. + + * batch.scm (batch:port parms): enabled warning. + +1998-09-28 Aubrey Jaffer + + * scheme2c.init scsh.init t3.init chez.init, vscm.init, + scheme48.init, mitscheme.init, macscheme.init, gambit.init, + elk.init, Template.scm: Placed in public domain to make + distributing modified versions easier. + + * schmooz.scm, htmlform.scm, admin.scm, glob.scm, ChangeLog: + Cleaned a bit. + +1998-09-28 Aubrey Jaffer + + * slib.texi (most-positive-fixnum): fixed description. + +1998-09-22 Ortwin Gasper + + * random.scm (random:random): Removed one-parameter call to + logand. + +1998-09-22 Radey Shouman + + * schmooz.scm: Changed all references to #\nl to #\newline. + Removed all references to #\cr. Trailing whitespace no longer + prevents issuing a defunx for an additional definition form. + +1998-09-21 Aubrey Jaffer + + * primes.scm: Eliminated use of 1+. + (probably-prime?): #f for negative numbers. + +1998-09-19 Jorgen Schaefer + + * glob.scm (glob:match?? glob:match-ci??): fixed wrappers. + 1998-09-11 Aubrey Jaffer * Makefile (release): Uploads SLIB.html. @@ -17,7 +485,7 @@ * schmooz.scm (schmooz): Now tries harder to determine whether a definition is of a procedure or non-procedure variable. Recognizes DEFMACRO, DEFINE-SYNTAX. - + 1998-09-06 Aubrey Jaffer * slib.texi (Schmooz): Added documentation. @@ -79,7 +547,7 @@ 1998-07-08 Aubrey Jaffer * prec.scm (prec:warn): now takes arbitrary number of arguments. - (prec:nofix): + (prec:nofix): (prec:postfix): extra arguments are appended to the rules list; not bound. @@ -98,7 +566,7 @@ 1998-06-08 Aubrey Jaffer * htmlform.scm (html:start-form): added rest of METHOD types. - (html:generate-form command->html): regularized argument order to + (html:generate-form command->html): regularized argument order to `command method action'. * dbutil.scm (add-domain): Changed from row:insert to row:update. @@ -142,7 +610,7 @@ o * require.scm (*SLIB-VERSION*): Bumped from 2c1 to 2c2. * schmooz.scm: Texinfo document generator for Scheme programs. 1998-06-02 Aubrey Jaffer - + * htmlform.scm: Added documentation. (http:send-error-page): scope of fluid-let was wrong. @@ -210,7 +678,7 @@ Tue Apr 14 16:28:20 EDT 1998 Aubrey Jaffer 1998-02-11 Aubrey Jaffer - * slib.texi (Top): + * slib.texi (Top): (Extra-SLIB Packages): Converted to use of new texinfo feature @url. @@ -328,7 +796,7 @@ Wed Oct 29 22:49:15 1997 Aubrey Jaffer vicinities. Thu Oct 23 23:14:33 1997 Eric Marsden - + * factor.scm (prime:product): added EXACT? test. Mon Oct 20 19:33:41 1997 Aubrey Jaffer @@ -544,8 +1012,8 @@ Sat Feb 22 10:18:36 1997 Aubrey Jaffer system is not provided. (system:success?): added. - * wttree.scm (error): - (error:wrong-type-argument): + * wttree.scm (error): + (error:wrong-type-argument): (error:bad-range-argument): Stubs added for non-MITScheme implementations. @@ -650,9 +1118,9 @@ Mon Feb 19 15:48:06 1996 Aubrey Jaffer * scanf.scm (stdio:scan-and-set): Removed flush-whitespace from all conversion specifications per suggestion from - oleg@mozart.compsci.com (Oleg Kiselyov). + oleg@acm.org (Oleg Kiselyov). -Sat Feb 3 00:02:06 1996 Oleg Kiselyov (oleg@ponder.csci.unt.edu) +Sat Feb 3 00:02:06 1996 Oleg Kiselyov (oleg@acm.org) * strsrch.scm (string-index substring? find-string-from-port?): added. @@ -797,17 +1265,17 @@ Sat Feb 25 01:05:25 1995 Aubrey Jaffer (jaffer@jacal) Sun Feb 5 16:34:03 1995 Aubrey Jaffer (jaffer@jacal) - * paramlst.scm ((make-parameter-list parameter-names)): - ((fill-empty-parameters defaults parameter-list)): - ((check-parameters checks parameter-list)): - ((parameter-list->arglist positions arities parameter-list)): - ((parameter-list-ref parameter-list i)): - ((adjoin-parameters! parameter-list parameters)): + * paramlst.scm ((make-parameter-list parameter-names)): + ((fill-empty-parameters defaults parameter-list)): + ((check-parameters checks parameter-list)): + ((parameter-list->arglist positions arities parameter-list)): + ((parameter-list-ref parameter-list i)): + ((adjoin-parameters! parameter-list parameters)): Procedures for making, merging, defaulting, checking and converting `parameter lists' (named parameters). - ((getopt->parameter-list argc argv optnames arities aliases)): + ((getopt->parameter-list argc argv optnames arities aliases)): ((getopt->arglist argc argv optnames positions - arities defaults checks aliases)): + arities defaults checks aliases)): Procedures for converting options and arguments processed by getopt to parameter-list or arglist form. @@ -884,7 +1352,7 @@ Sat Dec 17 12:10:02 1994 Aubrey Jaffer (jaffer@jacal) `expression' fields no longer done when retrieved from base tables (which made copying of many tables impossible). - * alistab.scm + * alistab.scm (write-base): rewrote to not use pretty-print. * sc3.scm: removed (only contained last-pair, t, and nil). @@ -965,7 +1433,7 @@ Tue Aug 2 10:44:32 1994 Aubrey Jaffer (jaffer@jacal) Sun Jul 31 21:39:54 1994 Aubrey Jaffer (jaffer@jacal) * cltime.scm (get-decoded-time get-universal-time - decode-universal-time encode-universal-time): + decode-universal-time encode-universal-time): Common-Lisp time conversion routines created. * time.scm (*timezone* tzset gmtime localtime mktime asctime ctime): @@ -1056,7 +1524,7 @@ Sat Apr 9 21:28:46 1994 Aubrey Jaffer (jaffer@jacal) Wed Apr 6 00:55:16 1994 Aubrey Jaffer (jaffer@jacal) * require.scm (slib:report): - (slib:report-version): + (slib:report-version): (slib:report-locations): added to display SLIB configuration information. @@ -1094,7 +1562,7 @@ Thu Mar 3 23:06:41 1994 Aubrey Jaffer (jaffer@jacal) * format.scm slib.texi: Format 3.0. * format's configuration is rearranged to fit only into SLIB. All implementation dependent configurations are done in the SLIB init files - * format's output routines rely on call-with-output-string now if + * format's output routines rely on call-with-output-string now if output to a string is desired * The floating point formatting code (formatfl.scm) moved into format.scm so that there is only one source code file; this @@ -1104,7 +1572,7 @@ Thu Mar 3 23:06:41 1994 Aubrey Jaffer (jaffer@jacal) procedure except number->string now; all formatting is now based solely on string, character and integer manipulations * major rewrite of the floating point formatting code; use global - buffers now + buffers now * ~f,~e,~g, ~$ may use also number strings as an argument * ~r, ~:r, ~@r, ~:@r roman numeral, and ordinal and cardinal English number printing added (from dorai@cs.rice.edu) @@ -1118,7 +1586,7 @@ Thu Mar 3 23:06:41 1994 Aubrey Jaffer (jaffer@jacal) * ~:c prints control characters like emacs (eg. ^C) and 8bit characters as an octal number * ~q gives information and copyright notice on this format implementation - ~:q gives format:version + ~:q gives format:version * case type of symbol conversion can now be forced (see format:symbol-case-conv in format.scm) * case type of the representation of internal objects can now be @@ -1131,7 +1599,7 @@ Thu Mar 3 23:06:41 1994 Aubrey Jaffer (jaffer@jacal) * if format's destination is a string it is regarded as a format string now and output is the current output port; this is a contribution to Scheme->C to use format with the runtime system; the former semantics - to append tothe destination string is given up + to append tothe destination string is given up * obj->string syntax change and speedup * tested with scm4d, Elk 2.2, MIT Scheme 7.1, Scheme->C 01Nov91 @@ -1606,7 +2074,7 @@ Sat Jun 13 17:01:41 1992 Aubrey Jaffer (jaffer at Ivan) * hash.scm hashtab.scm scheme48.init: added. * sc-macro.scm (macro:repl): created. macro:load now uses - eval:eval!. + eval:eval!. * eval.scm (eval:eval!) created and eval done in terms of it. diff --git a/FAQ b/FAQ index f07b487..790cbc5 100644 --- a/FAQ +++ b/FAQ @@ -1,5 +1,5 @@ -FAQ (Frequently Asked Questions and answers) for SLIB Scheme Library (slib2c3). -Written by Aubrey Jaffer (http://www-swiss.ai.mit.edu/~jaffer). +FAQ (Frequently Asked Questions and answers) for SLIB Scheme Library (slib2c7). +Written by Aubrey Jaffer (http://swissnet.ai.mit.edu/~jaffer). INTRODUCTION AND GENERAL INFORMATION @@ -14,14 +14,16 @@ Scheme is a programming language in the Lisp family. [] Which implementations has SLIB been ported to? -SLIB is supported by Chez, ELK 2.1, GAMBIT, MacScheme, MITScheme, -scheme->C, Scheme48, T3.1, SCM and VSCM +SLIB is supported by Bigloo, Chez, ELK, GAMBIT, MacScheme, MITScheme, +PocketScheme, RScheme Scheme->C, Scheme48, SCM, SCSH, T3.1, +UMB-Scheme, and VSCM. [] How can I obtain SLIB? +SLIB is available via http from: + http://swissnet.ai.mit.edu/~jaffer/SLIB.html SLIB is available via ftp from: - ftp-swiss.ai.mit.edu:pub/scm/slib2c3.tar.gz - prep.ai.mit.edu:pub/gnu/jacal/slib2c3.tar.gz + ftp.gnu.org:pub/gnu/jacal/ SLIB is also included with SCM floppy disks. @@ -38,7 +40,7 @@ or `info' or a text editor. Programs for printing and viewing TexInfo documentation (which SLIB has) come with GNU Emacs or can be obtained via ftp from: -prep.ai.mit.edu:pub/gnu/texinfo-3.1.tar.gz + ftp.gnu.org:/pub/gnu/texinfo/texinfo-3.12.tar.gz [] How often is SLIB released? @@ -46,9 +48,9 @@ Several times a year. [] What is the latest version? -The version as of this writing is slib2c3. The latest documentation +The version as of this writing is slib2c7. The latest documentation is available online at: - http://www-swiss.ai.mit.edu/~jaffer/SLIB.html + http://swissnet.ai.mit.edu/~jaffer/SLIB.html [] Which version am I using? diff --git a/Makefile b/Makefile index 149b1ba..dd11471 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ intro: srcdir=$(HOME)/slib/ dvidir=../dvi/ dvi: $(dvidir)slib.dvi -$(dvidir)slib.dvi: $(srcdir)slib.texi $(dvidir)slib.fn +$(dvidir)slib.dvi: version.txi slib.texi $(dvidir)slib.fn # cd $(dvidir);export TEXINPUTS=$(srcdir):;texi2dvi $(srcdir)slib.texi -(cd $(dvidir);export TEXINPUTS=$(srcdir):;texindex slib.??) cd $(dvidir);export TEXINPUTS=$(srcdir):;tex $(srcdir)slib.texi @@ -22,9 +22,16 @@ $(dvidir)slib.fn: xdvi: $(dvidir)slib.dvi xdvi -s 6 $(dvidir)slib.dvi htmldir=../public_html/ +slib_toc.html: version.txi slib.texi + texi2html -split -verbose slib.texi + +slib/slib_toc.html: + cd slib;make slib_toc.html + cd slib;texi2html -split -verbose slib.texi + html: $(htmldir)slib_toc.html -$(htmldir)slib_toc.html: $(srcdir)slib.texi - cd $(htmldir);make slib_toc.html +$(htmldir)slib_toc.html: slib slib_toc.html Makefile + hitch slib/slib_\*.html slib_\*.html $(htmldir) prefix = /usr/local exec_prefix = $(prefix) @@ -91,27 +98,38 @@ install48: slib48 (echo '#!/bin/sh'; \ echo exec $(RUNNABLE) -i '$(LIB)/$(IMAGE)' \"\$$\@\") \ > $(bindir)/slib48 - chmod +x $(bindir)/slib48 + chmod +x $(bindir)/slib48 + +#### Stuff for maintaining SLIB below #### + +VERSION = 2c7 +ver = $(VERSION) +version.txi: Makefile + echo @set SLIBVERSION $(VERSION) > version.txi + echo @set SLIBDATE `date +"%B %Y"` >> version.txi scheme = scm htmlform.txi: *.scm $(scheme) -rschmooz -e'(schmooz "slib.texi")' - -info: $(infodir)/slib.info -$(infodir)/slib.info: slib.texi htmlform.txi - makeinfo slib.texi -o $(infodir)/slib.info - install-info $(infodir)/slib.info $(infodir)/dir - -rm $(infodir)/slib.info*.gz - -infoz: $(infodir)/slib.info.gz +slib$(VERSION).info: version.txi slib.texi htmlform.txi objdoc.txi + -mv slib.info slibtemp.info + makeinfo slib.texi --no-split -o slib.info + mv slib.info slib$(VERSION).info + -mv slibtemp.info slib.info +slib.info: slib$(VERSION).info + infobar slib/slib.info slib$(VERSION).info slib.info +info: installinfo +installinfo: $(infodir)/slib.info +$(infodir)/slib.info: slib.info + cp -a slib.info $(infodir)/slib.info + -install-info $(infodir)/slib.info $(infodir)/dir + -rm $(infodir)/slib.info.gz +infoz: installinfoz +installinfoz: $(infodir)/slib.info.gz $(infodir)/slib.info.gz: $(infodir)/slib.info - gzip -f $(infodir)/slib.info* - -#### Stuff for maintaining SLIB below #### + gzip -f $(infodir)/slib.info -VERSION = 2c3 -ver = $(VERSION) ffiles = printf.scm format.scm genwrite.scm obj2str.scm pp.scm \ ppfile.scm strcase.scm debug.scm trace.scm lineio.scm \ strport.scm scanf.scm chap.scm qp.scm break.scm stdio.scm \ @@ -120,10 +138,10 @@ lfiles = sort.scm comlist.scm tree.scm logical.scm random.scm tsort.scm revfiles = sc4opt.scm sc4sc3.scm sc2.scm mularg.scm mulapply.scm \ trnscrpt.scm withfile.scm dynwind.scm promise.scm values.scm \ eval.scm -afiles = ratize.scm randinex.scm modular.scm primes.scm factor.scm \ +afiles = ratize.scm randinex.scm modular.scm factor.scm \ charplot.scm root.scm cring.scm determ.scm selfset.scm \ psxtime.scm cltime.scm timezone.scm tzfile.scm -bfiles = collect.scm fluidlet.scm struct.scm yasos.scm +bfiles = collect.scm fluidlet.scm struct.scm object.scm recobj.scm yasyn.scm scfiles = r4rsyn.scm scmacro.scm synclo.scm synrul.scm synchk.scm \ repl.scm macwork.scm mwexpand.scm mwdenote.scm mwsynrul.scm scafiles = scainit.scm scaglob.scm scamacr.scm scaoutp.scm scaexpp.scm \ @@ -132,17 +150,19 @@ dfiles = defmacex.scm mbe.scm efiles = record.scm dynamic.scm queue.scm process.scm \ priorque.scm hash.scm hashtab.scm alist.scm \ wttree.scm wttest.scm array.scm arraymap.scm \ - sierpinski.scm soundex.scm byte.scm + sierpinski.scm soundex.scm byte.scm nclients.scm rfiles = rdms.scm alistab.scm dbutil.scm paramlst.scm report.scm \ batch.scm makcrc.scm dbrowse.scm comparse.scm getopt.scm \ - htmlform.scm getparam.scm glob.scm + htmlform.scm getparam.scm glob.scm fft.scm gfiles = tek40.scm tek41.scm -docfiles = ANNOUNCE README FAQ ChangeLog slib.texi fmtdoc.txi +docfiles = ANNOUNCE README FAQ slib.info slib.texi objdoc.txi fmtdoc.txi \ + ChangeLog mfiles = Makefile require.scm Template.scm syncase.sh mklibcat.scm \ Bev2slib.scm -ifiles = chez.init elk.init macscheme.init \ - mitscheme.init scheme2c.init scheme48.init gambit.init t3.init \ - vscm.init mitcomp.pat scm.init scsh.init +ifiles = bigloo.init chez.init elk.init macscheme.init \ + mitscheme.init scheme2c.init scheme48.init gambit.init t3.init \ + vscm.init mitcomp.pat scm.init scsh.init pscheme.init STk.init \ + RScheme.init umbscheme.init tfiles = plottest.scm formatst.scm macrotst.scm scmactst.scm \ dwindtst.scm structst.scm sfiles = $(ffiles) $(lfiles) $(revfiles) $(afiles) $(scfiles) $(efiles) \ @@ -151,6 +171,7 @@ allfiles = $(docfiles) $(mfiles) $(ifiles) $(sfiles) $(tfiles) $(bfiles) makedev = make -f $(HOME)/makefile.dev CHPAT=$(HOME)/bin/chpat +RSYNC=rsync -v --rsync-path bin/rsync dest = $(HOME)/dist/ temp/slib: $(allfiles) -rm -rf temp @@ -163,22 +184,40 @@ infotemp/slib: slib.info mkdir infotemp mkdir infotemp/slib ln slib.info slib.info-* infotemp/slib +#For change-barred HTML. +slib: + unzip -a $(dest)slib[0-9]*.zip -distinfo: $(dest)slib.info.tar.gz -$(dest)slib.info.tar.gz: infotemp/slib - $(makedev) TEMP=infotemp/ DEST=$(dest) PROD=slib ver=.info tar.gz +distinfo: $(dest)slib.info.zip +$(dest)slib.info.zip: infotemp/slib + $(makedev) TEMP=infotemp/ DEST=$(dest) PROD=slib ver=.info zip rm -rf infotemp release: dist - rsync -v $(htmldir)SLIB.html martigny.ai.mit.edu:public_html/ - rsync -v $(dest)README $(dest)slib$(VERSION).tar.gz martigny.ai.mit.edu:dist/ - upload $(dest)README $(dest)slib$(VERSION).tar.gz prep.ai.mit.edu:gnu/jacal/ + cp $(srcdir)ANNOUNCE $(htmldir)SLIB_ANNOUNCE + $(RSYNC) $(htmldir)SLIB.html $(htmldir)SLIB_ANNOUNCE nestle.ai.mit.edu:public_html/ + $(RSYNC) $(dest)README $(dest)slib$(VERSION).zip nestle.ai.mit.edu:dist/ +# upload $(dest)README $(dest)slib$(VERSION).zip ftp.gnu.org:gnu/jacal/ +# $(MAKE) indiana +indiana: + upload $(dest)slib$(VERSION).zip ftp@ftp.cs.indiana.edu:/pub/scheme-repository/incoming + echo -e \ + 'I have uploaded slib$(VERSION).zip to ftp.cs.indiana.edu:/pub/scheme-repository/incoming\n' \ + 'for placement into ftp.cs.indiana.edu:/pub/scheme-repository/code/lib/' \ + | mail -s 'SLIB upload' -b jaffer scheme-repository-request@cs.indiana.edu + +postnews: + echo -e "Newsgroups: comp.lang.scheme\n" | cat - ANNOUNCE | \ + inews -h -O -S \ + -f "announce@docupress.com (Aubrey Jaffer & Radey Shouman)" \ + -t "SLIB$(VERSION) Released" -d world + upzip: $(HOME)/pub/slib.zip - rsync -v $(HOME)/pub/slib.zip martigny.ai.mit.edu:pub/ + $(RSYNC) $(HOME)/pub/slib.zip nestle.ai.mit.edu:pub/ -dist: $(dest)slib$(VERSION).tar.gz -$(dest)slib$(VERSION).tar.gz: temp/slib - $(makedev) DEST=$(dest) PROD=slib ver=$(VERSION) tar.gz +dist: $(dest)slib$(VERSION).zip +$(dest)slib$(VERSION).zip: temp/slib + $(makedev) DEST=$(dest) PROD=slib ver=$(VERSION) zip cvs tag -F slib$(VERSION) shar: slib.shar slib.shar: temp/slib @@ -190,10 +229,10 @@ slib.com: temp/slib zip: slib.zip slib.zip: temp/slib $(makedev) PROD=slib zip -distzip: slib$(VERSION).zip -slib$(VERSION).zip: temp/slib - $(makedev) DEST=$(dest) PROD=slib ver=$(VERSION) zip - mv $(dest)slib$(VERSION).zip /c/scm/dist/ +doszip: /c/scm/dist/slib$(VERSION).zip +/c/scm/dist/slib$(VERSION).zip: temp/slib + $(makedev) DEST=/c/scm/dist/ PROD=slib ver=$(VERSION) zip + zip -d /c/scm/dist/slib$(VERSION).zip slib/slib.info pubzip: temp/slib $(makedev) DEST=$(HOME)/pub/ PROD=slib zip @@ -203,7 +242,7 @@ pubdiffs: temp/slib distdiffs: temp/slib $(makedev) DEST=$(dest) PROD=slib ver=$(ver) distdiffs announcediffs: temp/slib - $(makedev) DEST=$(dest) PROD=slib ver=2c3 announcediffs + $(makedev) DEST=$(dest) PROD=slib ver=$(VERSION) announcediffs psdfiles=COPYING.psd README.psd cmuscheme.el comint.el instrum.scm pexpr.scm \ primitives.scm psd-slib.scm psd.el read.scm runtime.scm version.scm @@ -234,14 +273,15 @@ new: $(htmldir)README.html ../dist/README \ $(htmldir)SLIB.html $(htmldir)JACAL.html \ $(htmldir)SCM.html $(htmldir)Hobbit.html \ - $(htmldir)SIMSYNCH.html \ - ../scm/README ../scm/scm.texi \ + $(htmldir)SIMSYNCH.html ../scm/scm.texi \ /c/scm/dist/install.bat /c/scm/dist/makefile \ /c/scm/dist/mkdisk.bat $(CHPAT) $(VERSION) $(ver) README slib.texi require.scm Makefile \ $(htmldir)SLIB.html + cvs commit -m '(*SLIB-VERSION*): Bumped from $(VERSION) to $(ver).' + cvs tag -F slib$(ver) -tagfiles = slib.texi $(mfiles) $(sfiles) $(bfiles) $(tfiles) +tagfiles = version.txi slib.texi $(mfiles) $(sfiles) $(bfiles) $(tfiles) # README and $(ifiles) cause semgentation faults in ETAGS for Emacs version 19. tags: $(tagfiles) etags $(tagfiles) diff --git a/README b/README index ab01989..daae3a6 100644 --- a/README +++ b/README @@ -1,10 +1,10 @@ -This directory contains the distribution of Scheme Library slib2c3. +This directory contains the distribution of Scheme Library slib2c7. Slib conforms to Revised^5 Report on the Algorithmic Language Scheme and the IEEE P1178 specification. Slib supports Unix and similar systems, VMS, and MS-DOS. -The maintainer can be reached at jaffer @ life.ai.mit.edu. - http://www-swiss.ai.mit.edu/~jaffer/SLIB.html +The maintainer can be reached at jaffer @ ai.mit.edu. + http://swissnet.ai.mit.edu/~jaffer/SLIB.html MANIFEST @@ -16,6 +16,7 @@ The maintainer can be reached at jaffer @ life.ai.mit.edu. `Template.scm' Example configuration file. Copy and customize to reflect your system. + `bigloo.init' is a configuration file for Bigloo. `chez.init' is a configuration file for Chez Scheme. `elk.init' is a configuration file for ELK 2.1 `gambit.init' is a configuration file for Gambit Scheme. @@ -23,11 +24,15 @@ The maintainer can be reached at jaffer @ life.ai.mit.edu. `mitscheme.init' is a configuration file for MIT Scheme. `mitcomp.pat' is a patch file which adds definitions to SLIB files for the MitScheme compiler. - `scheme2c.init' is a configuration file for DEC's scheme->c. + `pscheme.init' is configuration file for PocketScheme 0.2.5 (WinCE SIOD) + `RScheme.init' is a configuration file for RScheme. + `scheme2c.init' is a configuration file for DEC's scheme->c. `scheme48.init' is a configuration file for Scheme48. `scsh.init' is a configuration file for Scheme-Shell `scm.init' is a configuration file for SCM. `t3.init' is a configuration file for T3.1 in Scheme mode. + `STk.init' is a configuration file for STk. + `umbscheme.init' is a configuration file for umb-scheme. `vscm.init' is a configuration file for VSCM. `mklibcat.scm' builds the *catalog* cache. `require.scm' has code which allows system independent access to @@ -116,7 +121,8 @@ The maintainer can be reached at jaffer @ life.ai.mit.edu. `values.scm' is multiple values. `queue.scm' has queues and stacks. - `yasos.scm' is object oriented programming (using R4RS macros). + `object.scm' is an object system. + `yasyn.scm' defines (syntax-rules) macros for object oriented programming. `collect.scm' is collection operators (like CL sequences). `priorque.scm' has code and documentation for priority queues. `wttree.scm' has weight-balanced trees. @@ -151,6 +157,7 @@ The maintainer can be reached at jaffer @ life.ai.mit.edu. `structure.scm' has syntax-case macros for the same. `structst.scm' has test code for struct.scm. `byte.scm' has arrays of small integers. + `nclients' provides a Scheme interface to FTP and WWW Browsers. INSTALLATION INSTRUCTIONS diff --git a/RScheme.init b/RScheme.init new file mode 100644 index 0000000..b16b286 --- /dev/null +++ b/RScheme.init @@ -0,0 +1,282 @@ +;;;"RScheme.init" Initialization for SLIB for RScheme -*-scheme-*- +;;;; From http://www.rscheme.org/rs/pg1/RScheme.scm +;;; Author: Aubrey Jaffer +;;; +;;; This code is in the public domain. +;;; +;;; adapted for RScheme by Donovan Kolbly -- (v1 1997-09-14) +;;; +;Permission to copy this software, to redistribute it, and to use it +;for any purpose is granted, subject to the following restrictions and +;understandings. +; +;1. Any copy made of this software must include this copyright notice +;in full. +; +;2. I have made no warrantee or representation that the operation of +;this software will be error-free, and I am under no obligation to +;provide any services, by way of maintenance, update, or otherwise. +; +;3. In conjunction with products arising from the use of this +;material, there shall be no use of my name in any advertising, +;promotional, or sales literature without prior written consent in +;each case. + +;;; (software-type) should be set to the generic operating system type. +;;; UNIX, VMS, MACOS, AMIGA and MS-DOS are supported. + +(define (software-type) 'UNIX) + +;;; (scheme-implementation-type) should return the name of the scheme +;;; implementation loading this file. + +(define (scheme-implementation-type) 'RScheme) + +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) "http://www.rscheme.org/") + +;;; (scheme-implementation-version) should return a string describing +;;; the version the scheme implementation loading this file. + +(define (scheme-implementation-version) "0.7.1") + +;;; (implementation-vicinity) should be defined to be the pathname of +;;; the directory where any auxillary files to your Scheme +;;; implementation reside. + +(define (implementation-vicinity) + (case (software-type) + ((UNIX) "/usr/local/lib/rs/0.7.1/") + ((VMS) "scheme$src:") + ((MS-DOS) "C:\\scheme\\"))) + +;;; (library-vicinity) should be defined to be the pathname of the +;;; directory where files of Scheme library functions reside. + +(define library-vicinity + (let ((library-path + (or + ;; Use this getenv if your implementation supports it. + (getenv "SCHEME_LIBRARY_PATH") + ;; Use this path if your scheme does not support GETENV + ;; or if SCHEME_LIBRARY_PATH is not set. + (case (software-type) + ((UNIX) "/usr/lib/slib/") + ((VMS) "lib$scheme:") + ((MS-DOS) "C:\\SLIB\\") + (else ""))))) + (lambda () library-path))) + +;;; *FEATURES* should be set to a list of symbols describing features +;;; of this implementation. Suggestions for features are: + +(define *features* + '( + source ;can load scheme source files + ;(slib:load-source "filename") +; compiled ;can load compiled files + ;(slib:load-compiled "filename") + rev4-report ;conforms to +; rev3-report ;conforms to +; ieee-p1178 ;conforms to +; sicp ;runs code from Structure and + ;Interpretation of Computer + ;Programs by Abelson and Sussman. + rev4-optional-procedures ;LIST-TAIL, STRING->LIST, + ;LIST->STRING, STRING-COPY, + ;STRING-FILL!, LIST->VECTOR, + ;VECTOR->LIST, and VECTOR-FILL! +; rev2-procedures ;SUBSTRING-MOVE-LEFT!, + ;SUBSTRING-MOVE-RIGHT!, + ;SUBSTRING-FILL!, + ;STRING-NULL?, APPEND!, 1+, + ;-1+, ?, >=? + multiarg/and- ;/ and - can take more than 2 args. + multiarg-apply ;APPLY can take more than 2 args. +; rationalize + delay ;has DELAY and FORCE + with-file ;has WITH-INPUT-FROM-FILE and + ;WITH-OUTPUT-FROM-FILE + string-port ;has CALL-WITH-INPUT-STRING and + ;CALL-WITH-OUTPUT-STRING +; transcript ;TRANSCRIPT-ON and TRANSCRIPT-OFF + char-ready? +; macro ;has R4RS high level macros +; defmacro ;has Common Lisp DEFMACRO +; eval ;SLIB:EVAL is single argument eval +; record ;has user defined data structures +; values ;proposed multiple values +; dynamic-wind ;proposed dynamic-wind +; ieee-floating-point ;conforms to + full-continuation ;can return multiple times +; object-hash ;has OBJECT-HASH + +; sort +; queue ;queues +; pretty-print +; object->string +; format +; trace ;has macros: TRACE and UNTRACE +; compiler ;has (COMPILER) +; ed ;(ED) is editor +; system ;posix (system ) + getenv ;posix (getenv ) +; program-arguments ;returns list of strings (argv) +; Xwindows ;X support +; curses ;screen management package +; termcap ;terminal description package +; terminfo ;sysV terminal description +; current-time ;returns time in seconds since 1/1/1970 + )) + +;;; (OUTPUT-PORT-WIDTH ) +(define (output-port-width . arg) 79) + +;;; (OUTPUT-PORT-HEIGHT ) +(define (output-port-height . arg) 24) + +;;; (CURRENT-ERROR-PORT) +;(define current-error-port +; (let ((port (current-output-port))) +; (lambda () port))) + +;;; (TMPNAM) makes a temporary file name. +(define tmpnam (let ((cntr 100)) + (lambda () (set! cntr (+ 1 cntr)) + (string-append "slib_" (number->string cntr))))) + +;;; (FILE-EXISTS? ) +(define (file-exists? f) (os-file-exists? f)) + +;;; (DELETE-FILE ) +(define (delete-file f) #f) + +;;; FORCE-OUTPUT flushes any pending output on optional arg output port +;;; use this definition if your system doesn't have such a procedure. +(define (force-output . arg) + (flush-output-port (if (null? arg) + (current-output-port) + (car arg)))) + +;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string +;;; port versions of CALL-WITH-*PUT-FILE. + +;;; CHAR-CODE-LIMIT is one greater than the largest integer which can +;;; be returned by CHAR->INTEGER. +(define char-code-limit 65536) + +;;; MOST-POSITIVE-FIXNUM is used in modular.scm +(define most-positive-fixnum #x1FFFFFFF) + +;;; Return argument +;;(define (identity x) x) + +;;; If your implementation provides eval SLIB:EVAL is single argument +;;; eval using the top-level (user) environment. +(define slib:eval eval) + +;;; If your implementation provides R4RS macros: +;(define macro:eval slib:eval) +;(define macro:load load) + +(define *defmacros* + (list (cons 'defmacro + (lambda (name parms . body) + `(set! *defmacros* (cons (cons ',name (lambda ,parms ,@body)) + *defmacros*)))))) +(define (defmacro? m) (and (assq m *defmacros*) #t)) + +(define (macroexpand-1 e) + (if (pair? e) (let ((a (car e))) + (cond ((symbol? a) (set! a (assq a *defmacros*)) + (if a (apply (cdr a) (cdr e)) e)) + (else e))) + e)) + +(define (macroexpand e) + (if (pair? e) (let ((a (car e))) + (cond ((symbol? a) + (set! a (assq a *defmacros*)) + (if a (macroexpand (apply (cdr a) (cdr e))) e)) + (else e))) + e)) + +(define gentemp + (let ((*gensym-counter* -1)) + (lambda () + (set! *gensym-counter* (+ *gensym-counter* 1)) + (string->symbol + (string-append "slib:G" (number->string *gensym-counter*)))))) + +(define base:eval slib:eval) +(define (defmacro:eval x) (base:eval (defmacro:expand* x))) +(define (defmacro:expand* x) + (require 'defmacroexpand) (apply defmacro:expand* x '())) + +(define (defmacro:load ) + (slib:eval-load defmacro:eval)) + +(define (slib:eval-load evl) + (if (not (file-exists? )) + (set! (string-append (scheme-file-suffix)))) + (call-with-input-file + (lambda (port) + (let ((old-load-pathname *load-pathname*)) + (set! *load-pathname* ) + (do ((o (read port) (read port))) + ((eof-object? o)) + (evl o)) + (set! *load-pathname* old-load-pathname))))) + +;;; define an error procedure for the library +(define (slib:error msg . args) + (error "~a ~j" msg args)) + +;;; define these as appropriate for your system. +(define slib:tab (integer->char 9)) +(define slib:form-feed (integer->char 12)) + +;;; Support for older versions of Scheme. Not enough code for its own file. +;(define (last-pair l) (if (pair? (cdr l)) (last-pair (cdr l)) l)) +(define t #t) +(define nil #f) + +;;; Define these if your implementation's syntax can support it and if +;;; they are not already defined. + +;(define (1+ n) (+ n 1)) +;(define (-1+ n) (+ n -1)) +;(define 1- -1+) + +(define in-vicinity string-append) + +;;; Define SLIB:EXIT to be the implementation procedure to exit or +;;; return if exitting not supported. +(define slib:exit (lambda args (process-exit 0))) + +;;; Here for backward compatability +(define scheme-file-suffix + (let ((suffix (case (software-type) + ((NOSVE) "_scm") + (else ".scm")))) + (lambda () suffix))) + +;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever +;;; suffix all the module files in SLIB have. See feature 'SOURCE. + +(define (slib:load-source f) (load (string-append f ".scm"))) + +;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced +;;; by compiling "foo.scm" if this implementation can compile files. +;;; See feature 'COMPILED. + +(define slib:load-compiled load) + +;;; At this point SLIB:LOAD must be able to load SLIB files. + +(define slib:load slib:load-source) + +(slib:load (in-vicinity (library-vicinity) "require")) diff --git a/STk.init b/STk.init new file mode 100644 index 0000000..47c2e2d --- /dev/null +++ b/STk.init @@ -0,0 +1,248 @@ +;;;"STk.init" SLIB Initialization for STk -*-scheme-*- +;;; Authors: Erick Gallesio (eg@unice.fr) and Aubrey Jaffer. +;;; +;;; This code is in the public domain. + +(require "unix") + +;;; (software-type) should be set to the generic operating system type. +;;; UNIX, VMS, MACOS, AMIGA and MSDOS are supported. + +(define (software-type) 'UNIX) + +;;; (scheme-implementation-type) should return the name of the scheme +;;; implementation loading this file. + +(define (scheme-implementation-type) '|STk|) + +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) + "http://kaolin.unice.fr/STk/STk.html") + +;;; (scheme-implementation-version) should return a string describing +;;; the version the scheme implementation loading this file. + +(define (scheme-implementation-version) (version)) + +;;; (implementation-vicinity) should be defined to be the pathname of +;;; the directory where any auxillary files to your Scheme +;;; implementation reside. + +(define (implementation-vicinity) "/usr/local/lib/stk/3.99.3/") + +;;; (library-vicinity) should be defined to be the pathname of the +;;; directory where files of Scheme library functions reside. + +(define library-vicinity + (let ((library-path (or (getenv "SCHEME_LIBRARY_PATH") "/usr/local/lib/slib/"))) + (lambda () library-path))) + +;;; +;;; +(define home-vicinity + (let ((home-path (or (getenv "HOME") "/"))) + (lambda () home-path))) + +;;; *FEATURES* should be set to a list of symbols describing features +;;; of this implementation. Suggestions for features are: + +(define *features* + '( + source ;can load scheme source files + ;(slib:load-source "filename") + compiled ;can load compiled files + ;(slib:load-compiled "filename") + rev4-report ;conforms to +; rev3-report ;conforms to +; ieee-p1178 ;conforms to +; sicp ;runs code from Structure and + ;Interpretation of Computer + ;Programs by Abelson and Sussman. + rev4-optional-procedures ;LIST-TAIL, STRING->LIST, + ;LIST->STRING, STRING-COPY, + ;STRING-FILL!, LIST->VECTOR, + ;VECTOR->LIST, and VECTOR-FILL! +; rev3-procedures ;LAST-PAIR, T, and NIL +; rev2-procedures ;SUBSTRING-MOVE-LEFT!, + ;SUBSTRING-MOVE-RIGHT!, + ;SUBSTRING-FILL!, + ;STRING-NULL?, APPEND!, 1+, + ;-1+, ?, >=? + multiarg/and- ;/ and - can take more than 2 args. + multiarg-apply ;APPLY can take more than 2 args. +; rationalize + delay ;has DELAY and FORCE + with-file ;has WITH-INPUT-FROM-FILE and + ;WITH-OUTPUT-FROM-FILE + string-port ;has CALL-WITH-INPUT-STRING and + ;CALL-WITH-OUTPUT-STRING +; transcript ;TRANSCRIPT-ON and TRANSCRIPT-OFF +; char-ready? +; macro ;has R4RS high level macros +; defmacro ;has Common Lisp DEFMACRO + eval ;SLIB:EVAL is single argument eval +; record ;has user defined data structures +; values ;proposed multiple values + dynamic-wind ;proposed dynamic-wind + ieee-floating-point ;conforms to + full-continuation ;can return multiple times +; object-hash ;has OBJECT-HASH + +; sort ; commented because icomplete +; queue ;queues +; pretty-print +; object->string +; format +; compiler ;has (COMPILER) + ed ;(ED) is editor + system ;posix (system ) + getenv ;posix (getenv ) +; program-arguments ;returns list of strings (argv) +; Xwindows ;X support +; curses ;screen management package +; termcap ;terminal description package +; terminfo ;sysV terminal description + )) + +;;; (OUTPUT-PORT-WIDTH ) +(define (output-port-width . arg) 79) + +;;; (OUTPUT-PORT-HEIGHT ) +(define (output-port-height . arg) 24) + +;;; (TMPNAM) makes a temporary file name. +(define tmpnam (let ((cntr 100)) + (lambda () (set! cntr (+ 1 cntr)) + (string-append "slib_" (number->string cntr))))) + +;;; (DELETE-FILE ) +(define (delete-file f) (system (format #f "/bin/rm ~A" f))) + +;;; FORCE-OUTPUT flushes any pending output on optional arg output port +;;; use this definition if your system doesn't have such a procedure. +(define (force-output . arg) (apply flush arg)) + +;;; CHAR-CODE-LIMIT is one greater than the largest integer which can +;;; be returned by CHAR->INTEGER. +(define char-code-limit 256) + +;;; MOST-POSITIVE-FIXNUM is used in modular.scm +(define most-positive-fixnum #x0fffffff) + +;;; If your implementation provides eval SLIB:EVAL is single argument +;;; eval using the top-level (user) environment. +(define slib:eval eval) + +;;; If your implementation provides R4RS macros: +;(define macro:eval slib:eval) +;(define macro:load load) + +(define *macros* '()) + +(define-macro (defmacro name args . body) + `(begin + (define-macro (,name ,@args) ,@body) + (set! *macros* (cons ,name *macros*)))) + + +(define (defmacro? m) (and (memv m *macros*) #t)) + +(define macroexpand-1 MACRO-EXPAND-1) +(define macroexpand MACRO-EXPAND) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(define gentemp GENSYM) +(define base:eval slib:eval) + +(define (defmacro:eval x) (base:eval (defmacro:expand* x))) +(define (defmacro:expand* x) + (require 'defmacroexpand) (apply defmacro:expand* x '())) + +(define (defmacro:load ) + (slib:eval-load defmacro:eval)) + +(define (slib:eval-load evl) + (if (not (file-exists? )) + (set! (string-append (scheme-file-suffix)))) + (call-with-input-file + (lambda (port) + (let ((old-load-pathname *load-pathname*)) + (set! *load-pathname* ) + (do ((o (read port) (read port))) + ((eof-object? o)) + (evl o)) + (set! *load-pathname* old-load-pathname))))) + +;;; define an error procedure for the library +(define (slib:error . args) + (error (apply string-append (map (lambda (x) (format #f " ~a" x)) args)))) + + +;;; define these as appropriate for your system. +(define slib:tab (integer->char 9)) +(define slib:form-feed (integer->char 12)) + +;;; Define these if your implementation's syntax can support it and if +;;; they are not already defined. +(define -1+ 1-) + +(define in-vicinity string-append) + +;;; Define SLIB:EXIT to be the implementation procedure to exit or +;;; return if exitting not supported. +(define slib:exit exit) + +;;; Here for backward compatability +(define scheme-file-suffix + (let ((suffix (case (software-type) + ((NOSVE) "_scm") + (else ".scm")))) + (lambda () suffix))) + +;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever +;;; suffix all the module files in SLIB have. See feature 'SOURCE. + +(define slib:load-source LOAD) + +;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced +;;; by compiling "foo.scm" if this implementation can compile files. +;;; See feature 'COMPILED. + +(define slib:load-compiled load) + +;;; +;;; Retain original require/provide before loading "require.scm" +;;; +(define stk:require require) +(define stk:provide provide) +(define stk:provided? provided?) + +(define slib:load slib:load-source) +(slib:load (in-vicinity (library-vicinity) "require")) + + +;;; +;;; Redefine require/provide so that symbols use SLIB one and strings use STk one +;;; + +(define require + (let ((slib:require require)) + (lambda (item) + ((if (symbol? item) slib:require stk:require) item )))) + +(define provide + (let ((slib:provide provide)) + (lambda (item) + ((if (symbol? item) slib:provide stk:provide) item)))) + +(define provided? + (let ((slib:provided? provided?)) + (lambda (item) + ((if (symbol? item) slib:provided? stk:provided?) item)))) + +(define identity (lambda (x) x)) diff --git a/Template.scm b/Template.scm index e3d2687..9d30d40 100644 --- a/Template.scm +++ b/Template.scm @@ -1,21 +1,7 @@ -;"Template.scm" configuration template of *features* for Scheme -*-scheme-*- -; Copyright (C) 1991, 1992, 1993, 1994, 1997 Aubrey Jaffer. -; -;Permission to copy this software, to redistribute it, and to use it -;for any purpose is granted, subject to the following restrictions and -;understandings. -; -;1. Any copy made of this software must include this copyright notice -;in full. -; -;2. I have made no warrantee or representation that the operation of -;this software will be error-free, and I am under no obligation to -;provide any services, by way of maintenance, update, or otherwise. -; -;3. In conjunction with products arising from the use of this -;material, there shall be no use of my name in any advertising, -;promotional, or sales literature without prior written consent in -;each case. +;;; "Template.scm" configuration template of *features* for Scheme -*-scheme-*- +;;; Author: Aubrey Jaffer +;;; +;;; This code is in the public domain. ;;; (software-type) should be set to the generic operating system type. ;;; UNIX, VMS, MACOS, AMIGA and MS-DOS are supported. @@ -27,6 +13,12 @@ (define (scheme-implementation-type) 'Template) +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) #f) + ;;; (scheme-implementation-version) should return a string describing ;;; the version the scheme implementation loading this file. diff --git a/alistab.scm b/alistab.scm index f0e8d59..426a4e3 100644 --- a/alistab.scm +++ b/alistab.scm @@ -42,12 +42,13 @@ (list resources (list 'free-id 1)))) (define (open-base infile writable) - (cons (if (input-port? infile) #f infile) - ((lambda (fun) - (if (input-port? infile) - (fun infile) - (call-with-input-file infile fun))) - read))) + (and (or (input-port? infile) (file-exists? infile)) + (cons (if (input-port? infile) #f infile) + ((lambda (fun) + (if (input-port? infile) + (fun infile) + (call-with-input-file infile fun))) + read)))) (define (write-base lldb outfile) ((lambda (fun) @@ -306,7 +307,7 @@ (define (supported-key-type? type) (case type - ((atom integer symbol string) #t) + ((atom integer number symbol string) #t) (else #f))) ;;make-table open-table remover assoc* make-assoc* diff --git a/arraymap.scm b/arraymap.scm index d3dedba..ab3d7c8 100644 --- a/arraymap.scm +++ b/arraymap.scm @@ -1,4 +1,4 @@ -;;;; "arraymap.scm", applicative routines for arrays in Scheme. +;;;; "arraymap.scm", applicative routines for arrays in Scheme. ;;; Copyright (c) 1993 Aubrey Jaffer ; ;Permission to copy this software, to redistribute it, and to use it diff --git a/batch.scm b/batch.scm index 7749451..d77519d 100644 --- a/batch.scm +++ b/batch.scm @@ -36,74 +36,77 @@ (define (batch:port parms) (let ((bp (parameter-list-ref parms 'batch-port))) (cond ((or (not (pair? bp)) (not (output-port? (car bp)))) - ;;(slib:error 'batch-line "missing batch-port parameter" bp) + (slib:warn 'batch-line "missing batch-port parameter" bp) (current-output-port)) (else (car bp))))) (define (batch:dialect parms) ; was batch-family (car (parameter-list-ref parms 'batch-dialect))) -(define (batch:line-length-limit parms) - (let ((bl (parameter-list-ref parms 'batch-line-length-limit))) - (cond (bl (car bl)) - (else (case (batch:dialect parms) - ((unix) 1023) - ((dos) 127) - ((vms) 1023) - ((system) 1023) - ((*unknown*) -1)))))) - (define (write-batch-line str line-limit port) - (cond ((and line-limit (>= (string-length str) line-limit)) #f) + (cond ((and line-limit (>= (string-length str) line-limit)) + (slib:warn 'write-batch-line 'too-long + (string-length str) '> line-limit) + #f) (else (write-line str port) #t))) (define (batch-line parms str) (write-batch-line str (batch:line-length-limit parms) (batch:port parms))) ;;; add a Scheme batch-dialect? -(define (batch:apply-chop-to-fit proc . args) - (define args-but-last (butlast args 1)) +(define (batch:try-chopped-command parms . args) + (define args-but-last (batch:flatten (butlast args 1))) + (define line-limit (batch:line-length-limit parms)) (let loop ((fodder (car (last-pair args)))) - (let ((hlen (quotient (length fodder) 2))) - (cond ((apply proc (append args-but-last (list fodder)))) - ((not (positive? hlen)) - (slib:error 'batch:apply-chop-to-fit "can't split" - (cons proc (append args-but-last (list fodder))))) - (else (loop (nthcdr (+ 1 hlen) fodder)) - (loop (butlast fodder hlen))))))) - -(define (batch:try-system parms . strings) - (set! strings (batch:flatten strings)) + (let ((str (batch:glued-line parms + (batch:flatten + (append args-but-last (list fodder)))))) + (cond ((< (string-length str) line-limit) + (batch:try-command parms str)) + ((< (length fodder) 2) + (slib:warn 'batch:try-chopped-command "can't fit in " line-limit + (cons proc (append args-but-last (list fodder)))) + #f) + (else (let ((hlen (quotient (length fodder) 2))) + (and (loop (last fodder hlen)) + (loop (butlast fodder hlen))))))))) + +(define (batch:glued-line parms strings) (case (batch:dialect parms) - ((unix) (batch-line parms (apply string-join " " strings))) - ((dos) (batch-line parms (apply string-join " " strings))) - ((vms) (batch-line parms (apply string-join " " "$" strings))) - ((system) - (let ((port (batch:port parms)) - (str (apply string-join " " strings))) - (write `(system ,str) port) (newline port) - (and (provided? 'system) (system:success? (system str))))) - ((*unknown*) - (let ((port (batch:port parms)) - (str (apply string-join " " strings))) - (write `(system ,str) port) (newline port)) - #t) + ((vms) (apply string-join " " "$" strings)) + ((unix dos amigados system *unknown*) (apply string-join " " strings)) (else #f))) -(define (batch:system parms . strings) - (cond ((apply batch:try-system parms strings)) - (else (slib:error 'batch:system 'failed strings)))) +(define (batch:try-command parms . strings) + (set! strings (batch:flatten strings)) + (let ((line (batch:glued-line parms strings))) + (and line + (case (batch:dialect parms) + ((unix dos vms amigados) (batch-line parms line)) + ((system) + (let ((port (batch:port parms))) + (write `(system ,line) port) (newline port) + (and (provided? 'system) (system:success? (system line))))) + ((*unknown*) + (let ((port (batch:port parms))) + (write `(system ,line) port) (newline port) #t)) + (else #f))))) + +(define (batch:command parms . strings) + (cond ((apply batch:try-command parms strings)) + (else (slib:error 'batch:command 'failed strings)))) (define (batch:run-script parms name . strings) (case (batch:dialect parms strings) - ((vms) (batch:system parms (string-append "@" name) strings)) - (else (batch:system parms name strings)))) + ((vms) (batch:command parms (string-append "@" name) strings)) + (else (batch:command parms name strings)))) (define (batch:write-comment-line dialect line port) (case dialect ((unix) (write-batch-line (string-append "# " line) #f port)) ((dos) (write-batch-line (string-append "rem " line) #f port)) ((vms) (write-batch-line (string-append "$! " line) #f port)) + ((amigados) (write-batch-line (string-append "; " line) #f port)) ((system) (write-batch-line (string-append "; " line) #f port)) ((*unknown*) (write-batch-line (string-append ";;; " line) #f port) ;;(newline port) @@ -139,6 +142,24 @@ (every (lambda (string) (batch-line parms string)) lines) (batch-line parms (string-append "$EOD")))) + ((amigados) (batch-line parms (string-append "delete force " file)) + (every + (lambda (str) + (letrec ((star-quote + (lambda (str) + (if (equal? "" str) + str + (let* ((ch (string-ref str 0)) + (s (if (char=? ch #\") + (string #\* ch) + (string ch)))) + (string-append + s + (star-quote + (substring str 1 (string-length str))))))))) + (batch-line parms (string-append "echo \"" (star-quote str) + "\" >> " file)))) + lines)) ((system) (write `(delete-file ,file) port) (newline port) (delete-file file) (require 'pretty-print) @@ -174,6 +195,8 @@ #t) ((vms) (batch-line parms (string-append "$DELETE " file)) #t) + ((amigados) (batch-line parms (string-append "delete force " file)) + #t) ((system) (write `(delete-file ,file) port) (newline port) (delete-file file)) ; SLIB provides ((*unknown*) (write `(delete-file ,file) port) (newline port) @@ -186,6 +209,9 @@ ;;((dos) (batch-line parms (string-join " " "REN" old-name new-name))) ((dos) (batch-line parms (string-join " " "MOVE" "/Y" old-name new-name))) ((vms) (batch-line parms (string-join " " "$RENAME" old-name new-name))) + ((amigados) (batch-line parms (string-join " " "failat 21")) + (batch-line parms (string-join " " "delete force" new-name)) + (batch-line parms (string-join " " "rename" old-name new-name))) ((system) (batch:extender 'rename-file batch:rename-file)) ((*unknown*) (write `(rename-file ,old-name ,new-name) port) (newline port) @@ -244,6 +270,17 @@ ;;(write-line "$DEFINE/USER SYS$OUTPUT BUILD.LOG" port) (proc port)))) + ((amigados) ((cond ((and (string? name) (provided? 'system)) + (lambda (proc) + (let ((ans (call-with-output-file name proc))) + (system (string-append "protect " name " rswd")) + ans))) + ((output-port? name) (lambda (proc) (proc name))) + (else (lambda (proc) (proc (current-output-port))))) + (lambda (port) + (batch:write-header-comment dialect name port) + (proc port)))) + ((system) ((cond ((and (string? name) (provided? 'system)) (lambda (proc) (let ((ans (call-with-output-file name @@ -340,9 +377,12 @@ (delete-file file-name)))) (define batch:database #f) -(define (os->batch-dialect os) - ((((batch:database 'open-table) 'operating-system #f) - 'get 'os-family) os)) +(define os->batch-dialect #f) +(define batch-dialect->line-length-limit #f) + +(define (batch:line-length-limit parms) + (let ((bl (parameter-list-ref parms 'batch-line-length-limit))) + (if bl (car bl) (batch-dialect->line-length-limit (batch:dialect parms))))) (define (batch:initialize! database) (set! batch:database database) @@ -350,12 +390,13 @@ '(batch-dialect ((family atom)) - () - ((unix) - (dos) - (vms) - (system) - (*unknown*))) + ((line-length-limit number)) + ((unix 1023) + (dos 127) + (vms 1023) + (amigados 511) + (system 1023) + (*unknown* -1))) '(operating-system ((name symbol)) @@ -365,7 +406,7 @@ (acorn *unknown*) (aix unix) (alliant *unknown*) - (amiga *unknown*) + (amiga amigados) (apollo unix) (apple2 *unknown*) (arm *unknown*) @@ -378,6 +419,7 @@ (harris *unknown*) (hp-ux unix) (hp48 *unknown*) + (irix unix) (isis *unknown*) (linux unix) (mac *unknown*) @@ -404,4 +446,9 @@ ))) ((database 'add-domain) '(operating-system operating-system #f symbol #f)) + (set! os->batch-dialect (((batch:database 'open-table) 'operating-system #f) + 'get 'os-family)) + (set! batch-dialect->line-length-limit + (((batch:database 'open-table) 'batch-dialect #f) + 'get 'line-length-limit)) ) diff --git a/bigloo.init b/bigloo.init new file mode 100644 index 0000000..14b9c9e --- /dev/null +++ b/bigloo.init @@ -0,0 +1,248 @@ +;; "bigloo.init" Initialization for SLIB for Bigloo -*-scheme-*- +;; Copyright 1994 Robert Sanders +;; Copyright 1991, 1992, 1993 Aubrey Jaffer +;; Copyright 1991 David Love +;; +;; Permission to copy this software, to redistribute it, and to use it +;; for any purpose is granted, subject to the following restrictions and +;; understandings. +;; +;; 1. Any copy made of this software must include this copyright notice +;; in full. +;; +;; 2. I have made no warrantee or representation that the operation of +;; this software will be error-free, and I am under no obligation to +;; provide any services, by way of maintenance, update, or otherwise. +;; +;; 3. In conjunction with products arising from the use of this +;; material, there shall be no use of my name in any advertising, +;; promotional, or sales literature without prior written consent in +;; each case. + +(define (software-type) 'UNIX) + +;;; (scheme-implementation-type) should return the name of the scheme +;;; implementation loading this file. + +(define (scheme-implementation-type) 'Bigloo) + +;;; (scheme-implementation-version) should return a string describing +;;; the version the scheme implementation loading this file. + +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) + "http://kaolin.unice.fr/~serrano/bigloo/bigloo.html") + +(define (scheme-implementation-version) "2.0c") + +;;; (implementation-vicinity) should be defined to be the pathname of +;;; the directory where any auxillary files to your Scheme +;;; implementation reside. + +(define (implementation-vicinity) + (case (software-type) + ((UNIX) "/usr/unsup/lib/bigloo/") + ((VMS) "scheme$src:") + ((MSDOS) "C:\\scheme\\"))) + +;;; (library-vicinity) should be defined to be the pathname of the +;;; directory where files of Scheme library functions reside. + +(define library-vicinity + (let ((library-path + (or + ;; Use this getenv if your implementation supports it. + (getenv "SCHEME_LIBRARY_PATH") + ;; Use this path if your scheme does not support GETENV + ;; or if SCHEME_LIBRARY_PATH is not set. + (case (software-type) + ((UNIX) "/home/bambam/leavens/unsup-src/scheme/scm/slib/") + ((VMS) "lib$scheme:") + ((MSDOS) "C:\\SLIB\\") + (else ""))))) + (lambda () library-path))) + +;;; (home-vicinity) should return the vicinity of the user's HOME +;;; directory, the directory which typically contains files which +;;; customize a computer environment for a user. + +(define home-vicinity + (let ((home-path (getenv "HOME"))) + (lambda () home-path))) + +;;; *FEATURES* should be set to a list of symbols describing features +;;; of this implementation. See Template.scm for the list of feature +;;; names. + +(define *features* + '( + source ;can load scheme source files + ;(slib:load-source "filename") + rev4-report ;conforms to + rev3-report ;conforms to + ieee-p1178 ;conforms to + rev4-optional-procedures + rev3-procedures + multiarg/and- + multiarg-apply + rationalize + object-hash + delay + promise + with-file + transcript + ieee-floating-point + eval + pretty-print + object->string + string-case + string-port + system + getenv + defmacro + ;;full-continuation ;not without the -call/cc switch + )) + +(define pretty-print pp) + +(define (object->string x) (obj->string x)) + +;;; Define these if your implementation's syntax can support it and if +;;; they are not already defined. + +(define (1+ n) (+ n 1)) +(define (-1+ n) (+ n -1)) +(define 1- -1+) + +;;; (OUTPUT-PORT-WIDTH ) +(define (output-port-width . arg) 79) + +;;; (OUTPUT-PORT-HEIGHT ) +(define (output-port-height . arg) 24) + +;;; (TMPNAM) makes a temporary file name. +(define tmpnam + (let ((cntr 100)) + (lambda () + (set! cntr (+ 1 cntr)) + (let ((tmp (string-append "slib_" (number->string cntr)))) + (if (file-exists? tmp) (tmpnam) tmp))))) + +;;; FORCE-OUTPUT flushes any pending output on optional arg output port +;;; use this definition if your system doesn't have such a procedure. +(define (force-output . args) + (flush-output-port (if (pair? args) (car args) (current-output-port)))) + +;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string +;;; port versions of CALL-WITH-*PUT-FILE. +(define (call-with-output-string f) + (let ((outsp (open-output-string))) + (f outsp) + (close-output-port outsp))) + +(define (call-with-input-string s f) + (let* ((insp (open-input-string s)) + (res (f insp))) + (close-input-port insp) + res)) + +;;; CHAR-CODE-LIMIT is one greater than the largest integer which can +;;; be returned by CHAR->INTEGER. +(define char-code-limit 256) + +;; MOST-POSITIVE-FIXNUM is used in modular.scm +(define most-positive-fixnum 536870911) + +;;; Return argument +(define (identity x) x) + +;; define an error procedure for the library + +;;; If your implementation provides eval, SLIB:EVAL is single argument +;;; eval using the top-level (user) environment. +(define slib:eval eval) + +(define-macro (defmacro name . forms) + `(define-macro (,name . ,(car forms)) ,@(cdr forms))) + +(define (defmacro? m) (get-eval-expander m)) +(define (macroexpand-1 body) (expand-once body)) +(define (macroexpand body) (expand body)) + +(define (gentemp) (gensym)) + +(define (slib:eval-load evl) + (if (not (file-exists? )) + (set! (string-append (scheme-file-suffix)))) + (call-with-input-file + (lambda (port) + (let ((old-load-pathname *load-pathname*)) + (set! *load-pathname* ) + (do ((o (read port) (read port))) + ((eof-object? o)) + (evl o)) + (set! *load-pathname* old-load-pathname))))) + +(define (slib:error . args) + (error 'slib:error "" args)) + +;; define these as appropriate for your system. +(define slib:tab (integer->char 9)) +(define slib:form-feed (integer->char 12)) + +;;; records +(defmacro define-record forms + (let* ((name (car forms)) + (maker-name (symbol-append 'make- name))) + `(begin + (define-struct ,name ,@(cadr forms)) + (define ,maker-name ,name)) + )) + + +(define (promise:force p) (force p)) + +;;; (implementation-vicinity) should be defined to be the pathname of +;;; the directory where any auxillary files to your Scheme +;;; implementation reside. + +(define in-vicinity string-append) + +;;; Define SLIB:EXIT to be the implementation procedure to exit or +;;; return if exitting not supported. +(define slib:exit (lambda args (exit 0))) + +;;; Here for backward compatability +(define scheme-file-suffix + (let ((suffix (case (software-type) + ((NOSVE) "_scm") + (else ".scm")))) + (lambda () suffix))) + +;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever +;;; suffix all the module files in SLIB have. See feature 'SOURCE. + +(define (slib:load-source f) (loadq (string-append f (scheme-file-suffix)))) + +;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced +;;; by compiling "foo.scm" if this implementation can compile files. +;;; See feature 'COMPILED. + +(define slib:load-compiled loadq) + +;;; At this point SLIB:LOAD must be able to load SLIB files. + +(define slib:load slib:load-source) + +(define defmacro:eval slib:eval) +(define defmacro:load slib:load) + +;;; If your implementation provides R4RS macros: +;(define macro:eval slib:eval) +;(define macro:load load) + +(slib:load (in-vicinity (library-vicinity) "require")) +; eof diff --git a/chap.scm b/chap.scm index ed559c9..6a20aeb 100644 --- a/chap.scm +++ b/chap.scm @@ -89,7 +89,7 @@ ((char-lower-case? (string-ref s (+ -1 p))) (chap:inc-string s (+ -1 p))) (else - (string-append + (string-append (substring s 0 p) "a" (substring s p (string-length s)))))) @@ -99,7 +99,7 @@ ((char-upper-case? (string-ref s (+ -1 p))) (chap:inc-string s (+ -1 p))) (else - (string-append + (string-append (substring s 0 p) "A" (substring s p (string-length s)))))) @@ -109,7 +109,7 @@ ((char-numeric? (string-ref s (+ -1 p))) (chap:inc-string s (+ -1 p))) (else - (string-append + (string-append (substring s 0 p) "1" (substring s p (string-length s)))))) diff --git a/charplot.scm b/charplot.scm index 2a2a49a..2c64615 100644 --- a/charplot.scm +++ b/charplot.scm @@ -18,6 +18,7 @@ ;each case. (require 'sort) +(require 'printf) (define charplot:rows 24) (define charplot:columns (output-port-width (current-output-port))) @@ -43,6 +44,9 @@ (display str) (charplot:printn! (- width (+ (string-length str) lpad)) #\ ))) +(define (charplot:number->string x) + (sprintf #f "%g" x)) + (define (scale-it z scale) (if (and (exact? z) (integer? z)) (quotient (* z (car scale)) (cadr scale)) @@ -86,8 +90,8 @@ (string-set! a (caar data) charplot:curve1) (set! data (cdr data))) (if (zero? (modulo (- ht xaxis) ystep)) - (let* ((v (number->string (/ (* (- ht xaxis) (cadr yscale)) - (car yscale)))) + (let* ((v (charplot:number->string (/ (* (- ht xaxis) (cadr yscale)) + (car yscale)))) (l (string-length v))) (if (> l 10) (display (substring v 0 10)) @@ -119,12 +123,16 @@ (charplot:center-print! xlabel (+ 12 fudge (- xstep/2))) (do ((i fudge (+ i xstep))) ((> (+ i xstep) charplot:width)) - (charplot:center-print! (number->string (/ (* (- i yaxis) (cadr xscale)) - (car xscale))) + (charplot:center-print! (charplot:number->string + (/ (* (- i yaxis) (cadr xscale)) + (car xscale))) xstep)) (newline))) (define (charplot:plot! data xlabel ylabel) + (cond ((array? data) + (set! data (map (lambda (lst) (cons (car lst) (cadr lst))) + (array->list data))))) (let* ((xmax (apply max (map car data))) (xmin (apply min (map car data))) (xscale (find-scale charplot:width (- xmax xmin))) @@ -139,4 +147,14 @@ data) xlabel ylabel xmin xscale ymin yscale))) +(define (plot-function func vlo vhi . npts) + (set! npts (if (null? npts) 100 (car npts))) + (let ((dats (make-array 0.0 npts 2))) + (array-index-map! (make-shared-array dats (lambda (idx) (list idx 0)) npts) + (lambda (idx) (+ vlo (* (- vhi vlo) (/ idx npts))))) + (array-map! (make-shared-array dats (lambda (idx) (list idx 1)) npts) + func + (make-shared-array dats (lambda (idx) (list idx 0)) npts)) + (charplot:plot! dats "" ""))) + (define plot! charplot:plot!) diff --git a/chez.init b/chez.init index 3ed210f..4b58b84 100644 --- a/chez.init +++ b/chez.init @@ -1,105 +1,55 @@ -;"chez.init" Initialization file for SLIB for Chez Scheme 5.0c -*-scheme-*- -; Copyright (C) 1993 dorai@cs.rice.edu (Dorai Sitaram) -; Copyright (C) 1991, 1992, 1993, 1994, 1997 Aubrey Jaffer. -; Adapted to version 5.0c by stone@math.grin.edu (John David Stone) 1997 -; -;Permission to copy this software, to redistribute it, and to use it -;for any purpose is granted, subject to the following restrictions and -;understandings. -; -;1. Any copy made of this software must include this copyright notice -;in full. -; -;2. I have made no warrantee or representation that the operation of -;this software will be error-free, and I am under no obligation to -;provide any services, by way of maintenance, update, or otherwise. -; -;3. In conjunction with products arising from the use of this -;material, there shall be no use of my name in any advertising, -;promotional, or sales literature without prior written consent in -;each case. - -;; The SOFTWARE-TYPE procedure returns a symbol indicating the generic -;; operating system type. UNIX, VMS, MACOS, AMIGA and MS-DOS are -;; supported. - -(define software-type - (lambda () 'unix)) - -;; The SCHEME-IMPLEMENTATION-TYPE procedure returns a symbol denoting the -;; Scheme implementation that loads this file. - -(define scheme-implementation-type - (lambda () 'chez)) - -;; The SCHEME-IMPLEMENTATION-VERSION procedure returns a string describing -;; the version of the Scheme implementation that loads this file. - -(define scheme-implementation-version - (lambda () "5.0c")) - -;; The IMPLEMENTATION-VICINITY procedure returns a string giving the -;; pathname of the directory that includes any auxiliary files used by this -;; Scheme implementation. +;;;"chez.init" Initialization file for SLIB for Chez Scheme 6.0a -*-scheme-*- +;;; Authors: dorai@cs.rice.edu (Dorai Sitaram) and Aubrey Jaffer. +;;; +;;; This code is in the public domain. + +;;; Adapted to version 5.0c by stone@math.grin.edu (John David Stone) 1997 +;;; Adapted to version 6.0a by Gary T. Leavens , 1999 + +;;; (software-type) should be set to the generic operating system type. +;;; UNIX, VMS, MACOS, AMIGA and MS-DOS are supported. + +(define (software-type) 'UNIX) + +;;; (scheme-implementation-type) should return the name of the scheme +;;; implementation loading this file. + +(define (scheme-implementation-type) 'chez) + +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) + "http://www.cs.indiana.edu/chezscheme/") + +;;; (scheme-implementation-version) should return a string describing +;;; the version the scheme implementation loading this file. + +(define (scheme-implementation-version) "6.0a") + +;;; (implementation-vicinity) should be defined to be the pathname of +;;; the directory where any auxillary files to your Scheme +;;; implementation reside. (define implementation-vicinity - (lambda () "/usr/local/chez/5.0c/")) - -;; The GETENV returns the value of a shell environment variable. - -;; In some implementations of Chez Scheme, this can be done with foreign -;; procedures. However, I [JDS] am using the HP version, which does not -;; support them, so a different approach is needed. -;; -;; Here's the version that doesn't work on HPs: -;; -;; (provide-foreign-entries '("getenv")) -;; -;; (define getenv -;; (foreign-procedure "getenv" -;; (string) string)) -;; -;; And here's a version that parses the value out of the output of the -;; /bin/env command: - -(define getenv - (lambda (env-var) - (let ((env-port (car (process "exec /bin/env"))) - (read-line - (lambda (source) - (let ((next (peek-char source))) - (if (eof-object? next) - next - (let loop ((ch (read-char source)) - (so-far '())) - (if (or (eof-object? ch) - (char=? ch #\newline)) - (apply string (reverse so-far)) - (loop (read-char source) (cons ch so-far)))))))) - (position-of-copula - (lambda (str) - (let ((len (string-length str))) - (do ((position 0 (+ position 1))) - ((or (= position len) - (char=? (string-ref str position) #\=)) - position)))))) - (let loop ((equation (read-line env-port))) - (if (eof-object? equation) - #f - (let ((break (position-of-copula equation)) - (len (string-length equation))) - (if (string=? (substring equation 0 break) env-var) - (if (= break len) - "" - (substring equation (+ break 1) len)) - (loop (read-line env-port))))))))) - -;; The LIBRARY-VICINITY procedure returns the pathname of the directory -;; where Scheme library functions reside. + (lambda () "/usr/unsup/scheme/chez/")) + +;;; (library-vicinity) should be defined to be the pathname of the +;;; directory where files of Scheme library functions reside. (define library-vicinity - (let ((library-path (or (getenv "SCHEME_LIBRARY_PATH") - "/usr/local/lib/slib/"))) + (let ((library-path + (or + ;; Use this getenv if your implementation supports it. + (getenv "SCHEME_LIBRARY_PATH") + ;; Use this path if your scheme does not support GETENV + ;; or if SCHEME_LIBRARY_PATH is not set. + (case (software-type) + ((UNIX) "/usr/local/lib/slib/") + ((VMS) "lib$scheme:") + ((MS-DOS) "C:\\SLIB\\") + (else ""))))) (lambda () library-path))) ;;; (home-vicinity) should return the vicinity of the user's HOME @@ -110,88 +60,219 @@ (let ((home-path (getenv "HOME"))) (lambda () home-path))) -;; The OUTPUT-PORT-WIDTH procedure returns the number of graphic characters -;; that can reliably be displayed on one line of the standard output port. +;;; *FEATURES* should be set to a list of symbols describing features +;;; of this implementation. Suggestions for features are: + +(define *features* + '( + source ; Chez Scheme can load Scheme source files, with the + ; command (slib:load-source "filename") -- see below. + + compiled ; Chez Scheme can also load compiled Scheme files, with the + ; command (slib:load-compiled "filename") -- see below. + rev4-report ;conforms to + rev3-report ;conforms to + ieee-p1178 ;conforms to +; sicp ;runs code from Structure and + ;Interpretation of Computer + ;Programs by Abelson and Sussman. + rev4-optional-procedures ;LIST-TAIL, STRING->LIST, + ;LIST->STRING, STRING-COPY, + ;STRING-FILL!, LIST->VECTOR, + ;VECTOR->LIST, and VECTOR-FILL! +; rev2-procedures ;SUBSTRING-MOVE-LEFT!, + ;SUBSTRING-MOVE-RIGHT!, + ;SUBSTRING-FILL!, + ;STRING-NULL?, APPEND!, 1+, + ;-1+, ?, >=? + multiarg/and- ;/ and - can take more than 2 args. + multiarg-apply ;APPLY can take more than 2 args. + rationalize + delay ;has DELAY and FORCE + with-file ;has WITH-INPUT-FROM-FILE and + ;WITH-OUTPUT-FROM-FILE + string-port ;has CALL-WITH-INPUT-STRING and + ;CALL-WITH-OUTPUT-STRING + transcript ;TRANSCRIPT-ON and TRANSCRIPT-OFF + char-ready? + macro ;has R4RS high level macros +; defmacro ;has Common Lisp DEFMACRO + eval ;R5RS two-argument eval + record ;has user defined data structures + values ;proposed multiple values + dynamic-wind ;proposed dynamic-wind +; ieee-floating-point ;conforms to + full-continuation ;can return multiple times +; object-hash ;has OBJECT-HASH + + sort +; queue ;queues + pretty-print +; object->string + format + trace ;has macros: TRACE and UNTRACE +; compiler ;has (COMPILER) +; ed ;(ED) is editor + system ;posix (system ) + getenv ;posix (getenv ) +; program-arguments ;returns list of strings (argv) +; Xwindows ;X support +; curses ;screen management package +; termcap ;terminal description package +; terminfo ;sysV terminal description +; current-time ;returns time in seconds since 1/1/1970 + fluid-let + random + rev3-procedures + )) + +;;; (OUTPUT-PORT-WIDTH ) returns the number of graphic characters +;;; that can reliably be displayed on one line of the standard output port. (define output-port-width (lambda arg (let ((env-width-string (getenv "COLUMNS"))) (if (and env-width-string - (let loop ((remaining (string-length env-width-string))) - (or (zero? remaining) - (let ((next (- remaining 1))) - (and (char-numeric? (string-ref env-width-string - next)) - (loop next)))))) - (- (string->number env-width-string) 1) - 79)))) - -;; The OUTPUT-PORT-HEIGHT procedure returns the number of lines of text -;; that can reliably be displayed simultaneously in the standard output -;; port. + (let loop ((remaining (string-length env-width-string))) + (or (zero? remaining) + (let ((next (- remaining 1))) + (and (char-numeric? (string-ref env-width-string + next)) + (loop next)))))) + (- (string->number env-width-string) 1) + 79)))) + +;;; (OUTPUT-PORT-HEIGHT ) returns the number of lines of text that +;;; can reliably be displayed simultaneously in the standard output port. (define output-port-height (lambda arg (let ((env-height-string (getenv "LINES"))) (if (and env-height-string - (let loop ((remaining (string-length env-height-string))) - (or (zero? remaining) - (let ((next (- remaining 1))) - (and (char-numeric? (string-ref env-height-string - next)) - (loop next)))))) - (string->number env-height-string) - 24)))) - -;; *FEATURES* is a list of symbols describing features of this -;; implementation; SLIB procedures sometimes consult this list to figure -;; out whether to attempt some incompletely standard operation. + (let loop ((remaining (string-length env-height-string))) + (or (zero? remaining) + (let ((next (- remaining 1))) + (and (char-numeric? (string-ref env-height-string + next)) + (loop next)))))) + (string->number env-height-string) + 24)))) + +;;; (CURRENT-ERROR-PORT) +(define current-error-port + (let ((port (console-output-port))) ; changed from current-output-port + (lambda () port))) -(define *features* - '(source ; Chez Scheme can load Scheme source files, with the - ; command (slib:load-source "filename") -- see below. +;;; (TMPNAM) makes a temporary file name. +(define tmpnam + (let ((cntr 100)) + (lambda () + (set! cntr (+ 1 cntr)) + (let ((tmp (string-append "slib_" (number->string cntr)))) + (if (file-exists? tmp) (tmpnam) tmp))))) - compiled ; Chez Scheme can also load compiled Scheme files, with the - ; command (slib:load-compiled "filename") -- see below. +;;; (FILE-EXISTS? ) is built-in to Chez Scheme - char-ready? delay dynamic-wind fluid-let format - full-continuation getenv ieee-p1178 macro multiarg/and- - multiarg-apply pretty-print random random-inexact rationalize - rev3-procedures rev3-report rev4-optional-procedures rev4-report - sort string-port system transcript values with-file)) +;;; (DELETE-FILE ) is built-in to Chez Scheme -;; Version 5.0c has R4RS macros, but not defmacro. +;; The FORCE-OUTPUT requires buffered output that has been written to a +;; port to be transferred all the way out to its ultimate destination. +(define force-output flush-output-port) -(define *defmacros* - (list (cons 'defmacro - (lambda (name parms . body) - `(set! *defmacros* (cons (cons ',name (lambda ,parms ,@body)) - *defmacros*)))))) -(define (defmacro? m) (and (assq m *defmacros*) #t)) +;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string +;;; port versions of CALL-WITH-*PUT-FILE. -(define (macroexpand-1 e) - (if (pair? e) (let ((a (car e))) - (cond ((symbol? a) (set! a (assq a *defmacros*)) - (if a (apply (cdr a) (cdr e)) e)) - (else e))) - e)) +;;; CHAR-CODE-LIMIT is one greater than the largest integer which can +;;; be returned by CHAR->INTEGER. +(define char-code-limit 256) -(define (macroexpand e) - (if (pair? e) (let ((a (car e))) - (cond ((symbol? a) - (set! a (assq a *defmacros*)) - (if a (macroexpand (apply (cdr a) (cdr e))) e)) - (else e))) - e)) +;;; MOST-POSITIVE-FIXNUM is used in modular.scm +;; Chez's MOST-POSITIVE-FIXNUM is a thunk rather than a number. -(define base:eval eval) -(define (defmacro:eval x) (base:eval (defmacro:expand* x))) -(define (defmacro:expand* x) - (require 'defmacroexpand) (apply defmacro:expand* x '())) +(if (procedure? most-positive-fixnum) + (set! most-positive-fixnum (most-positive-fixnum))) + +;;; Return argument +(define (identity x) x) -;; Chez's sorting routines take parameters in the order opposite to SLIB's. -;; The following definitions override the predefined procedures with the -;; parameters-reversed versions. +;;; SLIB:EVAL is single argument eval using the top-level (user) environment. +(define slib:eval eval) + +;;; define an error procedure for the library +(define slib:error + (lambda args + (let ((port (current-error-port))) + (display "Error: " port) + (for-each (lambda (x) (display x port)) args) + (error #f "")))) + +;;; define these as appropriate for your system. +(define slib:tab #\tab) +(define slib:form-feed #\page) + +;;; Support for older versions of Scheme. Not enough code for its own file. +;;; last-pair is built-in to Chez Scheme +(define t #t) +(define nil #f) + +;;; Define these if your implementation's syntax can support it and if +;;; they are not already defined. +;;; 1+, -1+, and 1- are built-in to Chez Scheme +;(define (1+ n) (+ n 1)) +;(define (-1+ n) (+ n -1)) +;(define 1- -1+) + +;;; (IN-VICINITY ) is simply STRING-APPEND, conventionally used +;;; to attach a directory pathname to the name of a file that is expected to +;;; be in that directory. +(define in-vicinity string-append) + +;;; Define SLIB:EXIT to be the implementation procedure to exit or +;;; return if exitting not supported. +(define slib:chez:quit + (let ((arg (call-with-current-continuation identity))) + (cond ((procedure? arg) arg) + (arg (exit)) + (else (exit 1))))) + +(define slib:exit + (lambda args + (cond ((null? args) (slib:chez:quit #t)) + ((eqv? #t (car args)) (slib:chez:quit #t)) + ((eqv? #f (car args)) (slib:chez:quit #f)) + ((zero? (car args)) (slib:chez:quit #t)) + (else (slib:chez:quit #f))))) + +;;; For backward compatability, the SCHEME-FILE-SUFFIX procedure is defined +;;; to return the string ".scm". Note, however, that ".ss" is a common Chez +;;; file suffix. +(define scheme-file-suffix + (let ((suffix (case (software-type) + ((NOSVE) "_scm") + (else ".scm")))) + (lambda () suffix))) + +;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever +;;; suffix all the module files in SLIB have. See feature 'SOURCE. + +(define (slib:load-source f) (load (string-append f ".scm"))) + +;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced +;;; by compiling "foo.scm" if this implementation can compile files. +;;; See feature 'COMPILED. + +(define slib:load-compiled load) + +;;; At this point SLIB:LOAD must be able to load SLIB files. + +(define slib:load slib:load-source) + +;;; The following make procedures in Chez Scheme compatible with +;;; the assumptions of SLIB. + +;;; Chez's sorting routines take parameters in the order opposite to SLIB's. +;;; The following definitions override the predefined procedures with the +;;; parameters-reversed versions. See the SORT feature. (define chez:sort sort) (define chez:sort! sort!) @@ -211,7 +292,8 @@ (lambda (s1 s2 p) (chez:merge! p s1 s2))) -;; Chez's (FORMAT F . A) corresponds to SLIB's (FORMAT #F F . A) +;;; Chez's (FORMAT F . A) corresponds to SLIB's (FORMAT #F F . A) +;;; See the FORMAT feature. (define chez:format format) @@ -222,173 +304,86 @@ ((eq? where #t) (display str)) (else (display str where)))))) -;; Chez's NIL variable is bound to '(); SLIB's is bound to #F. - -(define nil #f) - -;; SLIB provides identifiers for the TAB (ASCII 9) and FORM-FEED (ASCII 12) -;; characters. - -(define slib:tab #\tab) -(define slib:form-feed #\page) - ;; The following definitions implement a few widely useful procedures that ;; Chez Scheme does not provide or provides under a different name. -;; The RENAME-FILE procedure constructs and executes a Unix mv command to -;; change the name of a file. - -(define rename-file - (lambda (src dst) - (system (string-append "mv " src " " dst)))) - -;; The CURRENT-ERROR-PORT procedure returns a port to which error -;; messages are to be displayed; this is the original standard output -;; port (even if the program subsequently changes the current output port -;; somehow). - -(define current-error-port - (let ((port (current-output-port))) - (lambda () port))) - -;; SLIB provides its own version of the ERROR procedure. - -(define slib:error - (lambda args - (let ((port (current-error-port))) - (display "Error: " port) - (for-each (lambda (x) (display x port)) args) - (error #f "")))) - -;; The TMPNAM procedure constructs and returns a temporary file name, -;; presumably unique and not a duplicate of one already existing. - -(define tmpnam - (let ((cntr 100)) - (lambda () - (set! cntr (+ 1 cntr)) - (let ((tmp (string-append "slib_" (number->string cntr)))) - (if (file-exists? tmp) (tmpnam) tmp))))) - -;; The FORCE-OUTPUT requires buffered output that has been written to a -;; port to be transferred all the way out to its ultimate destination. - -(define force-output flush-output) - -;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string -;; port versions of CALL-WITH-INPUT-FILE and CALL-WITH-OUTPUT-FILE. +;;; CALL-WITH-INPUT-STRING and CALL-WITH-OUTPUT-STRING are the string +;;; port versions of CALL-WITH-INPUT-FILE and CALL-WITH-OUTPUT-FILE. +;;; See the STRING-PORT feature. (define call-with-output-string (lambda (f) (let ((outsp (open-output-string))) (f outsp) (let ((s (get-output-string outsp))) - (close-output-port outsp) - s)))) + (close-output-port outsp) + s)))) (define call-with-input-string (lambda (s f) (let* ((insp (open-input-string s)) - (res (f insp))) + (res (f insp))) (close-input-port insp) res))) -;; CHAR-CODE-LIMIT is the number of characters in the character set; only -;; non-negative integers less than CHAR-CODE-LIMIT are eligible as -;; arguments to INTEGER->CHAR. - -(define char-code-limit 256) - -;; Chez's MOST-POSITIVE-FIXNUM is a thunk rather than a number. - -(if (procedure? most-positive-fixnum) - (set! most-positive-fixnum (most-positive-fixnum))) - -;; The IDENTITY procedure returns its argument without change. - -(define identity - (lambda (x) x)) - -;; The GENTEMP procedure generates unused symbols and marks them as -;; belonging to the SLIB package. - -(define gentemp - (let ((*gensym-counter* -1)) - (lambda () - (set! *gensym-counter* (+ *gensym-counter* 1)) - (string->symbol - (string-append "slib:G" (number->string *gensym-counter*)))))) - -;; The IN-VICINITY procedure is simply STRING-APPEND, conventionally used -;; to attach a directory pathname to the name of a file that is expected to -;; be in that directory. - -(define in-vicinity string-append) - -;; For backward compatability, the SCHEME-FILE-SUFFIX procedure is defined -;; to return the string ".scm". Note, however, that ".ss" is a common Chez -;; file suffix. - -(define scheme-file-suffix - (lambda () ".scm")) - -;; SLIB appropriates Chez Scheme's EVAL procedure. - -(define slib:eval eval) +;;; If your implementation provides R4RS macros: (define macro:eval slib:eval) +;;; macro:load also needs the default suffix. +(define macro:load slib:load-source) -(define slib:eval-load - (lambda ( evl) - (if (not (file-exists? )) - (set! (string-append (scheme-file-suffix)))) - (call-with-input-file - (lambda (port) - (let ((old-load-pathname *load-pathname*)) - (set! *load-pathname* ) - (do ((o (read port) (read port))) - ((eof-object? o)) - (evl o)) - (set! *load-pathname* old-load-pathname)))))) - -;; SLIB:EXIT is the implementation procedure that exits, or returns -;; if exiting is not supported. - -(define slib:chez:quit - (let ((arg (call-with-current-continuation identity))) - (cond ((procedure? arg) arg) - (arg (exit)) - (else (exit 1))))) - -(define slib:exit - (lambda args - (cond ((null? args) (slib:chez:quit #t)) - ((eqv? #t (car args)) (slib:chez:quit #t)) - ((eqv? #f (car args)) (slib:chez:quit #f)) - ((zero? (car args)) (slib:chez:quit #t)) - (else (slib:chez:quit #f))))) - -;; The SLIB:LOAD-SOURCE procedure, given a string argument, should attach -;; the appropriate file suffix to the string and load the file named -;; by the resulting string. - -(define slib:load-source - (lambda (f) - (load (string-append f (scheme-file-suffix))))) - -;;; defmacro:load and macro:load also need the default suffix. +(define *defmacros* + (list (cons 'defmacro + (lambda (name parms . body) + `(set! *defmacros* (cons (cons ',name (lambda ,parms ,@body)) + *defmacros*)))))) +(define (defmacro? m) (and (assq m *defmacros*) #t)) -(define macro:load slib:load-source) +(define (macroexpand-1 e) + (if (pair? e) (let ((a (car e))) + (cond ((symbol? a) (set! a (assq a *defmacros*)) + (if a (apply (cdr a) (cdr e)) e)) + (else e))) + e)) -;; The SLIB:LOAD-COMPILED procedure, given a string argument, finds and -;; loads the file, assumed to have been compiled. +(define (macroexpand e) + (if (pair? e) (let ((a (car e))) + (cond ((symbol? a) + (set! a (assq a *defmacros*)) + (if a (macroexpand (apply (cdr a) (cdr e))) e)) + (else e))) + e)) -(define slib:load-compiled load) +;;; According to Kent Dybvig, you can improve the Chez Scheme init +;;; file by defining gentemp to be gensym in Chez Scheme. +(define gentemp gensym) -;; SLIB:LOAD can now be defined to load SLIB files. +(define base:eval slib:eval) +(define (defmacro:eval x) (base:eval (defmacro:expand* x))) +(define (defmacro:expand* x) + (require 'defmacroexpand) (apply defmacro:expand* x '())) -(define slib:load slib:load-source) +(define (slib:eval-load evl) + (if (not (file-exists? )) + (set! (string-append (scheme-file-suffix)))) + (call-with-input-file + (lambda (port) + (let ((old-load-pathname *load-pathname*)) + (set! *load-pathname* ) + (do ((o (read port) (read port))) + ((eof-object? o)) + (evl o)) + (set! *load-pathname* old-load-pathname))))) + +(define (defmacro:load ) + (slib:eval-load defmacro:eval)) + +(define slib:warn + (lambda args + (let ((port (current-error-port))) + (display "Warn: " port) + (for-each (lambda (x) (display x port)) args)))) -;; Load the REQUIRE package. +;;; Load the REQUIRE package. (slib:load (in-vicinity (library-vicinity) "require")) diff --git a/collect.scm b/collect.scm index abdf209..35a333d 100644 --- a/collect.scm +++ b/collect.scm @@ -23,10 +23,10 @@ (define-operation (collect:gen-elts ) ;; return element generator ;; default behavior (cond ;; see utilities, below, for generators - ((vector? ) (collect:vector-gen-elts )) + ((vector? ) (collect:vector-gen-elts )) ((list? ) (collect:list-gen-elts )) ((string? ) (collect:string-gen-elts )) - (else + (else (slib:error "Operation not supported: GEN-ELTS " (yasos:print obj #f))) ) ) @@ -117,7 +117,7 @@ (let loop ( (count 0) ) (cond ((< count max+1) - (set! + (set! (apply (map (lambda (g) (g)) generators))) (loop (collect:add1 count)) ) @@ -171,7 +171,7 @@ (define (set-loop last this idx) (cond - ((zero? idx) + ((zero? idx) (set-cdr! last (cons (cdr this))) ) @@ -203,7 +203,7 @@ (let ( (max+1 (yasos:size vec)) (index 0) ) - (lambda () + (lambda () (cond ((< index max+1) (set! index (collect:add1 index)) ( vec (collect:sub1 index)) diff --git a/comlist.scm b/comlist.scm index 1751c7f..8ecf525 100644 --- a/comlist.scm +++ b/comlist.scm @@ -31,7 +31,7 @@ (define (comlist:copy-list lst) (append lst '())) -(define (comlist:adjoin e l) (if (memq e l) l (cons e l))) +(define (comlist:adjoin e l) (if (memv e l) l (cons e l))) (define (comlist:union l1 l2) (cond ((null? l1) l2) @@ -176,13 +176,22 @@ ((car args) #t) (else (apply comlist:or? (cdr args))))) -; Checks to see if a list has any duplicates. +;;; Checks to see if a list has any duplicate MEMBERs. (define (comlist:has-duplicates? lst) (cond ((null? lst) #f) ((member (car lst) (cdr lst)) #t) (else (comlist:has-duplicates? (cdr lst))))) -(define (comlist:list* x . y) +;;; remove duplicates of MEMBERs of a list +(define (comlist:remove-duplicates lst) + (letrec ((rem-dup + (lambda (lst nlst) + (cond ((null? lst) nlst) + ((member (car lst) nlst) (rem-dup (cdr lst) nlst)) + (else (rem-dup (cdr lst) (cons (car lst) nlst))))))) + (rem-dup lst '()))) + +(define (comlist:list* x . y) (define (list*1 x) (if (null? (cdr x)) (car x) @@ -283,7 +292,7 @@ ((equal? obj (car list)) (delete (cdr list))) (else (set-cdr! list (delete (cdr list))) - list)))) + list)))) (define (comlist:delete-if pred list) (let delete-if ((list list)) @@ -291,7 +300,7 @@ ((pred (car list)) (delete-if (cdr list))) (else (set-cdr! list (delete-if (cdr list))) - list)))) + list)))) (define (comlist:delete-if-not pred list) (let delete-if ((list list)) @@ -299,7 +308,7 @@ ((not (pred (car list))) (delete-if (cdr list))) (else (set-cdr! list (delete-if (cdr list))) - list)))) + list)))) ;;; exports @@ -330,6 +339,7 @@ (define and? comlist:and?) (define or? comlist:or?) (define has-duplicates? comlist:has-duplicates?) +(define remove-duplicates comlist:remove-duplicates) (define delete-if-not comlist:delete-if-not) (define delete-if comlist:delete-if) diff --git a/cring.scm b/cring.scm index c3d67cd..320b1d2 100644 --- a/cring.scm +++ b/cring.scm @@ -1,5 +1,5 @@ ;;;"cring.scm" Extend Scheme numerics to any commutative ring. -;Copyright (C) 1997 Aubrey Jaffer +;Copyright (C) 1997, 1998 Aubrey Jaffer ; ;Permission to copy this software, to redistribute it, and to use it ;for any purpose is granted, subject to the following restrictions and @@ -22,6 +22,68 @@ (require 'database-utilities) (require 'sort) +(define cring:db (create-database #f 'alist-table)) +(define (make-ruleset . rules) + (define name #f) + (cond ((and (not (null? rules)) (symbol? (car rules))) + (set! name (car rules)) + (set! rules (cdr rules))) + (else (set! name (gentemp)))) + (define-tables cring:db + (list name + '((op symbol) + (sub-op1 symbol) + (sub-op2 symbol)) + '((reduction expression)) + rules)) + (let ((table ((cring:db 'open-table) name #t))) + (and table + (list (table 'get 'reduction) + (table 'row:update) + table)))) +(define *ruleset* (make-ruleset 'default)) +(define (cring:define-rule . args) + (if *ruleset* + ((cadr *ruleset*) args) + (slib:warn "No ruleset in *ruleset*"))) + +(define (combined-rulesets . rulesets) + (define name #f) + (cond ((symbol? (car rulesets)) + (set! name (car rulesets)) + (set! rulesets (cdr rulesets))) + (else (set! name (gentemp)))) + (apply make-ruleset name + (apply append + (map (lambda (ruleset) (((caddr ruleset) 'row:retrieve*))) + rulesets)))) + +;;; Distribute * over + (and -) +(define distribute* + (make-ruleset + 'distribute* + `(* + identity + ,(lambda (exp1 exp2) + ;;(print 'distributing '* '+ exp1 exp2 '==>) + (apply + (map (lambda (trm) (* trm exp2)) (cdr exp1))))) + `(* - identity + ,(lambda (exp1 exp2) + ;;(print 'distributing '* '- exp1 exp2 '==>) + (apply - (map (lambda (trm) (* trm exp2)) (cdr exp1))))))) + +;;; Distribute / over + (and -) +(define distribute/ + (make-ruleset + 'distribute/ + `(/ + identity + ,(lambda (exp1 exp2) + ;;(print 'distributing '/ '+ exp1 exp2 '==>) + (apply + (map (lambda (trm) (/ trm exp2)) (cdr exp1))))) + `(/ - identity + ,(lambda (exp1 exp2) + ;;(print 'distributing '/ '- exp1 exp2 '==>) + (apply - (map (lambda (trm) (/ trm exp2)) (cdr exp1))))))) + (define (symbol-alpha? sym) (char-alphabetic? (string-ref (symbol->string sym) 0))) (define (expression-< x y) @@ -41,36 +103,6 @@ (else (expression-< (cdr x) (cdr y))))) (define (expression-sort seq) (sort! seq expression-<)) -(define cring:db (create-database #f 'alist-table)) -(define-tables cring:db - `(operation - ((op symbol) - (sub-op1 symbol) - (sub-op2 symbol)) - ((reduction expression)) - (;; This is the distributive rule (* over +) - (* + identity - ,(lambda (exp1 exp2) - ;;(print 'distributing '* '+ exp1 exp2 '==>) - (apply + (map (lambda (trm) (* trm exp2)) (cdr exp1))))) - (* - identity - ,(lambda (exp1 exp2) - ;;(print 'distributing '* '- exp1 exp2 '==>) - (apply - (map (lambda (trm) (* trm exp2)) (cdr exp1))))) - (/ + identity - ,(lambda (exp1 exp2) - ;;(print 'distributing '/ '+ exp1 exp2 '==>) - (apply + (map (lambda (trm) (/ trm exp2)) (cdr exp1))))) - (/ - identity - ,(lambda (exp1 exp2) - ;;(print 'distributing '/ '- exp1 exp2 '==>) - (apply - (map (lambda (trm) (/ trm exp2)) (cdr exp1)))))))) - -(define cring:op-tab ((cring:db 'open-table) 'operation #t)) -(define cring:rule (cring:op-tab 'get 'reduction)) -(define cring:defrule (cring:op-tab 'row:update)) -(define (cring:define-rule . args) (cring:defrule args)) - (define number* *) (define number+ +) (define number- -) @@ -425,8 +457,9 @@ (arg-loop arg.pows))))) (define (cring:try-rule op sop1 sop2 exp1 exp2) - (let ((rule (cring:rule op sop1 sop2))) - (and rule (rule exp1 exp2)))) + (and *ruleset* + (let ((rule ((car *ruleset*) op sop1 sop2))) + (and rule (rule exp1 exp2))))) (define (cring:apply-rule op exp1 exp2) (and (pair? exp1) diff --git a/dbrowse.scm b/dbrowse.scm index 8008c04..082cef3 100644 --- a/dbrowse.scm +++ b/dbrowse.scm @@ -1,5 +1,5 @@ ;;; "dbrowse.scm" relational-database-browser -; Copyright 1996, 1997 Aubrey Jaffer +; Copyright 1996, 1997, 1998 Aubrey Jaffer ; ;Permission to copy this software, to redistribute it, and to use it ;for any purpose is granted, subject to the following restrictions and @@ -47,13 +47,9 @@ table-name)))))))) (define (browse:display-dir table-name table) - (printf "%s Tables: -" table-name) + (printf "%s Tables:\\n" table-name) ((table 'for-each-row) - (lambda (row) - (printf " %s -" - (car row))))) + (lambda (row) (printf "\\t%s\\n" (car row))))) (define (browse:display-table table-name table) (let* ((width 18) @@ -65,8 +61,7 @@ (dw-integer (string-append dw "d")) (underline (string-append (make-string (+ -1 width) #\=) " ")) (form "")) - (printf "Table: %s -" table-name) + (printf "Table: %s\\n" table-name) (for-each (lambda (name) (printf dwp-string name)) (table 'column-names)) (newline) @@ -88,8 +83,7 @@ (printf dwp-string type)) (table 'column-types)) (newline) - (set! form (string-append form " -")) + (set! form (string-append form "\\n")) (for-each (lambda (domain) (printf underline)) (table 'column-domains)) (newline) diff --git a/debug.scm b/debug.scm index 08406a9..58f6b03 100644 --- a/debug.scm +++ b/debug.scm @@ -19,12 +19,12 @@ (require 'trace) (require 'break) +(require 'line-i/o) (define (for-each-top-level-definition-in-file file proc) (call-with-input-file file - (lambda - (port) + (lambda (port) (letrec ((walk (lambda (exp) @@ -45,6 +45,8 @@ ((defmacro define-syntax) "should do something clever here") ((define) (proc exp)))))))) + (if (eqv? #\# (peek-char port)) + (read-line port)) ;remove `magic-number' (do ((form (read port) (read port))) ((eof-object? form)) (walk form)))))) diff --git a/elk.init b/elk.init index a127cf9..5acda43 100644 --- a/elk.init +++ b/elk.init @@ -1,21 +1,7 @@ ;;;"elk.init" Initialisation file for SLIB for ELK 2.1 -*- Scheme -*- -;;; Copyright (C) 1991, 1992, 1993, 1994, 1997 Aubrey Jaffer. -; -;Permission to copy this software, to redistribute it, and to use it -;for any purpose is granted, subject to the following restrictions and -;understandings. -; -;1. Any copy made of this software must include this copyright notice -;in full. -; -;2. I have made no warrantee or representation that the operation of -;this software will be error-free, and I am under no obligation to -;provide any services, by way of maintenance, update, or otherwise. -; -;3. In conjunction with products arising from the use of this -;material, there shall be no use of my name in any advertising, -;promotional, or sales literature without prior written consent in -;each case. +;;; Author: Aubrey Jaffer +;;; +;;; This code is in the public domain. ; No guarantees are given about the correctness of any of the ; choices made below. Only enough work was done to get the require @@ -38,6 +24,13 @@ (define (scheme-implementation-type) 'Elk) +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) + "http://www.informatik.uni-bremen.de/~net/elk/") + ;;; (scheme-implementation-version) should return a string describing ;;; the version the scheme implementation loading this file. diff --git a/factor.scm b/factor.scm index a5c7b44..f10f0d5 100644 --- a/factor.scm +++ b/factor.scm @@ -1,5 +1,5 @@ -;;;; "factor.scm", prime test and factorization for Scheme -;;; Copyright (C) 1991, 1992, 1993 Aubrey Jaffer. +;;;; "factor.scm" factorization, prime test and generation +;;; Copyright (C) 1991, 1992, 1993, 1998 Aubrey Jaffer. ; ;Permission to copy this software, to redistribute it, and to use it ;for any purpose is granted, subject to the following restrictions and @@ -17,8 +17,31 @@ ;promotional, or sales literature without prior written consent in ;each case. -(require 'random) +(require 'common-list-functions) (require 'modular) +(require 'random) +(require 'byte) + +;;@body +;;@0 is the random-state (@pxref{Random Numbers}) used by these +;;procedures. If you call these procedures from more than one thread +;;(or from interrupt), @code{random} may complain about reentrant +;;calls. +(define prime:prngs + (make-random-state "repeatable seed for primes")) + + +;;@emph{Note:} The prime test and generation procedures implement (or +;;use) the Solovay-Strassen primality test. See +;; +;;@itemize @bullet +;;@item Robert Solovay and Volker Strassen, +;;@cite{A Fast Monte-Carlo Test for Primality}, +;;SIAM Journal on Computing, 1977, pp 84-85. +;;@end itemize + +;;; Solovay-Strassen Prime Test +;;; if n is prime, then J(a,n) is congruent mod n to a**((n-1)/2) ;;; (modulo p 16) is because we care only about the low order bits. ;;; The odd? tests are inline of (expt -1 ...) @@ -35,41 +58,104 @@ (if (odd? (quotient (- (* qq qq) 1) 8)) (- (prime:jacobi-symbol (quotient p 2) q)) (prime:jacobi-symbol (quotient p 2) q)))))) +;;@args p q +;;Returns the value (+1, @minus{}1, or 0) of the Jacobi-Symbol of +;;exact non-negative integer @1 and exact positive odd integer @2. +(define jacobi-symbol prime:jacobi-symbol) -;;;; Solovay-Strassen Prime Test -;;; if n is prime, then J(a,n) is congruent mod n to a**((n-1)/2) - -;;; See: -;;; Robert Solovay and Volker Strassen, -;;; "A Fast Monte-Carlo Test for Primality," -;;; SIAM Journal on Computing, 1977, pp 84-85. +;;@body +;;@0 the maxinum number of iterations of Solovay-Strassen that will +;;be done to test a number for primality. +(define prime:trials 30) ;;; checks if n is prime. Returns #f if not prime. #t if (probably) prime. ;;; probability of a mistake = (expt 2 (- prime:trials)) ;;; choosing prime:trials=30 should be enough -(define prime:trials 30) -;;; prime:product is a product of small primes. -(define prime:product - (let ((p 210)) - (for-each (lambda (s) - (set! s (string->number s)) - (set! p (or (and s (exact? s) s) p))) - '("2310" "30030" "510510" "9699690" "223092870" - "6469693230" "200560490130")) - p)) +(define (Solovay-Strassen-prime? n) + (do ((i prime:trials (- i 1)) + (a (+ 2 (random (- n 2) prime:prngs)) + (+ 2 (random (- n 2) prime:prngs)))) + ((not (and (positive? i) + (= (gcd a n) 1) + (= (modulo (prime:jacobi-symbol a n) n) + (modular:expt n a (quotient (- n 1) 2))))) + (if (positive? i) #f #t)))) + +;;; prime:products are products of small primes. +(define (primes-gcd? n comps) + (comlist:notevery (lambda (prd) (= 1 (gcd n prd))) comps)) +(define prime:prime-sqr 121) +(define prime:products '(105)) +(define prime:sieve (bytes 0 0 1 1 0 1 0 1 0 0 0)) +(letrec ((lp (lambda (comp comps primes nexp) + (cond ((< comp (quotient most-positive-fixnum nexp)) + (let ((ncomp (* nexp comp))) + (lp ncomp comps + (cons nexp primes) + (next-prime nexp (cons ncomp comps))))) + ((< (quotient comp nexp) (* nexp nexp)) + (set! prime:prime-sqr (* nexp nexp)) + (set! prime:sieve (make-bytes nexp 0)) + (for-each (lambda (prime) + (byte-set! prime:sieve prime 1)) + primes) + (set! prime:products (reverse (cons comp comps)))) + (else + (lp nexp (cons comp comps) + (cons nexp primes) + (next-prime nexp (cons comp comps))))))) + (next-prime (lambda (nexp comps) + (set! comps (reverse comps)) + (do ((nexp (+ 2 nexp) (+ 2 nexp))) + ((not (primes-gcd? nexp comps)) nexp))))) + (lp 3 '() '(2 3) 5)) (define (prime:prime? n) (set! n (abs n)) - (cond ((<= n 36) (and (memv n '(2 3 5 7 11 13 17 19 23 29 31)) #t)) - ((= 1 (gcd n prime:product)) - (do ((i prime:trials (- i 1)) - (a (+ 1 (random (- n 1))) (+ 1 (random (- n 1))))) - ((not (and (positive? i) - (= (gcd a n) 1) - (= (modulo (prime:jacobi-symbol a n) n) - (modular:expt n a (quotient (- n 1) 2))))) - (if (positive? i) #f #t)))) - (else #f))) + (cond ((< n (bytes-length prime:sieve)) (positive? (byte-ref prime:sieve n))) + ((even? n) #f) + ((primes-gcd? n prime:products) #f) + ((< n prime:prime-sqr) #t) + (else (Solovay-Strassen-prime? n)))) +;;@args n +;;Returns @code{#f} if @1 is composite; @code{#t} if @1 is prime. +;;There is a slight chance @code{(expt 2 (- prime:trials))} that a +;;composite will return @code{#t}. +(define prime? prime:prime?) +(define probably-prime? prime:prime?) ;legacy + +(define (prime:prime< start) + (do ((nbr (+ -1 start) (+ -1 nbr))) + ((or (negative? nbr) (prime:prime? nbr)) + (if (negative? nbr) #f nbr)))) + +(define (prime:primes< start count) + (do ((cnt (+ -2 count) (+ -1 cnt)) + (lst '() (cons prime lst)) + (prime (prime:prime< start) (prime:prime< prime))) + ((or (not prime) (negative? cnt)) + (if prime (cons prime lst) lst)))) +;;@args start count +;;Returns a list of the first @2 prime numbers less than +;;@1. If there are fewer than @var{count} prime numbers +;;less than @var{start}, then the returned list will have fewer than +;;@var{start} elements. +(define primes< prime:primes<) + +(define (prime:prime> start) + (do ((nbr (+ 1 start) (+ 1 nbr))) + ((prime:prime? nbr) nbr))) + +(define (prime:primes> start count) + (set! start (max 0 start)) + (do ((cnt (+ -2 count) (+ -1 cnt)) + (lst '() (cons prime lst)) + (prime (prime:prime> start) (prime:prime> prime))) + ((negative? cnt) + (reverse (cons prime lst))))) +;;@args start count +;;Returns a list of the first @2 prime numbers greater than @1. +(define primes> prime:primes>) ;;;;Lankinen's recursive factoring algorithm: ;From: ld231782@longs.LANCE.ColoState.EDU (L. Detweiler) @@ -81,7 +167,7 @@ ; | f(u,v,2b,n/2) or f(u+b,v+b,2b,(n-u-v-b)/2) if n even ;Thm: f(1,1,2,(m-1)/2) = (p,q) iff pq=m for odd m. - + ;It may be illuminating to consider the relation of the Lankinen function in ;a `computational hierarchy' of other factoring functions.* Assumptions are ;made herein on the basis of conventional digital (binary) computers. Also, @@ -89,7 +175,7 @@ ;be factored is prime). However, all algorithms would probably perform to ;the same constant multiple of the given orders for complete composite ;factorizations. - + ;Thm: Eratosthenes' Sieve is very roughtly O(ln(n)/n) in time and ; O(n*log2(n)) in space. ;Pf: It works with all prime factors less than n (about ln(n)/n by the prime @@ -101,7 +187,7 @@ ;Pf: It tests all odd factors less than the square root of n (about ; sqrt(n)/2), with log2(n) time for each division. It requires only ; log2(n) space for the number and divisors. - + ;Thm: Lankinen's algorithm is O(sqrt(n)/2) in time and O((sqrt(n)/2)*log2(n)) ; in space. ;Pf: The algorithm is easily modified to seach only for factors p= k n) new) + (array-set! new (* (array-ref ara k) scale) (bit-reverse lgn k)))) + +(define (dft! ara n dir) + (define lgn (integer-length (+ -1 n))) + (define pi2i (* 0+8i (atan 1))) + (do ((s 1 (+ 1 s))) + ((> s lgn) ara) + (let* ((m (expt 2 s)) + (w_m (exp (* dir (/ pi2i m)))) + (m/2-1 (+ (quotient m 2) -1))) + (do ((j 0 (+ 1 j)) + (w 1 (* w w_m))) + ((> j m/2-1)) + (do ((k j (+ m k))) + ((>= k n)) + (let* ((k+m/2 (+ k m/2-1 1)) + (t (* w (array-ref ara k+m/2))) + (u (array-ref ara k))) + (array-set! ara (+ u t) k) + (array-set! ara (- u t) k+m/2))))))) + +(define (fft ara) + (define n (car (array-dimensions ara))) + (dft! (fft:shuffled&scaled ara n 1) n 1)) + +(define (fft-1 ara) + (define n (car (array-dimensions ara))) + (dft! (fft:shuffled&scaled ara n (/ n)) n -1)) diff --git a/fluidlet.scm b/fluidlet.scm index c93b288..59ba481 100644 --- a/fluidlet.scm +++ b/fluidlet.scm @@ -1,5 +1,5 @@ ; "fluidlet.scm", FLUID-LET for Scheme -; Copyright (c) 1992, Dorai Sitaram (dorai@cs.rice.edu) +; Copyright (c) 1998, Aubrey Jaffer ; ;Permission to copy this software, to redistribute it, and to use it ;for any purpose is granted, subject to the following restrictions and @@ -17,29 +17,24 @@ ;promotional, or sales literature without prior written consent in ;each case. -(require 'rev4-optional-procedures) -(require 'common-list-functions) (require 'dynamic-wind) -(require 'macro) +(require 'common-list-functions) ;MAKE-LIST -(define list-set! (lambda (s i v) (set-car! (list-tail s i) v))) - -(define-syntax fluid-let - (syntax-rules () - ((fluid-let ((x v) ...) . body) - (let ((%x-names (list 'x ...)) - (%x-values (list x ...)) - (%fluid-x-values (list v ...))) +(defmacro fluid-let (clauses . body) + (let ((ids (map car clauses)) + (new-tmps (map (lambda (x) (gentemp)) clauses)) + (old-tmps (map (lambda (x) (gentemp)) clauses))) + `(let (,@(map list new-tmps (map cadr clauses)) + ,@(map list old-tmps (make-list (length clauses) #f))) (dynamic-wind - (lambda () - (set! x (list-ref %fluid-x-values - (comlist:position 'x %x-names))) - ...) - (lambda () . body) - (lambda () - (let ((%x-position (comlist:position 'x %x-names))) - (list-set! %fluid-x-values %x-position x) - (set! x (list-ref %x-values %x-position))) - ...)))))) - -;--- end of file + (lambda () + ,@(map (lambda (ot id) `(set! ,ot ,id)) + old-tmps ids) + ,@(map (lambda (id nt) `(set! ,id ,nt)) + ids new-tmps)) + (lambda () ,@body) + (lambda () + ,@(map (lambda (nt id) `(set! ,nt ,id)) + new-tmps ids) + ,@(map (lambda (id ot) `(set! ,id ,ot)) + ids old-tmps)))))) diff --git a/format.scm b/format.scm index e64efa7..d9f1c86 100644 --- a/format.scm +++ b/format.scm @@ -113,9 +113,9 @@ (substring format-string 0 format:pos) (substring format-string format:pos (string-length format-string)) - (list-head (cddr format:args) format:arg-pos) + (format:list-head (cddr format:args) format:arg-pos) (list-tail (cddr format:args) format:arg-pos))) - (format port + (format port "~%FORMAT: error with call: (format~{ ~a~})~% " format:args)) (apply format port args) @@ -140,28 +140,34 @@ (set! format:pos 0) (if (< (length args) 1) (format:error "not enough arguments")) - (let ((destination (car args)) - (arglist (cdr args))) - (cond - ((or (and (boolean? destination) ; port output - destination) - (output-port? destination) - (number? destination)) - (format:out (cond - ((boolean? destination) (current-output-port)) - ((output-port? destination) destination) - ((number? destination) (current-error-port))) - (car arglist) (cdr arglist))) - ((and (boolean? destination) ; string output - (not destination)) - (call-with-output-string - (lambda (port) (format:out port (car arglist) (cdr arglist))))) - ((string? destination) ; dest. is format string (Scheme->C) - (call-with-output-string - (lambda (port) - (format:out port destination arglist)))) - (else - (format:error "illegal destination `~a'" destination))))) + + ;; If the first argument is a string, then that's the format string. + ;; (Scheme->C) + ;; In this case, put the argument list in canonical form. + (let ((args (if (string? (car args)) + (cons #f args) + args))) + ;; Use this canonicalized version when reporting errors. + (set! format:args args) + + (let ((destination (car args)) + (arglist (cdr args))) + (cond + ((or (and (boolean? destination) ; port output + destination) + (output-port? destination) + (number? destination)) + (format:out (cond + ((boolean? destination) (current-output-port)) + ((output-port? destination) destination) + ((number? destination) (current-error-port))) + (car arglist) (cdr arglist))) + ((and (boolean? destination) ; string output + (not destination)) + (call-with-output-string + (lambda (port) (format:out port (car arglist) (cdr arglist))))) + (else + (format:error "illegal destination `~a'" destination)))))) (define (format:out port fmt args) ; the output handler for a port (set! format:port port) ; global port for output routines @@ -248,7 +254,7 @@ (if (= k 0) l (loop (cdr l) (- k 1)))))) (add-arg-pos - (lambda (n) + (lambda (n) (set! arg-pos (+ n arg-pos)) (set! format:arg-pos arg-pos))) @@ -491,7 +497,7 @@ ((#\() ; Case conversion begin (set! format:case-conversion (case modifier - ((at) string-capitalize-first) + ((at) format:string-capitalize-first) ((colon) string-capitalize) ((colon-at) string-upcase) (else string-downcase))) @@ -529,7 +535,7 @@ (cond ((eq? modifier 'colon) (set! clause-default #t) - (substring format-string clause-pos + (substring format-string clause-pos (- format:pos 3))) ((memq modifier '(at colon-at)) (format:error "illegal modifier in ~~;")) @@ -689,13 +695,14 @@ ;; format directive modifiers and parameters ((#\@) ; `@' modifier - (if (eq? modifier 'colon-at) + (if (memq modifier '(at colon-at)) (format:error "double `@' modifier")) (set! modifier (if (eq? modifier 'colon) 'colon-at 'at)) (tilde-dispatch)) ((#\:) ; `:' modifier - (if modifier (format:error "illegal `:' modifier position")) - (set! modifier 'colon) + (if (memq modifier '(colon colon-at)) + (format:error "double `:' modifier")) + (set! modifier (if (eq? modifier 'at) 'colon-at 'colon)) (tilde-dispatch)) ((#\') ; Character parameter (if modifier (format:error "misplaced modifier")) @@ -782,29 +789,29 @@ (loop j (+ j 1))) (loop i (+ j 1)))))))) obj)) - + ((boolean? obj) (if obj "#t" "#f")) - + ((number? obj) (number->string obj)) - ((symbol? obj) + ((symbol? obj) (if format:symbol-case-conv (format:symbol-case-conv (symbol->string obj)) (symbol->string obj))) - + ((char? obj) (if slashify (format:char->str obj) (string obj))) - + ((null? obj) "()") ((input-port? obj) (format:iobj->str obj)) - + ((output-port? obj) (format:iobj->str obj)) - + ((list? obj) (string-append "(" (let loop ((obj-list obj)) @@ -822,16 +829,16 @@ " . " (format:obj->str (cdr obj) #t) ")")) - + ((vector? obj) (string-append "#" (format:obj->str (vector->list obj) #t))) - (else ; only objects with an #<...> + (else ; only objects with an #<...> (format:iobj->str obj)))) ; representation should fall in here -;; format:iobj->str reveals the implementation dependent representation of +;; format:iobj->str reveals the implementation dependent representation of ;; #<...> objects with the use of display and call-with-output-string. -;; If format:read-proof is set to #t the resulting string is additionally +;; If format:read-proof is set to #t the resulting string is additionally ;; set into string quotes. (define format:read-proof #f) @@ -839,7 +846,7 @@ (define (format:iobj->str iobj) (if (or format:read-proof format:iobj-case-conv) - (string-append + (string-append (if format:read-proof "\"" "") (if format:iobj-case-conv (format:iobj-case-conv @@ -881,7 +888,7 @@ (if par (if name (if (< par 0) - (format:error + (format:error "~s parameter must be a positive integer" name) par) par) @@ -927,7 +934,7 @@ (if (and (memq modifier '(at colon-at)) (> number 0)) (set! numlen (+ numlen 1))) (if (memq modifier '(colon colon-at)) - (set! numlen (+ (quotient (- numstr-len + (set! numlen (+ (quotient (- numstr-len (if (< number 0) 2 1)) commawidth) numlen))) @@ -1071,7 +1078,8 @@ (if (> ones 0) (cons #\- (string->list - (list-ref format:cardinal-ones-list ones)))))))))) + (list-ref format:cardinal-ones-list ones))) + '()))))))) (define format:cardinal-thousand-block-list '("" " thousand" " million" " billion" " trillion" " quadrillion" @@ -1173,7 +1181,7 @@ (if digits (begin ; fixed precision - (format:parse-float + (format:parse-float (if (string? number) number (number->string number)) #t scale) (if (<= (- format:fn-len format:fn-dot) digits) (format:fn-zfill #f (- digits (- format:fn-len format:fn-dot))) @@ -1230,7 +1238,7 @@ (overch (format:par pars l 4 #f #f)) (padch (format:par pars l 5 format:space-ch #f)) (expch (format:par pars l 6 #f #f))) - + (if digits ; fixed precision (let ((digits (if (> scale 0) @@ -1238,7 +1246,7 @@ (+ (- digits scale) 1) 0) digits))) - (format:parse-float + (format:parse-float (if (string? number) number (number->string number)) #f scale) (if (<= (- format:fn-len format:fn-dot) digits) (format:fn-zfill #f (- digits (- format:fn-len format:fn-dot))) @@ -1250,11 +1258,11 @@ (if (or (not format:fn-pos?) (eq? modifier 'at)) (set! numlen (+ numlen 1))) (if (and (= format:fn-dot 0) (> width (+ digits 1))) - (set! numlen (+ numlen 1))) + (set! numlen (+ numlen 1))) (set! numlen - (+ numlen + (+ numlen (if (and edigits (>= edigits format:en-len)) - edigits + edigits format:en-len))) (if (< numlen width) (format:out-fill (- width numlen) @@ -1283,7 +1291,7 @@ (set! numlen (+ numlen (if (and edigits (>= edigits format:en-len)) - edigits + edigits format:en-len))) (if (< numlen width) (format:out-fill (- width numlen) @@ -1292,7 +1300,7 @@ (let ((f (- format:fn-len format:fn-dot))) ; fract len (if (> (- numlen f) width) (if overch ; numstr too big for required width - (format:out-fill width + (format:out-fill width (integer->char overch)) (begin (format:fn-out modifier #t) @@ -1307,7 +1315,7 @@ (begin (format:fn-out modifier #t) (format:en-out edigits expch)))))))) - + ;; format general flonums (~G) (define (format:out-general modifier number pars) @@ -1429,7 +1437,7 @@ (begin ; fixed format m.nnn or .nnn (if (and (> left-zeros 0) (> format:fn-dot 0)) - (if (> format:fn-dot left-zeros) + (if (> format:fn-dot left-zeros) (begin ; norm 0{0}nn.mm to nn.mm (format:fn-shiftleft left-zeros) (set! left-zeros 0) @@ -1470,7 +1478,7 @@ (set! format:fn-dot 1))) (format:en-set (- (+ (- format:fn-dot scale) (format:en-int)) negexp)) - (cond + (cond (all-zeros? (format:en-set 0) (set! format:fn-dot 1)) @@ -1484,10 +1492,10 @@ (set! format:fn-dot scale))))) #t) - ;; do body + ;; do body (set! c (string-ref num-str i)) ; parse the output of number->string (cond ; which can be any valid number - ((char-numeric? c) ; representation of R4RS except + ((char-numeric? c) ; representation of R4RS except (if mantissa? ; complex numbers (begin (if (char=? c #\0) @@ -1521,7 +1529,7 @@ 0 (do ((i 0 (+ i 1)) (n 0)) - ((= i format:en-len) + ((= i format:en-len) (if format:en-pos? n (- n))) @@ -1581,14 +1589,14 @@ (set! c (+ (- (char->integer (string-ref format:fn-str i)) format:zero-ch) c)) (string-set! format:fn-str i (integer->char - (if (< c 10) + (if (< c 10) (+ c format:zero-ch) (+ (- c 10) format:zero-ch)))) (set! c (if (< c 10) 0 1)))) (define (format:fn-out modifier add-leading-zero?) (if format:fn-pos? - (if (eq? modifier 'at) + (if (eq? modifier 'at) (format:out-char #\+)) (format:out-char #\-)) (if (= format:fn-dot 0) @@ -1601,7 +1609,7 @@ (define (format:en-out edigits expch) (format:out-char (if expch (integer->char expch) format:expch)) (format:out-char (if format:en-pos? #\+ #\-)) - (if edigits + (if edigits (if (< format:en-len edigits) (format:out-fill (- edigits format:en-len) #\0))) (format:out-substr format:en-str 0 format:en-len)) @@ -1624,18 +1632,7 @@ ;;; some global functions not found in SLIB -;; string-index finds the index of the first occurence of the character `c' -;; in the string `s'; it returns #f if there is no such character in `s'. - -(define (string-index s c) - (let ((slen-1 (- (string-length s) 1))) - (let loop ((i 0)) - (cond - ((char=? c (string-ref s i)) i) - ((= i slen-1) #f) - (else (loop (+ i 1))))))) - -(define (string-capitalize-first str) ; "hello" -> "Hello" +(define (format:string-capitalize-first str) ; "hello" -> "Hello" (let ((cap-str (string-copy str)) ; "hELLO" -> "Hello" (non-first-alpha #f) ; "*hello" -> "*Hello" (str-len (string-length str))) ; "hello you" -> "Hello you" @@ -1649,10 +1646,10 @@ (set! non-first-alpha #t) (string-set! cap-str i (char-upcase c))))))))) -(define (list-head l k) +(define (format:list-head l k) (if (= k 0) '() - (cons (car l) (list-head (cdr l) (- k 1))))) + (cons (car l) (format:list-head (cdr l) (- k 1))))) ;; Aborts the program when a formatting error occures. This is a null diff --git a/formatst.scm b/formatst.scm index 370a39c..3f19130 100644 --- a/formatst.scm +++ b/formatst.scm @@ -7,7 +7,7 @@ ; Failure reports for various scheme interpreters: ; -; SCM4d +; SCM4d ; None. ; Elk 2.2: ; None. @@ -16,7 +16,7 @@ ; represented as `#f'. ; Scheme->C 01nov91: ; None, if format:symbol-case-conv and format:iobj-case-conv are set -; to string-downcase. +; to string-downcase. (require 'format) (if (not (string=? format:version "3.0")) @@ -82,7 +82,7 @@ (test '("~a" #t) "#t") (test '("~a" #f) "#f") (test '("~a" "abc") "abc") -(test '("~a" '#(1 2 3)) "#(1 2 3)") +(test '("~a" #(1 2 3)) "#(1 2 3)") (test '("~a" ()) "()") (test '("~a" (a)) "(a)") (test '("~a" (a b)) "(a b)") @@ -294,7 +294,7 @@ def") (test '("~a" "abc \" abc") "abc \" abc") (test '("~s" #\space) "#\\space") (test '("~s" #\newline) "#\\newline") -(test '("~s" #\tab) "#\\ht") +(test `("~s" ,slib:tab) "#\\ht") (test '("~s" #\a) "#\\a") (test '("~a" (a "b" c)) "(a \"b\" c)") @@ -576,7 +576,7 @@ def") " 31. | 31.4 | 31.4 | 31. ") (test '("~9,2,1,,'*g|~9,3,2,3,'?,,'$g|~9,3,2,0,'%g|~9,2g" 314.159 314.159 314.159 314.159) - " 3.14E+2| 314. | 314. | 3.14E+2") + " 3.14E+2| 314. | 314. | 3.14E+2") (test '("~9,2,1,,'*g|~9,3,2,3,'?,,'$g|~9,3,2,0,'%g|~9,2g" 3141.59 3141.59 3141.59 3141.59) " 3.14E+3|314.2$+01|0.314E+04| 3.14E+3") @@ -586,8 +586,8 @@ def") (test '("~9,2,1,,'*g|~9,3,2,3,'?,,'$g|~9,3,2,0,'%g|~9,2g" 3.14E120 3.14E120 3.14E120 3.14E120) "*********|?????????|%%%%%%%%%|3.14E+120") - - (test '("~g" 0.0) "0.0 ") ; further ~g tests + + (test '("~g" 0.0) "0.0 ") ; further ~g tests (test '("~g" 0.1) "0.1 ") (test '("~g" 0.01) "1.0E-2") (test '("~g" 123.456) "123.456 ") @@ -624,7 +624,7 @@ def") ; complex numbers -(cond +(cond (format:complex-numbers (test '("~i" 3.0) "3.0+0.0i") (test '("~,3i" 3.0) "3.000+0.000i") @@ -634,7 +634,7 @@ def") (test `("~7,2,,,'*@i" ,(string->number "3.0+5.0i")) "**+3.00**+5.00i") )) ; note: some parsers choke syntactically on reading a complex ; number though format:complex is #f; this is why we put them in - ; strings + ; strings ; inquiry test diff --git a/gambit.init b/gambit.init index 255476f..45dd4e2 100644 --- a/gambit.init +++ b/gambit.init @@ -1,21 +1,7 @@ -;;;"gambit.init" Initialisation for SLIB for Gambit -*-scheme-*- -;;; Copyright (C) 1991, 1992, 1993, 1994, 1997 Aubrey Jaffer -; -;Permission to copy this software, to redistribute it, and to use it -;for any purpose is granted, subject to the following restrictions and -;understandings. -; -;1. Any copy made of this software must include this copyright notice -;in full. -; -;2. I have made no warrantee or representation that the operation of -;this software will be error-free, and I am under no obligation to -;provide any services, by way of maintenance, update, or otherwise. -; -;3. In conjunction with products arising from the use of this -;material, there shall be no use of my name in any advertising, -;promotional, or sales literature without prior written consent in -;each case. +;;;"gambit.init" Initialization for SLIB for Gambit -*-scheme-*- +;;; Author: Aubrey Jaffer +;;; +;;; This code is in the public domain. ;;; Updated 1992 February 1 for Gambit v1.71 -- by Ken Dickey ;;; Date: Wed, 12 Jan 1994 15:03:12 -0500 @@ -23,11 +9,25 @@ ;;; Relative pathnames for Slib in MacGambit ;;; Hacked yet again for Gambit v2.4, Jan 1997, by Mike Pope -(define (software-type) 'UNIX) ; 'MACOS for MacGambit. +(define (software-type) 'MACOS) ; for MacGambit. +(define (software-type) 'UNIX) ; for Unix platforms. (define (scheme-implementation-type) 'gambit) -(define (scheme-implementation-version) "2.4") +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) + "http://www.iro.umontreal.ca/~gambit/index.html") + +(define (scheme-implementation-version) "3.0") +;;; Jefferson R. Lowrey reports that in Gambit Version 3.0 +;;; (argv) returns '(""). +(define argv + (if (equal? '("") (argv)) ;Fix only if it is broken. + (lambda () '("Lowrey HD:Development:MacGambit 3.0:Interpreter")) + argv)) ;;; (implementation-vicinity) should be defined to be the pathname of ;;; the directory where any auxillary files to your Scheme @@ -58,7 +58,7 @@ (let ((library-path (case (software-type) ((UNIX) "/usr/local/lib/slib/") - ((MACOS) (string-append (implementation-vicinity) ":slib:")) + ((MACOS) (string-append (implementation-vicinity) "slib:")) ((AMIGA) "dh0:scm/Library/") ((VMS) "lib$scheme:") ((WINDOWS MS-DOS) "C:\\SLIB\\") diff --git a/glob.scm b/glob.scm index 5f692b7..0029243 100644 --- a/glob.scm +++ b/glob.scm @@ -1,4 +1,4 @@ -;;; glob.scm: String matching for filenames (a la BASH). +;;; "glob.scm" String matching for filenames (a la BASH). ;;; Copyright (C) 1998 Radey Shouman. ; ;Permission to copy this software, to redistribute it, and to use it @@ -17,26 +17,68 @@ ;promotional, or sales literature without prior written consent in ;each case. -;;$Header: /usr/local/cvsroot/slib/glob.scm,v 1.2 1998/09/03 15:34:59 jaffer Exp $ +;;$Header: /usr/local/cvsroot/slib/glob.scm,v 1.15 1999/11/01 01:37:08 jaffer Exp $ ;;$Name: $ -(define (glob:match?? pat) - (glob:make-matcher pat char-ci=? char=?)) -(define (glob:match-ci?? pat) - (glob:make-matcher pat char-ci<=? char<=?)) +(define (glob:pattern->tokens pat) + (cond + ((string? pat) + (let loop ((i 0) + (toks '())) + (if (>= i (string-length pat)) + (reverse toks) + (let ((pch (string-ref pat i))) + (case pch + ((#\? #\*) + (loop (+ i 1) + (cons (substring pat i (+ i 1)) toks))) + ((#\[) + (let ((j + (let search ((j (+ i 2))) + (cond + ((>= j (string-length pat)) + (slib:error 'glob:make-matcher + "unmatched [" pat)) + ((char=? #\] (string-ref pat j)) + (if (and (< (+ j 1) (string-length pat)) + (char=? #\] (string-ref pat (+ j 1)))) + (+ j 1) + j)) + (else (search (+ j 1))))))) + (loop (+ j 1) (cons (substring pat i (+ j 1)) toks)))) + (else + (let search ((j (+ i 1))) + (cond ((= j (string-length pat)) + (loop j (cons (substring pat i j) toks))) + ((memv (string-ref pat j) '(#\? #\* #\[)) + (loop j (cons (substring pat i j) toks))) + (else (search (+ j 1))))))))))) + ((pair? pat) + (for-each (lambda (elt) (or (string? elt) + (slib:error 'glob:pattern->tokens + "bad pattern" pat))) + pat) + pat) + (else (slib:error 'glob:pattern->tokens "bad pattern" pat)))) (define (glob:make-matcher pat ch=? ch<=?) - (define (match-end str k) - (= k (string-length str))) - (define (match-char ch nxt) - (lambda (str k) - (and (< k (string-length str)) - (ch=? ch (string-ref str k)) - (nxt str (+ k 1))))) + (define (match-end str k kmatch) + (and (= k (string-length str)) (reverse (cons k kmatch)))) + (define (match-str pstr nxt) + (let ((plen (string-length pstr))) + (lambda (str k kmatch) + (and (<= (+ k plen) (string-length str)) + (let loop ((i 0)) + (cond ((= i plen) + (nxt str (+ k plen) (cons k kmatch))) + ((ch=? (string-ref pstr i) + (string-ref str (+ k i))) + (loop (+ i 1))) + (else #f))))))) (define (match-? nxt) - (lambda (str k) + (lambda (str k kmatch) (and (< k (string-length str)) - (nxt str (+ k 1))))) + (nxt str (+ k 1) (cons k kmatch))))) (define (match-set1 chrs) (let recur ((i 0)) (cond ((= i (string-length chrs)) @@ -53,67 +95,133 @@ (chrsi (string-ref chrs i))) (lambda (ch) (or (ch=? chrsi ch) (nxt ch)))))))) - (define (match-set chrs nxt) - (if (and (positive? (string-length chrs)) - (memv (string-ref chrs 0) '(#\^ #\!))) - (let ((pred (match-set1 (substring chrs 1 (string-length chrs))))) - (lambda (str k) - (and (< k (string-length str)) - (not (pred (string-ref str k))) - (nxt str (+ k 1))))) - (let ((pred (match-set1 chrs))) - (lambda (str k) - (and (< k (string-length str)) - (pred (string-ref str k)) - (nxt str (+ k 1))))))) + (define (match-set tok nxt) + (let ((chrs (substring tok 1 (- (string-length tok) 1)))) + (if (and (positive? (string-length chrs)) + (memv (string-ref chrs 0) '(#\^ #\!))) + (let ((pred (match-set1 (substring chrs 1 (string-length chrs))))) + (lambda (str k kmatch) + (and (< k (string-length str)) + (not (pred (string-ref str k))) + (nxt str (+ k 1) (cons k kmatch))))) + (let ((pred (match-set1 chrs))) + (lambda (str k kmatch) + (and (< k (string-length str)) + (pred (string-ref str k)) + (nxt str (+ k 1) (cons k kmatch)))))))) (define (match-* nxt) - (lambda (str k) - (let loop ((kk (string-length str))) - (and (>= kk k) - (or (nxt str kk) - (loop (- kk 1))))))) + (lambda (str k kmatch) + (let ((kmatch (cons k kmatch))) + (let loop ((kk (string-length str))) + (and (>= kk k) + (or (nxt str kk kmatch) + (loop (- kk 1)))))))) (let ((matcher - (let recur ((i 0)) - (if (= i (string-length pat)) + (let recur ((toks (glob:pattern->tokens pat))) + (if (null? toks) match-end - (let ((pch (string-ref pat i))) + (let ((pch (or (string=? (car toks) "") + (string-ref (car toks) 0)))) (case pch - ((#\?) - (let ((nxt (recur (+ i 1)))) - (match-? nxt))) - ((#\*) - (let ((nxt (recur (+ i 1)))) - (match-* nxt))) - ((#\[) - (let ((j - (let search ((j (+ i 2))) - (cond - ((>= j (string-length pat)) - (slib:error 'glob:make-matcher - "unmatched [" pat)) - ((char=? #\] (string-ref pat j)) - (if (and (< (+ j 1) (string-length pat)) - (char=? #\] (string-ref pat (+ j 1)))) - (+ j 1) - j)) - (else (search (+ j 1))))))) - (let ((nxt (recur (+ j 1)))) - (match-set (substring pat (+ i 1) j) nxt)))) - (else (let ((nxt (recur (+ i 1)))) - (match-char pch nxt))))))))) - (lambda (str) (matcher str 0)))) + ((#\?) (match-? (recur (cdr toks)))) + ((#\*) (match-* (recur (cdr toks)))) + ((#\[) (match-set (car toks) (recur (cdr toks)))) + (else (match-str (car toks) (recur (cdr toks)))))))))) + (lambda (str) (matcher str 0 '())))) + +(define (glob:caller-with-matches pat proc ch=? ch<=?) + (define (glob:wildcard? pat) + (cond ((string=? pat "") #f) + ((memv (string-ref pat 0) '(#\* #\? #\[)) #t) + (else #f))) + (let* ((toks (glob:pattern->tokens pat)) + (wild? (map glob:wildcard? toks)) + (matcher (glob:make-matcher toks ch=? ch<=?))) + (lambda (str) + (let loop ((inds (matcher str)) + (wild? wild?) + (res '())) + (cond ((not inds) #f) + ((null? wild?) + (apply proc (reverse res))) + ((car wild?) + (loop (cdr inds) + (cdr wild?) + (cons (substring str (car inds) (cadr inds)) res))) + (else + (loop (cdr inds) (cdr wild?) res))))))) + +(define (glob:make-substituter pattern template ch=? ch<=?) + (define (wildcard? pat) + (cond ((string=? pat "") #f) + ((memv (string-ref pat 0) '(#\* #\? #\[)) #t) + (else #f))) + (define (countq val lst) + (do ((lst lst (cdr lst)) + (c 0 (if (eq? val (car lst)) (+ c 1) c))) + ((null? lst) c))) + (let ((tmpl-literals (map (lambda (tok) + (if (wildcard? tok) #f tok)) + (glob:pattern->tokens template))) + (pat-wild? (map wildcard? (glob:pattern->tokens pattern))) + (matcher (glob:make-matcher pattern ch=? ch<=?))) + (or (= (countq #t pat-wild?) (countq #f tmpl-literals)) + (slib:error 'glob:make-substituter + "number of wildcards doesn't match" pattern template)) + (lambda (str) + (let ((indices (matcher str))) + (and indices + (let loop ((inds indices) + (wild? pat-wild?) + (lits tmpl-literals) + (res '())) + (cond + ((null? lits) + (apply string-append (reverse res))) + ((car lits) + (loop inds wild? (cdr lits) (cons (car lits) res))) + ((null? wild?) ;this should never happen. + (loop '() '() lits res)) + ((car wild?) + (loop (cdr inds) (cdr wild?) (cdr lits) + (cons (substring str (car inds) (cadr inds)) + res))) + (else + (loop (cdr inds) (cdr wild?) lits res))))))))) + +(define (glob:match?? pat) + (glob:make-matcher pat char=? char<=?)) +(define (glob:match-ci?? pat) + (glob:make-matcher pat char-ci=? char-ci<=?)) (define filename:match?? glob:match??) (define filename:match-ci?? glob:match-ci??) +(define (glob:substitute?? pat templ) + (cond ((procedure? templ) + (glob:caller-with-matches pat templ char=? char<=?)) + ((string? templ) + (glob:make-substituter pat templ char=? char<=?)) + (else + (slib:error 'glob:substitute "bad second argument" templ)))) +(define (glob:substitute-ci?? pat templ) + (cond ((procedure? templ) + (glob:caller-with-matches pat templ char-ci=? char-ci<=?)) + ((string? templ) + (glob:make-substituter pat templ char-ci=? char-ci<=?)) + (else + (slib:error 'glob:substitute "bad second argument" templ)))) +(define filename:substitute?? glob:substitute??) +(define filename:substitute-ci?? glob:substitute-ci??) + (define (replace-suffix str old new) - (define (cs str) - (let* ((len (string-length str)) - (re (- len (string-length old)))) - (cond ((string-ci=? old (substring str re len)) - (string-append (substring str 0 re) new)) - (else - (slib:error 'replace-suffix "suffix doesn't match:" - old str))))) - (if (string? str) (cs str) (map cs str))) + (let* ((f (glob:make-substituter (list "*" old) (list "*" new) + char=? char<=?)) + (g (lambda (st) + (or (f st) + (slib:error 'replace-suffix "suffix doesn't match:" + old st))))) + (if (pair? str) + (map g str) + (g str)))) diff --git a/htmlform.scm b/htmlform.scm index f8656e2..c7ce1dc 100644 --- a/htmlform.scm +++ b/htmlform.scm @@ -1,5 +1,4 @@ -;;; "htmlform.scm" Generate HTML 2.0 forms and -*-scheme-*- -;;; service CGI requests from RDB command table. +;;; "htmlform.scm" Generate HTML 2.0 forms; service CGI requests. -*-scheme-*- ; Copyright 1997, 1998 Aubrey Jaffer ; ;Permission to copy this software, to redistribute it, and to use it @@ -25,6 +24,8 @@ (require 'parameters) (require 'fluid-let) (require 'dynamic-wind) +(require 'pretty-print) +(require 'object->string) (require 'string-case) (require 'string-port) (require 'string-search) @@ -41,71 +42,267 @@ ;;@body Returns a string with character substitutions appropriate to ;;send @1 as an @dfn{attribute-value}. -(define (html:atval txt) ; attribute-value +(define (make-atval txt) ; attribute-value (if (symbol? txt) (set! txt (symbol->string txt))) - (string-subst txt - "&" "&" - "\"" """ - "<" "<" - ">" ">")) + (if (number? txt) + (number->string txt) + (string-subst (if (string? txt) txt (object->string txt)) + "&" "&" + "\"" """ + "<" "<" + ">" ">"))) ;;@body Returns a string with character substitutions appropriate to ;;send @1 as an @dfn{plain-text}. -(define (html:plain txt) ; plain-text `Data Characters' +(define (make-plain txt) ; plain-text `Data Characters' (if (symbol? txt) (set! txt (symbol->string txt))) - (string-subst txt - "&" "&" - "<" "<" - ">" ">")) + (if (number? txt) + (number->string txt) + (string-subst (if (string? txt) txt (object->string txt)) + "&" "&" + "<" "<" + ">" ">"))) + +;;@args title backlink tags ... +;;@args title backlink +;;@args title +;; +;;Outputs headers for an HTML page named @1. If string arguments @2 +;;... are supplied they are printed verbatim within the @t{} +;;section. +(define (html:start-page title . args) + (define backlink (if (null? args) #f (car args))) + (if (not (null? args)) (set! args (cdr args))) + (html:printf "\\n") + (html:printf "\\n") + (html:comment "HTML by SLIB" + "http://swissnet.ai.mit.edu/~jaffer/SLIB.html") + (html:printf "%s%s\\n" + (apply string-append args) (make-plain title)) + (html:printf "

%s

\\n" + (or backlink (make-plain title)))) + +;;@body Outputs HTML codes to end a page. +(define (html:end-page) + (html:printf "\\n") + (html:printf "\\n")) + +;;@body Writes (using @code{html:printf}) the strings @1, @2 as +;;@dfn{PRE}formmated plain text (rendered in fixed-width font). +;;Newlines are inserted between @1, @2. HTML tags (@samp{}) +;;within @2 will be visible verbatim. +(define (html:pre line1 . lines) + (html:printf "
\\n%s" (make-plain line1))
+  (for-each (lambda (line) (html:printf "\\n%s" (make-plain line))) lines)
+  (html:printf "
\\n")) ;;@body Writes (using @code{html:printf}) the strings @1 as HTML ;;comments. -(define (html:comment . lines) +(define (html:comment line1 . lines) (html:printf "\\n")) +;;@section HTML Tables + +;;@body +(define (html:start-table caption) + (html:printf "\\n") + (html:printf "\\n" (make-plain caption))) + +;;@body +(define (html:end-table) + (html:printf "
%s
\\n")) + +;;@body Outputs a heading row for the currently-started table. +(define (html:heading columns) + (html:printf "\\n") + (for-each (lambda (datum) (html:printf "%s\\n" (or datum ""))) columns)) + +;;@body Outputs a heading row with column-names @1 linked to URLs @2. +(define (html:href-heading columns urls) + (html:heading + (map (lambda (column url) + (if url + (sprintf #f "%s" url column) + column)) + columns urls))) + +;;@args k foreigns +;; +;;The positive integer @1 is the primary-key-limit (number of +;;primary-keys) of the table. @2 is a list of the filenames of +;;foreign-key field pages and #f for non foreign-key fields. +;; +;;@0 returns a procedure taking a row for its single argument. This +;;returned procedure prints the table row to @var{*html:output-port*}. +(define (make-row-converter pkl foreigns) + (lambda (data-row) + (define anchored? #f) + (define (present datum) + (cond ((or (string? datum) (symbol? datum)) + (html:printf "%s" (make-plain datum))) + (else + (html:printf + "
\\n%s
\\n" + (make-plain (call-with-output-string + (lambda (port) + (pretty-print datum port)))))))) + (html:printf "") + (for-each (lambda (datum foreign) + (html:printf "") + (cond ((not datum)) + ((null? datum)) + ((not anchored?) + (html:printf "= idx pkl)) + (html:printf + " %s" (make-atval (car contents)))))) + (html:printf "\">") + (set! anchored? (not (zero? pkl))))) + (cond ((not datum)) ((null? datum)) + ((not foreign) (present datum)) + ((zero? pkl) + (html:printf "" foreign) + (present datum) + (html:printf "")) + (else + (html:printf "" + foreign (make-atval datum)) + (present datum) + (html:printf "")))) + data-row foreigns) + (html:printf "\\n"))) + +;;@body +;;Returns the symbol @1 converted to a filename. +(define (table-name->filename table-name) + (and table-name (string-append + (string-subst (symbol->string table-name) "*" "" ":" "_") + ".html"))) + +(define (table-name->column-table-name db table-name) + ((((db 'open-table) '*catalog-data* #f) 'get 'coltab-name) + table-name)) + +;;@args caption db table-name match-key1 @dots{} +;;Writes HTML for @2 table @3 to @var{*html:output-port*}. +;; +;;The optional @4 @dots{} arguments restrict actions to a subset of +;;the table. @xref{Table Operations, match-key}. +(define (table->html caption db table-name . args) + (let* ((table ((db 'open-table) table-name #f)) + (foreigns (table 'column-foreigns)) + (tags (map table-name->filename foreigns)) + (names (table 'column-names)) + (primlim (table 'primary-limit))) + (html:start-table caption) + (html:href-heading + names + (append (make-list primlim (table-name->filename + (table-name->column-table-name db table-name))) + (make-list (- (length names) primlim) #f))) + (html:heading (table 'column-domains)) + (html:href-heading foreigns tags) + (html:heading (table 'column-types)) + (apply (table 'for-each-row) (make-row-converter primlim tags) args) + (html:end-table))) + +;;@body +;;Writes a complete HTML page to @var{*html:output-port*}. The string +;;@3 names the page which refers to this one. +(define (table->page db table-name index-filename) + (dynamic-wind + (lambda () + (if index-filename + (html:start-page + table-name + (sprintf #f "%s" + index-filename + (make-atval table-name) + (make-plain table-name))) + (html:start-page table-name))) + (lambda () (table->html table-name db table-name)) + html:end-page)) + +;;@body +;;Writes HTML for the catalog table of @1 to @var{*html:output-port*}. +(define (catalog->html db caption) + (html:start-table caption) + (html:heading '(table columns)) + ((((db 'open-table) '*catalog-data* #f) 'for-each-row) + (lambda (row) + (cond ((and (eq? '*columns* (caddr row)) + (not (eq? '*columns* (car row))))) + (else ((make-row-converter + 0 (list (table-name->filename (car row)) + (table-name->filename (caddr row)))) + (list (car row) (caddr row)))))))) + +;;@body +;;Writes a complete HTML page for the catalog of @1 to +;;@var{*html:output-port*}. +(define (catalog->page db caption) + (dynamic-wind + (lambda () (html:start-page caption)) + (lambda () + (catalog->html db caption) + (html:end-table)) + html:end-page)) + +;;@section HTML Forms + (define (html:dt-strong-doc name doc) (if (and (string? doc) (not (equal? "" doc))) (html:printf "
%s (%s)\\n" - (html:plain name) (html:plain doc)) - (html:printf "
%s\\n" (html:plain name)))) + (make-plain name) (make-plain doc)) + (html:printf "
%s\\n" (make-plain name)))) (define (html:checkbox name doc pname) (html:printf "
\\n" - (html:atval pname)) + (make-atval pname)) (if (and (string? doc) (not (equal? "" doc))) (html:printf "
%s (%s)\\n" - (html:plain name) (html:plain doc)) - (html:printf "
%s\\n" (html:plain name)))) + (make-plain name) (make-plain doc)) + (html:printf "
%s\\n" (make-plain name)))) (define (html:text name doc pname default) (cond (default (html:dt-strong-doc name doc) (html:printf "
\\n" - (html:atval pname) + (make-atval pname) (max 20 (string-length (if (symbol? default) (symbol->string default) default))) - (html:atval default))) + (make-atval default))) (else (html:dt-strong-doc name doc) - (html:printf "
\\n" (html:atval pname))))) + (html:printf "
\\n" (make-atval pname))))) (define (html:text-area name doc pname default-list) (html:dt-strong-doc name doc) (html:printf "
\\n")) (define (html:s %s\\n" - (html:atval pname) (html:atval value) + (make-atval pname) (make-atval value) (if (member value default-list) " CHECKED" "") - (html:plain value))) + (make-plain value))) value-list)) ((nary nary1) (for-each (lambda (value) (html:printf "
  • %s\\n" - (html:atval pname) (html:atval value) + (make-atval pname) (make-atval value) (if (member value default-list) " CHECKED" "") - (html:plain value))) + (make-plain value))) value-list))) (html:printf "")) @@ -166,7 +363,7 @@ (cond ((not (memq method '(get head post put delete))) (slib:error 'html:start-form "method unknown:" method))) (html:printf "
    \\n" - (html:atval method) (html:atval action)) + (make-atval method) (make-atval action)) (html:printf "
    \\n")) ;;@body @0 prints the footer for an HTML @dfn{form}. The string @2 @@ -174,20 +371,9 @@ (define (html:end-form pname submit-label) (html:printf "
    \\n") (html:printf " \\n" - (html:atval '*command*) (html:atval submit-label)) + (make-atval '*command*) (make-atval submit-label)) (html:printf "

    \\n")) -;;@body Outputs headers for an HTML page named @1. -(define (html:start-page title) - (html:printf "\\n") - (html:comment) - (html:printf "%s\\n" (html:plain title)) - (html:printf "

    %s

    \\n" (html:plain title))) - -;;@body Outputs HTML codes to end a page. -(define (html:end-page) - (html:printf "\\n")) - (define (html:generate-form comname method action docu pnames docs aliases arities types default-lists value-lists) (define aliast (map list pnames)) @@ -198,7 +384,7 @@ (dynamic-wind (lambda () (html:printf "

    %s:

    %s
    \\n" - (html:plain comname) (html:plain docu)) + (make-plain comname) (make-plain docu)) (html:start-form 'post action)) (lambda () (for-each diff --git a/lineio.scm b/lineio.scm index ad8320b..c80ece8 100644 --- a/lineio.scm +++ b/lineio.scm @@ -17,34 +17,66 @@ ;promotional, or sales literature without prior written consent in ;each case. -(define (read-line . arg) - (let* ((char (apply read-char arg))) + +;;@args +;;@args port +;;Returns a string of the characters up to, but not including a +;;newline or end of file, updating @var{port} to point to the +;;character following the newline. If no characters are available, an +;;end of file object is returned. The @var{port} argument may be +;;omitted, in which case it defaults to the value returned by +;;@code{current-input-port}. +(define (read-line . port) + (let* ((char (apply read-char port))) (if (eof-object? char) char - (do ((char char (apply read-char arg)) + (do ((char char (apply read-char port)) (clist '() (cons char clist))) ((or (eof-object? char) (char=? #\newline char)) (list->string (reverse clist))))))) -(define (read-line! str . arg) - (let* ((char (apply read-char arg)) - (len (+ -1 (string-length str)))) +;;@args string +;;@args string port +;;Fills @1 with characters up to, but not including a newline or end +;;of file, updating the @var{port} to point to the last character read +;;or following the newline if it was read. If no characters are +;;available, an end of file object is returned. If a newline or end +;;of file was found, the number of characters read is returned. +;;Otherwise, @code{#f} is returned. The @var{port} argument may be +;;omitted, in which case it defaults to the value returned by +;;@code{current-input-port}. +(define (read-line! str . port) + (let* ((char (apply read-char port)) + (midx (+ -1 (string-length str)))) (if (eof-object? char) char - (do ((char char (apply read-char arg)) + (do ((char char (apply read-char port)) (i 0 (+ 1 i))) ((or (eof-object? char) (char=? #\newline char) - (>= i len)) - (cond ((or (eof-object? char) (char=? #\newline char)) - i) - (else - (string-set! str i char) - (set! char (apply peek-char arg)) - (if (or (eof-object? char) (char=? #\newline char)) - (+ 1 i) #f)))) + (> i midx)) + (if (> i midx) #f i)) (string-set! str i char))))) -(define (write-line str . arg) - (apply display str arg) - (apply newline arg)) +;;@args string +;;@args string port +;;Writes @1 followed by a newline to the given @var{port} and returns +;;an unspecified value. The @var{Port} argument may be omited, in +;;which case it defaults to the value returned by +;;@code{current-input-port}.@refill +(define (write-line str . port) + (apply display str port) + (apply newline port)) + +;;@args path +;;@args path port +;;Displays the contents of the file named by @1 to @var{port}. The +;;@var{port} argument may be ommited, in which case it defaults to the +;;value returned by @code{current-output-port}. +(define (display-file path . port) + (set! port (if (null? port) (current-output-port) (car port))) + (call-with-input-file path + (lambda (inport) + (do ((line (read-line inport) (read-line inport))) + ((eof-object? line)) + (write-line line port))))) diff --git a/macscheme.init b/macscheme.init index 58927ee..16c53bb 100644 --- a/macscheme.init +++ b/macscheme.init @@ -1,21 +1,7 @@ ;;;"macscheme.init" Configuration of *features* for MacScheme -*-scheme-*- -;Copyright (C) 1994, 1997 Aubrey Jaffer -; -;Permission to copy this software, to redistribute it, and to use it -;for any purpose is granted, subject to the following restrictions and -;understandings. -; -;1. Any copy made of this software must include this copyright notice -;in full. -; -;2. I have made no warrantee or representation that the operation of -;this software will be error-free, and I am under no obligation to -;provide any services, by way of maintenance, update, or otherwise. -; -;3. In conjunction with products arising from the use of this -;material, there shall be no use of my name in any advertising, -;promotional, or sales literature without prior written consent in -;each case. +;;; Author: Aubrey Jaffer +;;; +;;; This code is in the public domain. ;;; From: jjb@isye.gatech.edu (John Bartholdi) @@ -29,6 +15,12 @@ (define (scheme-implementation-type) 'MacScheme) +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) #f) + ;;; (scheme-implementation-version) should return a string describing ;;; the version the scheme implementation loading this file. diff --git a/mbe.scm b/mbe.scm index d39a2f7..df88857 100644 --- a/mbe.scm +++ b/mbe.scm @@ -1,5 +1,5 @@ ;;;; "mbe.scm" "Macro by Example" (Eugene Kohlbecker, R4RS) -;;; From: Dorai Sitaram, dorai@cs.rice.edu, 1991, 1997 +;;; From: Dorai Sitaram, dorai@cs.rice.edu, 1991, 1999 ; ;Permission to copy this software, to redistribute it, and to use it ;for any purpose is granted, subject to the following restrictions and @@ -20,6 +20,7 @@ ;;; revised Dec. 6, 1993 to R4RS syntax (if not semantics). ;;; revised Mar. 2 1994 for SLIB (jaffer@ai.mit.edu). ;;; corrections, Apr. 24, 1997. +;;; corr., Jan. 30, 1999. (mflatt@cs.rice.edu, dorai@cs.rice.edu) ;;; A vanilla implementation of hygienic macro-by-example as described ;;; by Eugene Kohlbecker and in R4RS Appendix. This file requires @@ -34,29 +35,29 @@ (lambda (k al) (let loop ((al al)) (if (null? al) #f - (let ((c (car al))) - (if (eq? (cdr c) k) c - (loop (cdr al)))))))) + (let ((c (car al))) + (if (eq? (cdr c) k) c + (loop (cdr al)))))))) (define hyg:tag (lambda (e kk al) (cond ((pair? e) - (let* ((a-te-al (hyg:tag (car e) kk al)) - (d-te-al (hyg:tag (cdr e) kk (cdr a-te-al)))) - (cons (cons (car a-te-al) (car d-te-al)) - (cdr d-te-al)))) + (let* ((a-te-al (hyg:tag (car e) kk al)) + (d-te-al (hyg:tag (cdr e) kk (cdr a-te-al)))) + (cons (cons (car a-te-al) (car d-te-al)) + (cdr d-te-al)))) ((vector? e) - (list->vector - (hyg:tag (vector->list e) kk al))) + (list->vector + (hyg:tag (vector->list e) kk al))) ((symbol? e) - (cond ((eq? e '...) (cons '... al)) - ((memq e kk) (cons e al)) - ((hyg:rassq e al) => - (lambda (c) - (cons (car c) al))) - (else - (let ((te (gentemp))) - (cons te (cons (cons te e) al)))))) + (cond ((eq? e '...) (cons '... al)) + ((memq e kk) (cons e al)) + ((hyg:rassq e al) => + (lambda (c) + (cons (car c) al))) + (else + (let ((te (gentemp))) + (cons te (cons (cons te e) al)))))) (else (cons e al))))) ;;untagging @@ -65,140 +66,184 @@ (lambda (e al tmps) (if (pair? e) (let ((a (hyg:untag (car e) al tmps))) - (if (list? e) - (case a - ((quote) (hyg:untag-no-tags e al)) - ((if begin) - `(,a ,@(map (lambda (e1) - (hyg:untag e1 al tmps)) (cdr e)))) - ((set! define) - `(,a ,(hyg:untag-vanilla (cadr e) al tmps) - ,@(map (lambda (e1) - (hyg:untag e1 al tmps)) (cddr e)))) - ((lambda) (hyg:untag-lambda (cadr e) (cddr e) al tmps)) - ((letrec) (hyg:untag-letrec (cadr e) (cddr e) al tmps)) - ((let) - (let ((e2 (cadr e))) - (if (symbol? e2) - (hyg:untag-named-let e2 (caddr e) (cdddr e) al tmps) - (hyg:untag-let e2 (cddr e) al tmps)))) - ((let*) (hyg:untag-let* (cadr e) (cddr e) al tmps)) - ((do) (hyg:untag-do (cadr e) (caddr e) (cdddr e) al tmps)) - ((case) - `(case ,(hyg:untag-vanilla (cadr e) al tmps) - ,@(map - (lambda (c) - `(,(hyg:untag-vanilla (car c) al tmps) - ,@(hyg:untag-list (cdr c) al tmps))) - (cddr e)))) - ((cond) - `(cond ,@(map - (lambda (c) - (hyg:untag-list c al tmps)) - (cdr e)))) - (else (cons a (hyg:untag-list (cdr e) al tmps)))) - (cons a (hyg:untag-list* (cdr e) al tmps)))) + (if (list? e) + (case a + ((quote) (hyg:untag-no-tags e al)) + ((quasiquote) (list a (hyg:untag-quasiquote (cadr e) al tmps))) + ((if begin) + `(,a ,@(map (lambda (e1) + (hyg:untag e1 al tmps)) (cdr e)))) + ((set! define) + `(,a ,(hyg:untag-vanilla (cadr e) al tmps) + ,@(map (lambda (e1) + (hyg:untag e1 al tmps)) (cddr e)))) + ((lambda) (hyg:untag-lambda (cadr e) (cddr e) al tmps)) + ((letrec) (hyg:untag-letrec (cadr e) (cddr e) al tmps)) + ((let) + (let ((e2 (cadr e))) + (if (symbol? e2) + (hyg:untag-named-let e2 (caddr e) (cdddr e) al tmps) + (hyg:untag-let e2 (cddr e) al tmps)))) + ((let*) (hyg:untag-let* (cadr e) (cddr e) al tmps)) + ((do) (hyg:untag-do (cadr e) (caddr e) (cdddr e) al tmps)) + ((case) + `(case ,(hyg:untag-vanilla (cadr e) al tmps) + ,@(map + (lambda (c) + `(,(hyg:untag-vanilla (car c) al tmps) + ,@(hyg:untag-list (cdr c) al tmps))) + (cddr e)))) + ((cond) + `(cond ,@(map + (lambda (c) + (hyg:untag-list c al tmps)) + (cdr e)))) + (else (cons a (hyg:untag-list (cdr e) al tmps)))) + (cons a (hyg:untag-list* (cdr e) al tmps)))) (hyg:untag-vanilla e al tmps)))) (define hyg:untag-list (lambda (ee al tmps) (map (lambda (e) - (hyg:untag e al tmps)) ee))) + (hyg:untag e al tmps)) ee))) (define hyg:untag-list* (lambda (ee al tmps) (let loop ((ee ee)) (if (pair? ee) - (cons (hyg:untag (car ee) al tmps) - (loop (cdr ee))) - (hyg:untag ee al tmps))))) + (cons (hyg:untag (car ee) al tmps) + (loop (cdr ee))) + (hyg:untag ee al tmps))))) (define hyg:untag-no-tags (lambda (e al) (cond ((pair? e) - (cons (hyg:untag-no-tags (car e) al) - (hyg:untag-no-tags (cdr e) al))) + (cons (hyg:untag-no-tags (car e) al) + (hyg:untag-no-tags (cdr e) al))) ((vector? e) - (list->vector - (hyg:untag-no-tags (vector->list e) al))) + (list->vector + (hyg:untag-no-tags (vector->list e) al))) ((not (symbol? e)) e) ((assq e al) => cdr) (else e)))) +(define hyg:untag-quasiquote + (lambda (form al tmps) + (let qq ((x form) (level 0)) + (cond + ((pair? x) + (let ((first (qq (car x) level))) + (cond + ((and (eq? first 'unquote) (list? x)) + (let ((rest (cdr x))) + (if (or (not (pair? rest)) + (not (null? (cdr rest)))) + (slib:error 'unquote 'takes-exactly-one-expression) + (if (zero? level) + (list 'unquote (hyg:untag (car rest) al tmps)) + (cons first (qq rest (sub1 level))))))) + ((and (eq? first 'quasiquote) (list? x)) + (cons 'quasiquote (qq (cdr x) (add1 level)))) + ((and (eq? first 'unquote-splicing) (list? x)) + (slib:error 'unquote-splicing 'invalid-context-within-quasiquote)) + ((pair? first) + (let ((car-first (qq (car first) level))) + (if (and (eq? car-first 'unquote-splicing) + (list? first)) + (let ((rest (cdr first))) + (if (or (not (pair? rest)) + (not (null? (cdr rest)))) + (slib:error 'unquote-splicing + 'takes-exactly-one-expression) + (list (list 'unquote-splicing + (if (zero? level) + (hyg:untag (cadr rest) al tmps) + (qq (cadr rest) (sub1 level))) + (qq (cdr x) level))))) + (cons (cons car-first + (qq (cdr first) level)) + (qq (cdr x) level))))) + (else + (cons first (qq (cdr x) level)))))) + ((vector? x) + (list->vector + (qq (vector->list x) level))) + (else (hyg:untag-no-tags x al)))))) + (define hyg:untag-lambda (lambda (bvv body al tmps) (let ((tmps2 (nconc (hyg:flatten bvv) tmps))) `(lambda ,bvv - ,@(hyg:untag-list body al tmps2))))) + ,@(hyg:untag-list body al tmps2))))) (define hyg:untag-letrec (lambda (varvals body al tmps) (let ((tmps (nconc (map car varvals) tmps))) `(letrec - ,(map - (lambda (varval) - `(,(car varval) - ,(hyg:untag (cadr varval) al tmps))) - varvals) - ,@(hyg:untag-list body al tmps))))) + ,(map + (lambda (varval) + `(,(car varval) + ,(hyg:untag (cadr varval) al tmps))) + varvals) + ,@(hyg:untag-list body al tmps))))) (define hyg:untag-let (lambda (varvals body al tmps) (let ((tmps2 (nconc (map car varvals) tmps))) `(let - ,(map - (lambda (varval) - `(,(car varval) - ,(hyg:untag (cadr varval) al tmps))) - varvals) - ,@(hyg:untag-list body al tmps2))))) + ,(map + (lambda (varval) + `(,(car varval) + ,(hyg:untag (cadr varval) al tmps))) + varvals) + ,@(hyg:untag-list body al tmps2))))) (define hyg:untag-named-let (lambda (lname varvals body al tmps) (let ((tmps2 (cons lname (nconc (map car varvals) tmps)))) `(let ,lname - ,(map - (lambda (varval) - `(,(car varval) - ,(hyg:untag (cadr varval) al tmps))) - varvals) - ,@(hyg:untag-list body al tmps2))))) + ,(map + (lambda (varval) + `(,(car varval) + ,(hyg:untag (cadr varval) al tmps))) + varvals) + ,@(hyg:untag-list body al tmps2))))) (define hyg:untag-let* (lambda (varvals body al tmps) (let ((tmps2 (nconc (nreverse (map car varvals)) tmps))) `(let* - ,(let loop ((varvals varvals) - (i (length varvals))) - (if (null? varvals) '() - (let ((varval (car varvals))) - (cons `(,(car varval) - ,(hyg:untag (cadr varval) - al (list-tail tmps2 i))) - (loop (cdr varvals) (- i 1)))))) - ,@(hyg:untag-list body al tmps2))))) + ,(let loop ((varvals varvals) + (i (length varvals))) + (if (null? varvals) '() + (let ((varval (car varvals))) + (cons `(,(car varval) + ,(hyg:untag (cadr varval) + al (list-tail tmps2 i))) + (loop (cdr varvals) (- i 1)))))) + ,@(hyg:untag-list body al tmps2))))) (define hyg:untag-do (lambda (varinistps exit-test body al tmps) (let ((tmps2 (nconc (map car varinistps) tmps))) `(do - ,(map - (lambda (varinistp) - (let ((var (car varinistp))) - `(,var ,@(hyg:untag-list (cdr varinistp) al - (cons var tmps))))) - varinistps) - ,(hyg:untag-list exit-test al tmps2) - ,@(hyg:untag-list body al tmps2))))) + ,(map + (lambda (varinistp) + (let ((var (car varinistp))) + `(,var ,@(hyg:untag-list (cdr varinistp) al + (cons var tmps))))) + varinistps) + ,(hyg:untag-list exit-test al tmps2) + ,@(hyg:untag-list body al tmps2))))) (define hyg:untag-vanilla (lambda (e al tmps) (cond ((pair? e) - (cons (hyg:untag-vanilla (car e) al tmps) - (hyg:untag-vanilla (cdr e) al tmps))) + (cons (hyg:untag-vanilla (car e) al tmps) + (hyg:untag-vanilla (cdr e) al tmps))) ((vector? e) - (list->vector - (hyg:untag-vanilla (vector->list e) al tmps))) + (list->vector + (hyg:untag-vanilla (vector->list e) al tmps))) ((not (symbol? e)) e) ((memq e tmps) e) ((assq e al) => cdr) @@ -214,6 +259,7 @@ ;;;; End of hygiene filter. + ;;; finds the leftmost index of list l where something equal to x ;;; occurs (define mbe:position @@ -223,6 +269,14 @@ ((equal? (car l) x) i) (else (loop (cdr l) (+ i 1))))))) +;;; (mbe:append-map f l) == (apply append (map f l)) + +(define mbe:append-map + (lambda (f l) + (let loop ((l l)) + (if (null? l) '() + (append (f (car l)) (loop (cdr l))))))) + ;;; tests if expression e matches pattern p where k is the list of ;;; keywords (define mbe:matches-pattern? @@ -301,11 +355,26 @@ ;;; finds the subenvironments in r corresponding to the ellipsed ;;; variables in nestings + (define mbe:ellipsis-sub-envs (lambda (nestings r) - (some (lambda (c) - (if (mbe:contained-in? nestings (car c)) (cdr c) #f)) - r))) + (let ((sub-envs-list + (let loop ((r r) (sub-envs-list '())) + (if (null? r) (nreverse sub-envs-list) + (let ((c (car r))) + (loop (cdr r) + (if (mbe:contained-in? nestings (car c)) + (cons (cdr c) sub-envs-list) + sub-envs-list))))))) + (case (length sub-envs-list) + ((0) #f) + ((1) (car sub-envs-list)) + (else + (let loop ((sub-envs-list sub-envs-list) (final-sub-envs '())) + (if (some null? sub-envs-list) (nreverse final-sub-envs) + (loop (map cdr sub-envs-list) + (cons (mbe:append-map car sub-envs-list) + final-sub-envs))))))))) ;;; checks if nestings v and y have an intersection (define mbe:contained-in? @@ -337,36 +406,36 @@ (defmacro define-syntax (macro-name syn-rules) (if (or (not (pair? syn-rules)) - (not (eq? (car syn-rules) 'syntax-rules))) + (not (eq? (car syn-rules) 'syntax-rules))) (slib:error 'define-syntax 'not-an-r4rs-high-level-macro macro-name syn-rules) (let ((keywords (cons macro-name (cadr syn-rules))) - (clauses (cddr syn-rules))) + (clauses (cddr syn-rules))) `(defmacro ,macro-name macro-arg - (let ((macro-arg (cons ',macro-name macro-arg)) - (keywords ',keywords)) - (cond ,@(map - (lambda (clause) - (let ((in-pattern (car clause)) + (let ((macro-arg (cons ',macro-name macro-arg)) + (keywords ',keywords)) + (cond ,@(map + (lambda (clause) + (let ((in-pattern (car clause)) (out-pattern (cadr clause))) - `((mbe:matches-pattern? ',in-pattern macro-arg - keywords) - (let ((tagged-out-pattern+alist - (hyg:tag - ',out-pattern - (nconc (hyg:flatten ',in-pattern) - keywords) '()))) - (hyg:untag - (mbe:expand-pattern - (car tagged-out-pattern+alist) - (mbe:get-bindings ',in-pattern macro-arg - keywords) - keywords) - (cdr tagged-out-pattern+alist) - '()))))) - clauses) - (else (slib:error ',macro-name 'no-matching-clause - ',clauses)))))))) + `((mbe:matches-pattern? ',in-pattern macro-arg + keywords) + (let ((tagged-out-pattern+alist + (hyg:tag + ',out-pattern + (nconc (hyg:flatten ',in-pattern) + keywords) '()))) + (hyg:untag + (mbe:expand-pattern + (car tagged-out-pattern+alist) + (mbe:get-bindings ',in-pattern macro-arg + keywords) + keywords) + (cdr tagged-out-pattern+alist) + '()))))) + clauses) + (else (slib:error ',macro-name 'no-matching-clause + ',clauses)))))))) (define macro:eval slib:eval) (define macro:load slib:load) diff --git a/mitscheme.init b/mitscheme.init index bd612b0..ab1e1b7 100644 --- a/mitscheme.init +++ b/mitscheme.init @@ -1,21 +1,7 @@ ;;;"mitscheme.init" Initialization for SLIB for MITScheme -*-scheme-*- -;;; Copyright (C) 1991, 1992, 1993, 1994, 1997 Aubrey Jaffer. -; -;Permission to copy this software, to redistribute it, and to use it -;for any purpose is granted, subject to the following restrictions and -;understandings. -; -;1. Any copy made of this software must include this copyright notice -;in full. -; -;2. I have made no warrantee or representation that the operation of -;this software will be error-free, and I am under no obligation to -;provide any services, by way of maintenance, update, or otherwise. -; -;3. In conjunction with products arising from the use of this -;material, there shall be no use of my name in any advertising, -;promotional, or sales literature without prior written consent in -;each case. +;;; Author: Aubrey Jaffer +;;; +;;; This code is in the public domain. ;;; Make this part of your ~/.scheme.init file. @@ -29,6 +15,13 @@ (define (scheme-implementation-type) 'MITScheme) +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) + "http://swissnet.ai.mit.edu/scheme-home.html") + ;;; (scheme-implementation-version) should return a string describing ;;; the version the scheme implementation loading this file. @@ -161,9 +154,12 @@ (lambda () (proc port)))))))) (define object->string write-to-string) +(define object->limited-string write-to-string) ;;; CHAR-CODE-LIMIT is one greater than the largest integer which can -;;; be returned by CHAR->INTEGER. It is defined by MITScheme. +;;; be returned by CHAR->INTEGER. It is defined incorrectly (65536) +;;; by MITScheme version 8.0. +(define char-code-limit 256) ;;; MOST-POSITIVE-FIXNUM is used in modular.scm (define most-positive-fixnum #x03FFFFFF) diff --git a/mklibcat.scm b/mklibcat.scm index dbc26d9..d6bd380 100644 --- a/mklibcat.scm +++ b/mklibcat.scm @@ -42,7 +42,7 @@ (cons (car p) (if (pair? (cdr p)) - (cons + (cons (cadr p) (in-vicinity (library-vicinity) (cddr p))) (in-vicinity (library-vicinity) (cdr p)))))) @@ -56,7 +56,7 @@ (with-file . "withfile") (dynamic-wind . "dynwind") (dynamic . "dynamic") - (fluid-let macro . "fluidlet") + (fluid-let defmacro . "fluidlet") (alist . "alist") (hash . "hash") (sierpinski . "sierpinski") @@ -66,8 +66,8 @@ (random . "random") (random-inexact . "randinex") (modular . "modular") - (primes . "primes") (factor . "factor") + (primes . factor) (charplot . "charplot") (sort . "sort") (tsort . topological-sort) @@ -100,7 +100,8 @@ (syntactic-closures . "scmacro") (macros-that-work . "macwork") (macro . macro-by-example) - (yasos macro . "yasos") + (object . "object") + (yasos macro . "yasyn") (oop . yasos) (collect macro . "collect") (struct defmacro . "struct") @@ -128,6 +129,7 @@ (glob . "glob") (filename . glob) (make-crc . "makcrc") + (fft . "fft") (wt-tree . "wttree") (string-search . "strsrch") (root . "root") @@ -139,6 +141,7 @@ (byte . "byte") (tzfile . "tzfile") (schmooz . "schmooz") + (net-clients . "nclients") (new-catalog . "mklibcat") )))) (display " " op) diff --git a/mwexpand.scm b/mwexpand.scm index a53f0da..9dea34b 100644 --- a/mwexpand.scm +++ b/mwexpand.scm @@ -38,8 +38,8 @@ (mw:desugar-definitions def-or-exp mw:global-syntax-environment)))) (define (mw:desugar-definitions exp env) - (letrec - ((define-loop + (letrec + ((define-loop (lambda (exp rest first) (cond ((and (pair? exp) (eq? (mw:syntax-lookup env (car exp)) @@ -70,10 +70,10 @@ (append (reverse first) (map (lambda (exp) (mw:expand exp env)) (cons exp rest)))))))) - + (desugar-define (lambda (exp env) - (cond + (cond ((null? (cdr exp)) (mw:error "Malformed definition" exp)) ; (define foo) syntax is transformed into (define foo (undefined)). ((null? (cddr exp)) @@ -93,8 +93,8 @@ (redefinition id) (mw:syntax-bind-globally! id (mw:make-identifier-denotation id)) `(,mw:define1 ,id ,(mw:expand (caddr exp) env))))))) - - (define-syntax-loop + + (define-syntax-loop (lambda (exp rest) (cond ((and (pair? exp) (eq? (mw:syntax-lookup env (car exp)) @@ -115,7 +115,7 @@ (else (cons mw:begin1 (map (lambda (exp) (mw:expand exp env)) (cons exp rest))))))) - + (redefinition (lambda (id) (if (symbol? id) @@ -123,9 +123,9 @@ (mw:syntax-lookup mw:global-syntax-environment id))) (mw:warn "Redefining keyword" id)) (mw:error "Malformed variable or keyword" id))))) - + ; body of letrec - + (define-loop exp '() '()))) ; Given an expression and a syntactic environment, @@ -157,7 +157,7 @@ ((or (eq? keyword mw:denote-of-define) (eq? keyword mw:denote-of-define-syntax)) ;; slight hack to allow expansion into defines -KenD - (if mw:in-define? + (if mw:in-define? (mw:error "Definition out of context" exp) (begin (set! mw:in-define? #t) @@ -378,10 +378,10 @@ ; Clean up alist hacking et cetera. ;;----------------------------------------------------------------- -;; The following was added to allow expansion without flattening -;; LETs to LAMBDAs so that the origianl structure of the program -;; is preserved by macro expansion. I.e. so that usual.scm is not -;; required. -- added KenD +;; The following was added to allow expansion without flattening +;; LETs to LAMBDAs so that the origianl structure of the program +;; is preserved by macro expansion. I.e. so that usual.scm is not +;; required. -- added KenD (define (mw:process-let-bindings alist binding-list env) ;; helper proc (map (lambda (bind) @@ -414,7 +414,7 @@ ; LET (define (mw:let exp env) (let* ( (name (if (or (pair? (cadr exp)) (null? (cadr exp))) - #f + #f (cadr exp))) ; named let? (binds (if name (caddr exp) (cadr exp))) (body (if name (cdddr exp) (cddr exp))) @@ -460,12 +460,12 @@ (if (null? bindings) `(let* ,(reverse newbinds) ,(mw:body body newenv)) (let* ( (bind (car bindings)) - (var (car bind)) + (var (car bind)) (valexp (cdr bind)) (rename (mw:rename-vars (list var))) (next-newenv (mw:syntax-rename newenv rename)) ) - (bind-loop (cdr bindings) + (bind-loop (cdr bindings) (cons (list (cdr (assq var rename)) (mw:body valexp newenv)) newbinds) @@ -500,13 +500,13 @@ ) ) ; -; Quasiquotation (backquote) +; Quasiquotation (backquote) ; ; At level 0, unquoted forms are left painted (not mw:strip'ed). ; At higher levels, forms which are unquoted to level 0 are painted. ; This includes forms within quotes. E.g.: -; (lambda (a) -; (quasiquote +; (lambda (a) +; (quasiquote ; (a (unquote a) b (quasiquote (a (unquote (unquote a)) b))))) ;or equivalently: ; (lambda (a) `(a ,a b `(a ,,a b))) @@ -551,12 +551,12 @@ ((eq? keyword mw:denote-of-quasiquote) (cons 'quasiquote (quasi (cdr subexp) (+ level 1))) ) - (else - (cons (quasi (car subexp) level) (quasi (cdr subexp) level)) + (else + (cons (quasi (car subexp) level) (quasi (cdr subexp) level)) ) ) ) ) ; end else, let - ) ; end cond + ) ; end cond ) (quasi exp 0) ; need to unquote to level 0 to paint diff --git a/mwsynrul.scm b/mwsynrul.scm index 1784441..bc5d7de 100644 --- a/mwsynrul.scm +++ b/mwsynrul.scm @@ -136,7 +136,7 @@ (loop P '() 0 k)) (define (mw:compile-template T vars env) - + (define (loop T inserted referenced rank escaped? k) (cond ((symbol? T) (let ((x (mw:pattern-variable T vars))) @@ -185,7 +185,7 @@ (lambda (T inserted referenced) (k (vector T) inserted referenced)))) (else (k T inserted referenced)))) - + (define (loop1 T inserted referenced rank escaped? k) (loop (car T) inserted @@ -208,7 +208,7 @@ T2) inserted referenced)))))) - + (loop T '() '() @@ -227,7 +227,7 @@ (list (mw:make-patternvar (string->symbol "") 0))) (define (mw:match F P env-def env-use) - + (define (match F P answer rank) (cond ((null? P) (and (null? F) answer)) @@ -248,7 +248,7 @@ (and (vector? F) (match (vector->list F) (vector-ref P 0) answer rank))) (else (and (equal? F P) answer)))) - + (define (match1 F P answer rank) (cond ((not (list? F)) #f) ((null? F) @@ -268,11 +268,11 @@ (mw:ellipsis-pattern-vars P)) answer) #f))))) - + (match F P mw:empty-pattern-variable-environment 0)) (define (mw:rewrite T alist) - + (define (rewrite T alist rank) (cond ((null? T) '()) ((pair? T) @@ -288,7 +288,7 @@ ((vector? T) (list->vector (rewrite (vector-ref T 0) alist rank))) (else T))) - + (define (rewrite1 T alist rank) (let* ((T1 (mw:ellipsis-template T)) (vars (mw:ellipsis-template-vars T)) @@ -296,7 +296,7 @@ vars))) (map (lambda (alist) (rewrite T1 alist rank)) (make-columns vars rows alist)))) - + (define (make-columns vars rows alist) (define (loop rows) (if (null? (car rows)) @@ -313,7 +313,7 @@ (mw:error "Use of macro is not consistent with definition" vars rows))) - + (rewrite T alist 0)) ; Given a use of a macro, the syntactic environment of the use, diff --git a/nclients.scm b/nclients.scm new file mode 100644 index 0000000..530683d --- /dev/null +++ b/nclients.scm @@ -0,0 +1,385 @@ +;;; "nclients.scm" Interface to net-client programs. +; Copyright 1997, 1998 Aubrey Jaffer +; +;Permission to copy this software, to redistribute it, and to use it +;for any purpose is granted, subject to the following restrictions and +;understandings. +; +;1. Any copy made of this software must include this copyright notice +;in full. +; +;2. I have made no warrantee or representation that the operation of +;this software will be error-free, and I am under no obligation to +;provide any services, by way of maintenance, update, or otherwise. +; +;3. In conjunction with products arising from the use of this +;material, there shall be no use of my name in any advertising, +;promotional, or sales literature without prior written consent in +;each case. + +(require 'string-search) +(require 'line-i/o) +(require 'system) +(require 'printf) +(require 'scanf) + +;;@args proc +;;@args proc k +;;Calls @1 with @var{k} arguments, strings returned by successive +;;calls to @code{tmpnam}. If @1 returns, then any files named by the +;;arguments to @1 are deleted automatically and the value(s) yielded +;;by the @1 is(are) returned. @var{k} may be ommited, in which case +;;it defaults to @code{1}. +(define (call-with-tmpnam proc . k) + (do ((cnt (if (null? k) 0 (+ -1 (car k))) (+ -1 cnt)) + (paths '() (cons (tmpnam) paths))) + ((negative? cnt) + (let ((ans (apply proc paths))) + (for-each (lambda (path) (if (file-exists? path) (delete-file path))) + paths) + ans)))) + +;;@args +;;@0 returns a string of the form @samp{username@r{@@}hostname}. If +;;this e-mail address cannot be obtained, #f is returned. +(define user-email-address + (let ((user (or (getenv "USER") (getenv "USERNAME"))) + (hostname (getenv "HOSTNAME"))) ;with domain + (lambda () + (if (not (and user hostname)) + (call-with-tmpnam + (lambda (tmp) + (define command->string + (lambda (command) + (and (zero? (system (string-append command " >" tmp))) + (file-exists? tmp) + (let ((res #f)) + (call-with-input-file tmp + (lambda (port) + (and (eqv? 1 (fscanf port "%s" res)) res))))))) + (case (software-type) + ;;((AMIGA) ) + ;;((MACOS THINKC) ) + ((MS-DOS WINDOWS OS/2 ATARIST) + (let ((compname (getenv "COMPUTERNAME")) ;without domain + (workgroup #f) + (netdir (or (getenv "windir") + (getenv "winbootdir") + (and (getenv "SYSTEMROOT") + (string-append (getenv "SYSTEMROOT") + "\\system32")) + "C:\\windows"))) + (define (net . cmd) + (zero? (system (apply string-append + (or netdir "") + (if netdir "\\" "") + "NET " cmd)))) + (and (not (and user hostname)) + (zero? (system (string-append + (or netdir "") + (if netdir "\\" "") + "IPCONFIG /ALL > " tmp " "))) + (file-exists? tmp) + ;;(print tmp '=) (display-file tmp) + (call-with-input-file tmp + (lambda (port) + (find-string-from-port? "Host Name" port) + (fscanf port " %*[. ]: %s" hostname) + (delete-file tmp)))) + (and (not (and user hostname)) + (net "START /LIST >" tmp) + (file-exists? tmp) + (not (eof-object? (call-with-input-file tmp read-char))) + (cond + ((call-with-input-file tmp + (lambda (port) + (find-string-from-port? "o network servic" port))) + (and (net "CONFIG /YES >" tmp) + (net "STOP /YES"))) + (else (net "CONFIG /YES >" tmp))) + (call-with-input-file tmp + (lambda (port) + (do ((line (read-line port) (read-line port))) + ((eof-object? line)) + (sscanf line " Workstation root directory %s" + netdir) + (sscanf line " Computer name \\\\%s" compname) + (sscanf line " Workstation Domain %s" workgroup) + (sscanf line " Workgroup %s" workgroup) + (sscanf line " User name %s" user))))) + (and netdir (not (and user hostname)) + (set! netdir (string-append netdir "\\system.ini")) + (file-exists? netdir) + (call-with-input-file netdir + (lambda (port) + (and (find-string-from-port? "[DNS]" port) + (read-line port) ;past newline + (do ((line (read-line port) (read-line port))) + ((not (and (string? line) + (string-index line #\=)))) + (sscanf line "HostName=%s" compname) + (sscanf line "DomainName=%s" workgroup))))) + (not user) + (call-with-input-file netdir + (lambda (port) + (and (find-string-from-port? "[Network]" port) + (read-line port) ;past newline + (do ((line (read-line port) (read-line port))) + ((not (and (string? line) + (string-index line #\=)))) + (sscanf line "UserName=%s" user)))))) + (if (and compname (not hostname)) + (set! hostname + (string-append + compname "." (or workgroup "localnet")))))) + ;;((NOSVE) ) + ;;((VMS) ) + ((UNIX COHERENT) + (if (not user) + (set! user (command->string "whoami"))) + (if (not hostname) + (set! hostname (command->string "hostname"))))) + (if (not user) (set! user "John_Doe")) + (if (not hostname) (set! hostname "localhost"))))) + (string-append user "@" hostname)))) + +;;@args +;;@0 returns a string containing the absolute file name representing +;;the current working directory. If this string cannot be obtained, +;;#f is returned. +;; +;;If @0 cannot be supported by the platform, the value of @0 is +;;#f. +(define current-directory + (case (software-type) + ;;((AMIGA) ) + ;;((MACOS THINKC) ) + ((MS-DOS WINDOWS ATARIST OS/2) + (lambda () + (call-with-tmpnam + (lambda (tmp) + (and (zero? (system (string-append "cd >" tmp))) + (file-exists? tmp) + (call-with-input-file tmp + (lambda (port) + (let ((lst (scanf-read-list "%[^:]%[:] %s" port))) + (and (pair? lst) + (eqv? 3 (length lst)) + (apply string-append lst)))))))))) + ;;((NOSVE) ) + ((UNIX COHERENT) + (lambda () + (call-with-tmpnam + (lambda (tmp) + (and (zero? (system (string-append "pwd >" tmp))) + (file-exists? tmp) + (let ((path (call-with-input-file tmp read-line))) + (and (string? path) path))))))) + ;;((VMS) ) + (else #f))) + +;;@body +;;Creates a sub-directory @1 of the current-directory. If successful, +;;@0 returns #t; otherwise #f. +(define (make-directory name) + (zero? (system (string-append "mkdir " name)))) + +;;@body +;;Returns #t if changing directory to @1 makes the current working +;;directory the same as it is before changing directory; otherwise +;;returns #f. +(define (null-directory? file-name) + (member file-name '("" "." "./" ".\\"))) + +;;@body +;;Returns #t if @1 is a fully specified pathname (does not depend on +;;the current working directory); otherwise returns #f. +(define (absolute-path? file-name) + (and (string? file-name) + (positive? (string-length file-name)) + (memv (string-ref file-name 0) '(#\\ #\/)))) + + +;;@body Returns #t if the string @1 contains characters used for +;;specifying glob patterns, namely @samp{*}, @samp{?}, or @samp{[}. +(define (glob-pattern? str) + (let loop ((idx (+ -1 (string-length str)))) + (if (negative? idx) + #f + (case (string-ref str idx) + ((#\* #\[ #\?) #t) + (else (loop (+ -1 idx))))))) + +;;@body +;;Returns a list of the decoded FTP @1; or #f if indecipherable. FTP +;;@dfn{Uniform Resource Locator}, @dfn{ange-ftp}, and @dfn{getit} +;;formats are handled. The returned list has four elements which are +;;strings or #f: +;; +;;@enumerate 0 +;;@item +;;username +;;@item +;;password +;;@item +;;remote-site +;;@item +;;remote-directory +;;@end enumerate +(define (parse-ftp-address url) + (define length? (lambda (len lst) (and (eqv? len (length lst)) lst))) + (cond + ((not url) #f) + ((length? 1 (scanf-read-list " ftp://%s %s" url)) + => (lambda (host) + (let ((login #f) (path #f) (dross #f)) + (sscanf (car host) "%[^/]/%[^@]%s" login path dross) + (and login + (append (cond + ((length? 2 (scanf-read-list "%[^@]@%[^@]%s" login)) + => (lambda (userpass@hostport) + (append + (cond ((length? 2 (scanf-read-list + "%[^:]:%[^@/]%s" + (car userpass@hostport)))) + (else (list (car userpass@hostport) #f))) + (cdr userpass@hostport)))) + (else (list "anonymous" #f login))) + (list path)))))) + (else + (let ((user@site #f) (colon #f) (path #f) (dross #f)) + (case (sscanf url " %[^:]%[:]%[^@] %s" user@site colon path dross) + ((2 3) + (let ((user #f) (site #f)) + (cond ((or (eqv? 2 (sscanf user@site "/%[^@/]@%[^@]%s" + user site dross)) + (eqv? 2 (sscanf user@site "%[^@/]@%[^@]%s" + user site dross))) + (list user #f site path)) + ((eqv? 1 (sscanf user@site "@%[^@]%s" site dross)) + (list #f #f site path)) + (else (list #f #f user@site path))))) + (else + (let ((site (scanf-read-list " %[^@/] %s" url))) + (and (length? 1 site) (list #f #f (car site) #f))))))))) + +;;@body +;;@3 must be a non-empty string or #f. @1 must be a non-empty list +;;of pathnames or Glob patterns (@pxref{Filenames}) matching files to +;;transfer. +;; +;;@0 puts the files specified by @1 into the @5 directory of FTP @4 +;;using name @2 with (optional) @3. +;; +;;If @3 is #f and @2 is not @samp{ftp} or @samp{anonymous}, then @2 is +;;ignored; FTP takes the username and password from the @file{.netrc} +;;or equivalent file. +(define (ftp-upload paths user password remote-site remote-dir) + (call-with-tmpnam + (lambda (script logfile) + (define local-path (current-directory)) + (define passwd (or password (user-email-address))) + (dynamic-wind + (lambda () #f) + (lambda () + (call-with-current-continuation + (lambda (exit) + (define (run-ftp-script paths) + (call-with-output-file script + (lambda (port) + (define lcd "") + (cond ((or (member user '(ftp anonymous "ftp" "anonymous")) + password) + (fprintf port "user %s %s\n" user passwd))) + (fprintf port "binary\n") ; Turn binary ON for all transfers + ;;(fprintf port "prompt\n") ; Turn prompt OFF for possible mget + (if (not (null-directory? remote-dir)) + (fprintf port "cd %s\n" remote-dir)) + (for-each + (lambda (path-name) + (let* ((r/i (string-reverse-index path-name #\/)) + (dir (if r/i (substring path-name 0 (+ 1 r/i)) "")) + (file-name (if r/i + (substring path-name (+ 1 r/i) + (string-length path-name)) + path-name))) + (cond ((and r/i (glob-pattern? dir)) + (slib:warn + "Wildcard not allowed in directory component " + path-name) + (exit #f)) + ((and (not (glob-pattern? file-name)) + (not (file-exists? path-name))) + (slib:warn " file doesn't exist:" path-name) + (exit #f)) + ((equal? lcd dir)) + ((absolute-path? dir) + (fprintf port "lcd %s\n" dir)) + ((eqv? 0 (substring? lcd dir)) + (fprintf port "lcd %s\n" + (substring dir (string-length lcd) + (string-length dir)))) + (else + (fprintf port "lcd %s\n" local-path) + (if (not (null-directory? dir)) + (fprintf port "lcd %s\n" dir)))) + (set! lcd dir) + (cond ((glob-pattern? file-name) + (fprintf port "mput %s\n" file-name)) + (else + (fprintf port "put %s\n" file-name))))) + paths))) + ;;(display-file script) + (cond + ((zero? (system + (string-append + "ftp " + (if (or (member user '(ftp anonymous "ftp" "anonymous")) + password) + "-inv" "-iv") + " " remote-site + " <" script + " >" logfile))) + (file-exists? logfile) + (call-with-input-file logfile + (lambda (port) + (do ((line (read-line port) (read-line port))) + ((or (eof-object? line) + (substring-ci? "Unknown host" line) + (substring-ci? "Not connected" line) + (and (memv (string-ref line 0) '(#\4 #\5)) + (not (substring-ci? "bytes" line)))) + (cond ((eof-object? line) #t) + (else (slib:warn line) #f))) + ;;(write-line line) + )))) + (else (slib:warn 'ftp 'failed) #f))) + (cond ((or local-path (every? absolute-file? paths)) + (run-ftp-script paths)) + (else (for-each (lambda (path) (run-ftp-script (list path))) + paths)))))) + (lambda () + (if (file-exists? script) (delete-file script)) + (if (file-exists? logfile) (delete-file logfile))))) + 2)) + +;;@body +;;Returns a URL-string for @1 on the local host. +(define (path->url path) + (if (absolute-path? path) + (sprintf #f "file:%s" path) + (sprintf #f "file:%s/%s" (current-directory) path))) + +;;@body +;;If a @samp{netscape} browser is running, @0 causes the browser to +;;display the page specified by string @1 and returns #t. +;; +;;If the browser is not running, @0 runs @samp{netscape} with the +;;argument @1. If the browser starts as a background job, @0 returns +;;#t immediately; if the browser starts as a foreground job, then @0 +;;returns #t when the browser exits; otherwise it returns #f. +(define (browse-url-netscape url) + (or (eqv? 0 (system (sprintf #f "netscape-remote -remote 'openURL(%s)'" url))) + (eqv? 0 (system (sprintf #f "netscape -remote 'openURL(%s)'" url))) + (eqv? 0 (system (sprintf #f "netscape '%s'&" url))) + (eqv? 0 (system (sprintf #f "netscape '%s'" url))))) diff --git a/objdoc.txi b/objdoc.txi new file mode 100644 index 0000000..123417b --- /dev/null +++ b/objdoc.txi @@ -0,0 +1,238 @@ + +@code{(require 'object)} +@ftindex object + +This is the Macroless Object System written by Wade Humeniuk +(whumeniu@@datap.ca). Conceptual Tributes: @ref{Yasos}, MacScheme's +%object, CLOS, Lack of R4RS macros. + +@subsection Concepts +@table @asis + +@item OBJECT +An object is an ordered association-list (by @code{eq?}) of methods +(procedures). Methods can be added (@code{make-method!}), deleted +(@code{unmake-method!}) and retrieved (@code{get-method}). Objects may +inherit methods from other objects. The object binds to the environment +it was created in, allowing closures to be used to hide private +procedures and data. + +@item GENERIC-METHOD +A generic-method associates (in terms of @code{eq?}) object's method. +This allows scheme function style to be used for objects. The calling +scheme for using a generic method is @code{(generic-method object param1 +param2 ...)}. + +@item METHOD +A method is a procedure that exists in the object. To use a method +get-method must be called to look-up the method. Generic methods +implement the get-method functionality. Methods may be added to an +object associated with any scheme obj in terms of eq? + +@item GENERIC-PREDICATE +A generic method that returns a boolean value for any scheme obj. + +@item PREDICATE +A object's method asscociated with a generic-predicate. Returns +@code{#t}. +@end table + +@subsection Procedures + +@defun make-object ancestor @dots{} +Returns an object. Current object implementation is a tagged vector. +@var{ancestor}s are optional and must be objects in terms of object?. +@var{ancestor}s methods are included in the object. Multiple +@var{ancestor}s might associate the same generic-method with a method. +In this case the method of the @var{ancestor} first appearing in the +list is the one returned by @code{get-method}. +@end defun + +@defun object? obj +Returns boolean value whether @var{obj} was created by make-object. +@end defun + +@defun make-generic-method exception-procedure +Returns a procedure which be associated with an object's methods. If +@var{exception-procedure} is specified then it is used to process +non-objects. +@end defun + +@defun make-generic-predicate +Returns a boolean procedure for any scheme object. +@end defun + +@defun make-method! object generic-method method +Associates @var{method} to the @var{generic-method} in the object. The +@var{method} overrides any previous association with the +@var{generic-method} within the object. Using @code{unmake-method!} +will restore the object's previous association with the +@var{generic-method}. @var{method} must be a procedure. +@end defun + +@defun make-predicate! object generic-preciate +Makes a predicate method associated with the @var{generic-predicate}. +@end defun + +@defun unmake-method! object generic-method +Removes an object's association with a @var{generic-method} . +@end defun + +@defun get-method object generic-method +Returns the object's method associated (if any) with the +@var{generic-method}. If no associated method exists an error is +flagged. +@end defun + +@subsection Examples + +@example +(require 'object) +@ftindex object + +(define instantiate (make-generic-method)) + +(define (make-instance-object . ancestors) + (define self (apply make-object + (map (lambda (obj) (instantiate obj)) ancestors))) + (make-method! self instantiate (lambda (self) self)) + self) + +(define who (make-generic-method)) +(define imigrate! (make-generic-method)) +(define emigrate! (make-generic-method)) +(define describe (make-generic-method)) +(define name (make-generic-method)) +(define address (make-generic-method)) +(define members (make-generic-method)) + +(define society + (let () + (define self (make-instance-object)) + (define population '()) + (make-method! self imigrate! + (lambda (new-person) + (if (not (eq? new-person self)) + (set! population (cons new-person population))))) + (make-method! self emigrate! + (lambda (person) + (if (not (eq? person self)) + (set! population + (comlist:remove-if (lambda (member) + (eq? member person)) + population))))) + (make-method! self describe + (lambda (self) + (map (lambda (person) (describe person)) population))) + (make-method! self who + (lambda (self) (map (lambda (person) (name person)) + population))) + (make-method! self members (lambda (self) population)) + self)) + +(define (make-person %name %address) + (define self (make-instance-object society)) + (make-method! self name (lambda (self) %name)) + (make-method! self address (lambda (self) %address)) + (make-method! self who (lambda (self) (name self))) + (make-method! self instantiate + (lambda (self) + (make-person (string-append (name self) "-son-of") + %address))) + (make-method! self describe + (lambda (self) (list (name self) (address self)))) + (imigrate! self) + self) +@end example + +@subsubsection Inverter Documentation +Inheritance: +@lisp + ::( ) +@end lisp +Generic-methods +@lisp + ::value @result{} ::value + ::set-value! @result{} ::set-value! + ::describe @result{} ::describe + ::help + ::invert + ::inverter? +@end lisp + +@subsubsection Number Documention +Inheritance +@lisp + ::() +@end lisp +Slots +@lisp + :: +@end lisp +Generic Methods +@lisp + ::value + ::set-value! +@end lisp + +@subsubsection Inverter code +@example +(require 'object) +@ftindex object + +(define value (make-generic-method (lambda (val) val))) +(define set-value! (make-generic-method)) +(define invert (make-generic-method + (lambda (val) + (if (number? val) + (/ 1 val) + (error "Method not supported:" val))))) +(define noop (make-generic-method)) +(define inverter? (make-generic-predicate)) +(define describe (make-generic-method)) +(define help (make-generic-method)) + +(define (make-number x) + (define self (make-object)) + (make-method! self value (lambda (this) x)) + (make-method! self set-value! + (lambda (this new-value) (set! x new-value))) + self) + +(define (make-description str) + (define self (make-object)) + (make-method! self describe (lambda (this) str)) + (make-method! self help (lambda (this) "Help not available")) + self) + +(define (make-inverter) + (let* ((self (make-object + (make-number 1) + (make-description "A number which can be inverted"))) + ( (get-method self value))) + (make-method! self invert (lambda (self) (/ 1 ( self)))) + (make-predicate! self inverter?) + (unmake-method! self help) + (make-method! self help + (lambda (self) + (display "Inverter Methods:") (newline) + (display " (value inverter) ==> n") (newline))) + self)) + +;;;; Try it out + +(define invert! (make-generic-method)) + +(define x (make-inverter)) + +(make-method! x invert! (lambda (x) (set-value! x (/ 1 (value x))))) + +(value x) @result{} 1 +(set-value! x 33) @result{} undefined +(invert! x) @result{} undefined +(value x) @result{} 1/33 + +(unmake-method! x invert!) @result{} undefined + +(invert! x) @error{} ERROR: Method not supported: x +@end example diff --git a/object.scm b/object.scm new file mode 100644 index 0000000..c272ef9 --- /dev/null +++ b/object.scm @@ -0,0 +1,97 @@ +;;; "object.scm" Macroless Object System +;;;From: whumeniu@datap.ca (Wade Humeniuk) + +;;;Date: February 15, 1994 + +;; Object Construction: +;; 0 1 2 3 4 +;; #(object-tag get-method make-method! unmake-method! get-all-methods) + +(define object:tag "object") + +;;; This might be better done using COMLIST:DELETE-IF. +(define (object:removeq obj alist) + (if (null? alist) + alist + (if (eq? (caar alist) obj) + (cdr alist) + (cons (car alist) (object:removeq obj (cdr alist)))))) + +(define (get-all-methods obj) + (if (object? obj) + ((vector-ref obj 4)) + (slib:error "Cannot get methods on non-object: " obj))) + +(define (object? obj) + (and (vector? obj) + (eq? object:tag (vector-ref obj 0)))) + +(define (make-method! obj generic-method method) + (if (object? obj) + (if (procedure? method) + (begin + ((vector-ref obj 2) generic-method method) + method) + (slib:error "Method must be a procedure: " method)) + (slib:error "Cannot make method on non-object: " obj))) + +(define (get-method obj generic-method) + (if (object? obj) + ((vector-ref obj 1) generic-method) + (slib:error "Cannot get method on non-object: " obj))) + +(define (unmake-method! obj generic-method) + (if (object? obj) + ((vector-ref obj 3) generic-method) + (slib:error "Cannot unmake method on non-object: " obj))) + +(define (make-predicate! obj generic-predicate) + (if (object? obj) + ((vector-ref obj 2) generic-predicate (lambda (self) #t)) + (slib:error "Cannot make predicate on non-object: " obj))) + +(define (make-generic-method . exception-procedure) + (define generic-method + (lambda (obj . operands) + (if (object? obj) + (let ((object-method ((vector-ref obj 1) generic-method))) + (if object-method + (apply object-method (cons obj operands)) + (slib:error "Method not supported: " obj))) + (apply exception-procedure (cons obj operands))))) + + (if (not (null? exception-procedure)) + (if (procedure? (car exception-procedure)) + (set! exception-procedure (car exception-procedure)) + (slib:error "Exception Handler Not Procedure:")) + (set! exception-procedure + (lambda (obj . params) + (slib:error "Operation not supported: " obj)))) + generic-method) + +(define (make-generic-predicate) + (define generic-predicate + (lambda (obj) + (if (object? obj) + (if ((vector-ref obj 1) generic-predicate) + #t + #f) + #f))) + generic-predicate) + +(define (make-object . ancestors) + (define method-list + (apply append (map (lambda (obj) (get-all-methods obj)) ancestors))) + (define (make-method! generic-method method) + (set! method-list (cons (cons generic-method method) method-list)) + method) + (define (unmake-method! generic-method) + (set! method-list (object:removeq generic-method method-list)) + #t) + (define (all-methods) method-list) + (define (get-method generic-method) + (let ((method-def (assq generic-method method-list))) + (if method-def (cdr method-def) #f))) + (vector object:tag get-method make-method! unmake-method! all-methods)) + + diff --git a/paramlst.scm b/paramlst.scm index b4af55a..32fb158 100644 --- a/paramlst.scm +++ b/paramlst.scm @@ -55,8 +55,11 @@ (and (every (lambda (check parameter) (every (lambda (p) - (not (and check (not (check p))))) - ;;(slib:error (car parameter) "parameter is wrong type: " p) + (let ((good? (not (and check (not (check p)))))) + (if (not good?) + (slib:warn + (car parameter) 'parameter? p)) + good?)) (cdr parameter))) checks parameter-list) parameter-list)) diff --git a/primes.scm b/primes.scm deleted file mode 100644 index 672e899..0000000 --- a/primes.scm +++ /dev/null @@ -1,187 +0,0 @@ -;; "primes.scm", test and generate prime numbers. -; Written by Michael H Coffin (mhc@edsdrd.eds.com) -; -; This code is in the public domain. - -;Date: Thu, 23 Feb 1995 07:47:49 +0500 -;From: mhc@edsdrd.eds.com (Michael H Coffin) -;; -;; Test numbers for primality using Rabin-Miller Monte-Carlo -;; primality test. -;; -;; Public functions: -;; -;; (primes start count . iter) -;; -;; (probably-prime? p . iter) -;; -;; -;; Please contact the author if you have problems or suggestions: -;; -;; Mike Coffin -;; 1196 Whispering Knoll -;; Rochester Hills, Mi. 48306 -;; -;; mhc@edsdrd.eds.com -;; - -(require 'random) - -;; The default number of times to perform the Rabin-Miller test. The -;; probability of a composite number passing the Rabin-Miller test for -;; primality with this many random numbers is at most -;; 1/(4^primes:iterations). The default yields about 1e-9. -;; -(define primes:iter 15) - -;; Is n probably prime? -;; -(define (primes:probably-prime? n . iter) - (let ((iter (if (null? iter) primes:iter (car iter)))) - (primes:prob-pr? n iter))) - - -;; Return a list of the first `number' odd probable primes less -;; than `start'. - -(define (primes:primes< start number . iter) - (let ((iter (if (null? iter) primes:iter (car iter)))) - (do ((candidate (if (odd? start) start (- start 1)) - (- candidate 2)) - (count 0) - (result '()) - ) - ((or (< candidate 3) (>= count number)) result) - (if (primes:prob-pr? candidate iter) - (begin - (set! count (1+ count)) - (set! result (cons candidate result))) - )))) - -(define (primes:primes> start number . iter) - (let ((iter (if (null? iter) primes:iter (car iter)))) - (do ((candidate (if (odd? start) start (+ 1 start)) - (+ 2 candidate)) - (count 0) - (result '()) - ) - ((= count number) (reverse result)) - (if (primes:prob-pr? candidate iter) - (begin - (set! count (1+ count)) - (set! result (cons candidate result))) - )))) - - -;; Is n probably prime? First we check for divisibility by small -;; primes; if it passes that, and it's less than the maximum small -;; prime squared, we try Rabin-Miller. -;; -(define (primes:prob-pr? n count) - (and (not (primes:dbsp? n)) - (or (< n (* primes:max-small-prime primes:max-small-prime)) - (primes:rm-prime? n count)))) - - -;; Is `n' Divisible By a Small Prime? -;; -(define primes:dbsp? - (let ((sqrt (cond ((provided? 'inexact) sqrt) - (else (require 'root) integer-sqrt)))) - (lambda (n) - (let ((limit (min (sqrt n) primes:max-small-prime)) - (divisible #f) - ) - (do ((i 0 (1+ i))) - ((let* ((divisor (vector-ref primes:small-primes i))) - (set! divisible (= (modulo n divisor) 0)) - (or divisible (> divisor limit))) - divisible) - ))))) - - -;; Does `n' pass the R.-M. primality test for `m' random numbers? -;; -(define (primes:rm-prime? n m) - (do ((i 0 (1+ i)) - (x (+ 2 (random (- n 2) primes:prngs)))) - ((or (= i m) (primes:rm-composite? n x)) - (= i m)))) - - -;; Does `x' prove `n' composite using Rabin-Miller? -;; -(define (primes:rm-composite? n x) - (let ((f (primes:extract2s (- n 1)))) - (primes:rm-comp? n (cdr f) (car f) x))) - - -;; Is `n' (where n-1 = 2^k * q) proven composite by `x'? -;; -(define (primes:rm-comp? n q k x) - (let ((y (primes:expt-mod x q n))) - (if (= y 1) - #f - (let loop ((j 0) (y y)) - (cond ((= j k) #t) - ((= y (- n 1)) #f) - ((= y 1) #t) - (else (loop (1+ j) (primes:expt-mod y 2 n))) - ))))) - - -;; Extract factors of 2; that is, factor x as 2^k * q -;; and return (k . q) -;; -(define (primes:extract2s x) - (do ((k 0 (1+ k)) - (q x (quotient q 2))) - ((odd? q) (cons k q)) - )) - - -;; Raise `base' to the power `exp' modulo `modulus' Could use the -;; modulo package, but we only need this function (and besides, this -;; implementation is quite a bit faster). -;; -(define (primes:expt-mod base exp modulus) - (do ((y 1) - (k exp (quotient k 2)) - (z base (modulo (* z z) modulus))) - ((= k 0) y) - (if (odd? k) - (set! y (modulo (* y z) modulus))) - )) - -(define primes:prngs - (make-random-state "repeatable seed for primes")) - -;; This table seems big enough so that making it larger really -;; doesn't have much effect. -;; -(define primes:max-small-prime 997) - -(define primes:small-primes - '#( 2 3 5 7 11 13 17 19 23 29 - 31 37 41 43 47 53 59 61 67 71 - 73 79 83 89 97 101 103 107 109 113 - 127 131 137 139 149 151 157 163 167 173 - 179 181 191 193 197 199 211 223 227 229 - 233 239 241 251 257 263 269 271 277 281 - 283 293 307 311 313 317 331 337 347 349 - 353 359 367 373 379 383 389 397 401 409 - 419 421 431 433 439 443 449 457 461 463 - 467 479 487 491 499 503 509 521 523 541 - 547 557 563 569 571 577 587 593 599 601 - 607 613 617 619 631 641 643 647 653 659 - 661 673 677 683 691 701 709 719 727 733 - 739 743 751 757 761 769 773 787 797 809 - 811 821 823 827 829 839 853 857 859 863 - 877 881 883 887 907 911 919 929 937 941 - 947 953 967 971 977 983 991 997 )) - -(define primes< primes:primes<) -(define primes> primes:primes>) -(define probably-prime? primes:probably-prime?) - -(provide 'primes) diff --git a/printf.scm b/printf.scm index 42341fc..da7178c 100644 --- a/printf.scm +++ b/printf.scm @@ -21,10 +21,13 @@ ;; Parse the output of NUMBER->STRING. ;; Returns a list: (sign-character digit-string exponent-integer) -;; sign-char will be either #\+ or #\-, digit-string will always begin +;; SIGN-CHAR will be either #\+ or #\-, DIGIT-STRING will always begin ;; with a "0", after which a decimal point should be understood. +;; If STR denotes a non-real number, 3 additional elements for the +;; complex part are appended. (define (stdio:parse-float str) - (let ((n (string-length str))) + (let ((n (string-length str)) + (iend 0)) (letrec ((prefix (lambda (i rest) (if (and (< i (- n 1)) @@ -41,7 +44,7 @@ (case c ((#\- #\+) (cons c (rest (+ i 1)))) (else (cons #\+ (rest i)))))))) - (digits + (digits (lambda (i rest) (do ((j i (+ j 1))) ((or (>= j n) @@ -56,45 +59,77 @@ (char=? #\. (string-ref str i))) (rest (+ i 1)) (rest i)))) - (exp + (exp (lambda (i) (if (< i n) (case (string-ref str i) ((#\e #\s #\f #\d #\l #\E #\S #\F #\D #\L) - (let ((s (sign (+ i 1) (lambda (i) (digits i end))))) + (let ((s (sign (+ i 1) (lambda (i) (digits i end!))))) (list (if (char=? #\- (car s)) (- (string->number (cadr s))) (string->number (cadr s)))))) - (else (parse-error))) - '(0)))) - (end + (else (end! i) + '(0))) + (begin (end! i) + '(0))))) + (end! + (lambda (i) + (set! iend i) + '())) + (real (lambda (i) - (if (< i n) (parse-error) '()))) + (let ((parsed + (prefix + i + (lambda (i) + (sign + i + (lambda (i) + (digits + i + (lambda (i) + (point + i + (lambda (i) + (digits i exp))))))))))) + (and (list? parsed) + (apply + (lambda (sgn idigs fdigs exp) + (let* ((digs (string-append "0" idigs fdigs)) + (n (string-length digs))) + (let loop ((i 1) + (exp (+ exp (string-length idigs)))) + (if (and (< i n) + (char=? #\0 (string-ref digs i))) + (loop (+ i 1) (- exp 1)) + (list sgn (substring digs (- i 1) n) exp))))) + parsed))))) (parse-error (lambda () #f))) - (let ((parsed - (prefix 0 - (lambda (i) - (sign i - (lambda (i) - (digits i - (lambda (i) - (point i - (lambda (i) - (digits i exp))))))))))) - (and (list? parsed) - (apply - (lambda (sgn idigs fdigs exp) - (let* ((digs (string-append "0" idigs fdigs)) - (n (string-length digs))) - (let loop ((i 1) - (exp (+ exp (string-length idigs)))) - (if (and (< i n) - (char=? #\0 (string-ref digs i))) - (loop (+ i 1) (- exp 1)) - (list sgn (substring digs (- i 1) n) exp))))) - parsed)))))) + (let ((realpart (real 0))) + (cond ((= iend n) realpart) + ((memv (string-ref str iend) '(#\+ #\-)) + (let ((complexpart (real iend))) + (and (= iend (- n 1)) + (char-ci=? #\i (string-ref str iend)) + (append realpart complexpart)))) + ((eqv? (string-ref str iend) #\@) + ;; Polar form: No point in parsing the angle ourselves, + ;; since some transcendental approximation is unavoidable. + (let ((num (string->number str))) + (and num + (let ((realpart + (stdio:parse-float + (number->string (real-part num)))) + (imagpart + (if (real? num) + '() + (stdio:parse-float + (number->string (imag-part num)))))) + (and realpart imagpart + (append realpart imagpart)))))) + (else #f)))))) ;; STR is a digit string representing a floating point mantissa, STR must ;; begin with "0", after which a decimal point is understood. @@ -109,11 +144,13 @@ (cond ((< ndigs 0) "") ((= n ndigs) str) ((< n ndigs) - (if strip-0s str - (string-append - str (make-string (- ndigs n) - (if (char-numeric? (string-ref str n)) - #\0 #\#))))) + (let ((zeropad (make-string + (max 0 (- (or strip-0s ndigs) n)) + (if (char-numeric? (string-ref str n)) + #\0 #\#)))) + (if (zero? (string-length zeropad)) + str + (string-append str zeropad)))) (else (let ((res (substring str 0 (+ ndigs 1))) (dig (lambda (i) @@ -132,7 +169,7 @@ (let inc! ((i ndigs)) (let ((d (dig i))) (if (< d 9) - (string-set! res i + (string-set! res i (string-ref (number->string (+ d 1)) 0)) (begin @@ -147,7 +184,6 @@ (loop (- i 1)))) res))) - (define (stdio:iprintf out format-string . args) (cond ((not (equal? "" format-string)) @@ -168,11 +204,17 @@ (define (incomplete) (slib:error 'printf "conversion specification incomplete" format-string)) + (define (wna) + (slib:error 'printf "wrong number of arguments" + (length args) + format-string)) (let loop ((args args)) (advance) (cond - ((end-of-format?)) + ((end-of-format?) + ;;(or (null? args) (wna)) ;Extra arguments are *not* a bug. + ) ((eqv? #\\ fc);;Emulating C strings may not be a good idea. (must-advance) (and (case fc @@ -216,7 +258,7 @@ (apply string-append pre (append strs - (list (make-string + (list (make-string (- width len) #\space))))) (leading-0s (apply string-append @@ -278,16 +320,16 @@ (list "." fdigs))))) ((zero? precision) (list (if alternate-form "0." "0"))) - ((string=? digs "") (list "0")) + ((and strip-0s (string=? digs "") (list "0"))) (else (list "0." (make-string (min precision (- -1 exp)) #\0) digs))))) (define (e digs exp strip-0s) - (let* ((digs (stdio:round-string + (let* ((digs (stdio:round-string digs (+ 1 precision) (and strip-0s 0))) (istrt (if (char=? #\0 (string-ref digs 0)) 1 0)) - (fdigs (substring + (fdigs (substring digs (+ 1 istrt) (string-length digs))) (exp (if (zero? istrt) exp (- exp 1)))) (list @@ -299,38 +341,65 @@ (if (negative? exp) "-" "+") (if (< -10 exp 10) "0" "") (number->string (abs exp))))) + (define (g digs exp) + (let ((strip-0s (not alternate-form))) + (set! alternate-form #f) + (cond ((<= (- 1 precision) exp precision) + (set! precision (- precision exp)) + (f digs exp strip-0s)) + (else + (set! precision (- precision 1)) + (e digs exp strip-0s))))) + (define (k digs exp sep) + (let* ((units '#("y" "z" "a" "f" "p" "n" "u" "m" "" + "k" "M" "G" "T" "P" "E" "Z" "Y")) + (base 8) ;index of "" + (uind (let ((i (if (negative? exp) + (quotient (- exp 3) 3) + (quotient (- exp 1) 3)))) + (and + (< -1 (+ i base) (vector-length units)) + i)))) + (cond (uind + (set! exp (- exp (* 3 uind))) + (set! precision (max 0 (- precision exp))) + (append + (f digs exp #f) + (list sep + (vector-ref units (+ uind base))))) + (else + (g digs exp))))) + (cond ((negative? precision) (set! precision 6)) ((and (zero? precision) (char-ci=? fc #\g)) (set! precision 1))) - (let* ((str + (let* ((str (cond ((number? num) (number->string (exact->inexact num))) ((string? num) num) ((symbol? num) (symbol->string num)) (else "???"))) (parsed (stdio:parse-float str))) - (cond (parsed - (apply - (lambda (sgn digs exp) - (apply pad + (letrec ((format-real + (lambda (signed? sgn digs exp . rest) + (if (null? rest) + (cons (if (char=? #\- sgn) "-" - (if signed "+" (if blank " " ""))) + (if signed? "+" (if blank " " ""))) (case fc ((#\e #\E) (e digs exp #f)) ((#\f #\F) (f digs exp #f)) - ((#\g #\G) - (let ((strip-0s (not alternate-form))) - (set! alternate-form #f) - (cond ((< -4 exp (+ 1 precision)) - (set! precision (- precision exp)) - (f digs exp strip-0s)) - (else - (set! precision (- precision 1)) - (e digs exp strip-0s)))))))) - parsed)) - (else str)))) + ((#\g #\G) (g digs exp)) + ((#\k) (k digs exp "")) + ((#\K) (k digs exp " ")))) + (append (format-real signed? sgn digs exp) + (apply format-real #t rest) + '("i")))))) + (if parsed + (apply pad (apply format-real signed parsed)) + (pad "???"))))) (do () ((case fc ((#\-) (set! left-adjust #t) #f) @@ -355,6 +424,13 @@ (set! type-modifier fc) (must-advance))) + ;;At this point fc completely determines the format to use. + (if (null? args) + (if (memv (char-downcase fc) + '(#\c #\s #\a #\d #\i #\u #\o #\x #\b + #\f #\e #\g #\k)) + (wna))) + (case fc ;; only - is allowed between % and c ((#\c #\C) ; C is enhancement @@ -443,7 +519,7 @@ ((#\b #\B) (and (out (integer-convert (car args) 2)) (loop (cdr args)))) ((#\%) (and (out #\%) (loop args))) - ((#\f #\F #\e #\E #\g #\G) + ((#\f #\F #\e #\E #\g #\G #\k #\K) (and (out (float-convert (car args) fc)) (loop (cdr args)))) (else (cond ((end-of-format?) (incomplete)) diff --git a/pscheme.init b/pscheme.init new file mode 100644 index 0000000..dfa05a8 --- /dev/null +++ b/pscheme.init @@ -0,0 +1,202 @@ +;;; "pscheme.init" -*-scheme-*- +;;; SLIB init file for Pocket Scheme +;;; SLIB orig Author: Aubrey Jaffer (jaffer@ai.mit.edu) +;;; Author: Ben Goetter +;;; Initial work for 0.2.3 by Robert Goldman (goldman@htc.honeywell.com) +;;; +;;; This code is in the public domain. + +; best fit for Windows CE? +(define (software-type) 'MS-DOS) + +(define (scheme-implementation-type) 'PocketScheme) +(define (scheme-implementation-version) "0.3.6") + +(define in-vicinity string-append) + +(define (implementation-vicinity) + "\\Program Files\\Pocket Scheme\\") + +(define (library-vicinity) + (in-vicinity (implementation-vicinity) "slib\\")) + +(define (home-vicinity) + "\\My Documents\\") + +(define *features* + '(source + rev4-report + ieee-p1178 + rev4-optional-procedures + multiarg/and- + multiarg-apply + with-file + char-ready? + defmacro + delay + eval + dynamic-wind + full-continuation + ;;trace ; Comment out for SLIB TRACE macros + system + string-port + )) + +;;; (OUTPUT-PORT-WIDTH ) +(define (output-port-width . arg) 79) + +;;; (OUTPUT-PORT-HEIGHT ) +(define (output-port-height . arg) 12) + +;;; (TMPNAM) makes a temporary file name. +(define tmpnam (let ((cntr 100)) + (lambda () (set! cntr (+ 1 cntr)) + (string-append "slib_" (number->string cntr))))) + +;;; (FILE-EXISTS? ) +(define (file-exists? f) + (let ((file #f)) + (with-handlers (((lambda (x) #t) (lambda (x) #f))) + (set! file (open-input-file f)) + (close-input-port file) + #t))) + +;; pscheme: current-error-port, delete-file, force-output already defined + +;;; CHAR-CODE-LIMIT is one greater than the largest integer which can +;;; be returned by CHAR->INTEGER. +;(define char-code-limit +; (with-handlers ( +; ((lambda (x) #t) (lambda (x) 256)) +; ) +; (integer->char 65535) +; 65536)) +;;; Currently there are only three clients of this symbol. +;;; Following observations relate to PScheme 0.3.5, JACAL 1a9, SLIB 2c5. +;;; JACAL: crashes when set to 65536. +;;; make-crc: extremely inefficient when set to 65536, spending forever in init +;;; precedence-parse: ignores any setting in excess of 256 +;;; So we patch it to 256. +(define char-code-limit 256) + +;;; MOST-POSITIVE-FIXNUM is used in modular.scm +;;; This is the most positive immediate-value fixnum in PScheme. +;;; The secondary representation extends fixnum values to 0xffffffff. +(define most-positive-fixnum #x07FFFFFF) + +;;; Return argument +(define (identity x) x) + +;;; SLIB:EVAL is single argument eval using the top-level (user) environment. +(define slib:eval eval) + +;;; If your implementation provides R4RS macros: +;(define macro:eval slib:eval) +;(define macro:load load) + +(define gentemp + (let ((*gensym-counter* -1)) + (lambda () + (set! *gensym-counter* (+ *gensym-counter* 1)) + (string->symbol + (string-append "slib:G" (number->string *gensym-counter*)))))) + +(define base:eval slib:eval) +(define defmacro:eval slib:eval) + +(define (slib:eval-load evl) + (if (not (file-exists? )) + (set! (string-append (scheme-file-suffix)))) + (call-with-input-file + (lambda (port) + (let ((old-load-pathname *load-pathname*)) + (set! *load-pathname* ) + (do ((o (read port) (read port))) + ((eof-object? o)) + (evl o)) + (set! *load-pathname* old-load-pathname))))) + +(define (defmacro:load ) + (slib:eval-load defmacro:eval)) + +(define slib:warn + (lambda args + (let ((port (current-error-port))) + (display "Warn: " port) + (for-each (lambda (x) (display x port)) args)))) + +;;; Define an error procedure for the library +(define (slib:error . k) + (error + (cond + ((= (length k) 0) '()) + ((= (length k) 1) (car k)) + ((provided? 'string-port) + (call-with-output-string + (lambda (out) + (let ((add-space #f)) + (map + (lambda (arg) + (if add-space (write-char #\space out) (set! add-space #t)) + (display arg out)) + k))))) + (else (car k))))) + +;;; For the benefit of slib:error above, as announced by feature string-port +(define (call-with-output-string t) + (let* ((p (open-output-string)) + (r (t p)) + (s (get-output-string p))) + (close-output-port p) + s)) + +(define (call-with-input-string s t) + (let* ((p (open-input-string s)) + (r (t p))) + (close-input-port p) + r)) + +;;; define these as appropriate for your system. +(define slib:tab (integer->char 9)) +(define slib:form-feed (integer->char 12)) + +;;; Support for older versions of Scheme. Not enough code for its own file. +(define (last-pair l) (if (pair? (cdr l)) (last-pair (cdr l)) l)) +(define t #t) +(define nil #f) + +;;; Define these if your implementation's syntax can support it and if +;;; they are not already defined. + +(define (1+ n) (+ n 1)) +(define (-1+ n) (+ n -1)) +(define 1- -1+) + +;;; Define SLIB:EXIT to be the implementation procedure to exit or +;;; return if exitting not supported. +(define slib:exit exit) + +;;; Here for backward compatability +(define (scheme-file-suffix) ".scm") + +;;; (SLIB:LOAD-SOURCE "foo") should load "foo.scm" or with whatever +;;; suffix all the module files in SLIB have. See feature 'SOURCE. + +(define (slib:load-source f) + (if (not (file-exists? f)) + (set! f (string-append f (scheme-file-suffix)))) + (load f)) + +;;; (SLIB:LOAD-COMPILED "foo") should load the file that was produced +;;; by compiling "foo.scm" if this implementation can compile files. +;;; See feature 'COMPILED. + +(define slib:load-compiled load) + +;;; At this point SLIB:LOAD must be able to load SLIB files. + +(define slib:load slib:load-source) + +;;; Hold onto pscheme native version +(define pscheme:require require) +(slib:load (in-vicinity (library-vicinity) "require")) diff --git a/queue.scm b/queue.scm index 4557746..89a65b0 100644 --- a/queue.scm +++ b/queue.scm @@ -49,7 +49,7 @@ (if (null? old-first-pair) (queue:set-last-pair! q new-first-pair))) q) - + (define (enqueue! q datum) (let ((new-pair (cons datum '()))) (cond ((null? (queue:first-pair q)) diff --git a/randinex.scm b/randinex.scm index e6dc48b..8a0afd1 100644 --- a/randinex.scm +++ b/randinex.scm @@ -1,5 +1,5 @@ ;;;"randinex.scm" Pseudo-Random inexact real numbers for scheme. -;;; Copyright (C) 1991, 1993 Aubrey Jaffer. +;;; Copyright (C) 1991, 1993, 1999 Aubrey Jaffer. ; ;Permission to copy this software, to redistribute it, and to use it ;for any purpose is granted, subject to the following restrictions and @@ -20,28 +20,49 @@ ;This file is loaded by random.scm if inexact numbers are supported by ;the implementation. -;;; Fixed sphere and normal functions from: Harald Hanche-Olsen +;;; Sphere and normal functions corrections from: Harald Hanche-Olsen ;;; Generate an inexact real between 0 and 1. -(define random:uniform - (letrec ((random:chunks/float ; how many chunks fill an inexact? - (letrec ((random:size-float - (lambda (l x) - (cond ((= 1.0 (+ 1 x)) l) - ((= 4 l) l) - (else (random:size-float (+ l 1) (/ x 256.0))))))) - (random:size-float 0 1.0))) - - (random:uniform-chunk - (lambda (n state) - (if (= 1 n) - (/ (exact->inexact (random:chunk state)) - 256.0) - (/ (+ (random:uniform-chunk (- n 1) state) - (exact->inexact (random:chunk state))) - 256.0))))) - (lambda (state) - (random:uniform-chunk random:chunks/float state)))) +(define random:uniform1 + ; how many chunks fill an inexact? + (do ((random:chunks/float 0 (+ 1 random:chunks/float)) + (smidgen 1.0 (/ smidgen 256.0))) + ((or (= 1.0 (+ 1 smidgen)) (= 4 random:chunks/float)) + (lambda (state) + (do ((cnt random:chunks/float (+ -1 cnt)) + (uni (/ (random:chunk state) 256.0) + (/ (+ uni (random:chunk state)) 256.0))) + ((= 1 cnt) uni)))))) + + +;;@args +;;@args state +;;Returns an uniformly distributed inexact real random number in the +;;range between 0 and 1. +(define (random:uniform . args) + (random:uniform1 (if (null? args) *random-state* (car args)))) + + +;;@args +;;@args state +;;Returns an inexact real in an exponential distribution with mean 1. For +;;an exponential distribution with mean @var{u} use +;;@w{@code{(* @var{u} (random:exp))}}. +(define (random:exp . args) + (- (log (random:uniform1 (if (null? args) *random-state* (car args)))))) + + +;;@args +;;@args state +;;Returns an inexact real in a normal distribution with mean 0 and +;;standard deviation 1. For a normal distribution with mean @var{m} and +;;standard deviation @var{d} use +;;@w{@code{(+ @var{m} (* @var{d} (random:normal)))}}. +(define (random:normal . args) + (let ((vect (make-vector 1))) + (apply random:normal-vector! vect args) + (vector-ref vect 0))) + ;;; If x and y are independent standard normal variables, then with ;;; x=r*cos(t), y=r*sin(t), we find that t is uniformly distributed @@ -49,6 +70,10 @@ ;;; 1-exp(-r^2/2). This latter means that u=exp(-r^2/2) is uniformly ;;; distributed on [0,1], so r=sqrt(-2 log u) can be used to generate r. +;;@args vect +;;@args vect state +;;Fills @1 with inexact real random numbers which are independent +;;and standard normally distributed (i.e., with mean 0 and variance 1). (define (random:normal-vector! vect . args) (let ((state (if (null? args) *random-state* (car args))) (sum2 0)) @@ -57,39 +82,44 @@ (set! sum2 (+ sum2 (* x x)))))) (do ((n (- (vector-length vect) 1) (- n 2))) ((negative? n) sum2) - (let ((t (* 6.28318530717958 (random:uniform state))) - (r (sqrt (* -2 (log (random:uniform state)))))) + (let ((t (* 6.28318530717958 (random:uniform1 state))) + (r (sqrt (* -2 (log (random:uniform1 state)))))) (do! n (* r (cos t))) (if (positive? n) (do! (- n 1) (* r (sin t))))))))) -(define random:normal - (let ((vect (make-vector 1))) - (lambda args - (apply random:normal-vector! vect args) - (vector-ref vect 0)))) ;;; For the uniform distibution on the hollow sphere, pick a normal ;;; family and scale. +;;@args vect +;;@args vect state +;;Fills @1 with inexact real random numbers the sum of whose +;;squares is less than 1.0. Thinking of @1 as coordinates in +;;space of dimension @var{n} = @code{(vector-length @1)}, the +;;coordinates are uniformly distributed within the unit @var{n}-shere. +;;The sum of the squares of the numbers is returned. (define (random:hollow-sphere! vect . args) (let ((ms (sqrt (apply random:normal-vector! vect args)))) (do ((n (- (vector-length vect) 1) (- n 1))) ((negative? n)) (vector-set! vect n (/ (vector-ref vect n) ms))))) + ;;; For the uniform distribution on the solid sphere, note that in ;;; this distribution the length r of the vector has cumulative ;;; distribution r^n; i.e., u=r^n is uniform [0,1], so r can be ;;; generated as r=u^(1/n). +;;@args vect +;;@args vect state +;;Fills @1 with inexact real random numbers the sum of whose +;;squares is equal to 1.0. Thinking of @1 as coordinates in space +;;of dimension n = @code{(vector-length @1)}, the coordinates are +;;uniformly distributed over the surface of the unit n-shere. (define (random:solid-sphere! vect . args) (apply random:hollow-sphere! vect args) - (let ((r (expt (random:uniform (if (null? args) *random-state* (car args))) + (let ((r (expt (random:uniform1 (if (null? args) *random-state* (car args))) (/ (vector-length vect))))) (do ((n (- (vector-length vect) 1) (- n 1))) ((negative? n)) (vector-set! vect n (* r (vector-ref vect n)))))) - -(define (random:exp . args) - (let ((state (if (null? args) *random-state* (car args)))) - (- (log (random:uniform state))))) diff --git a/random.scm b/random.scm index d22388e..dc4c3fb 100644 --- a/random.scm +++ b/random.scm @@ -1,5 +1,5 @@ ;;;; "random.scm" Pseudo-Random number generator for scheme. -;;; Copyright (C) 1991, 1993 Aubrey Jaffer. +;;; Copyright (C) 1991, 1993, 1998, 1999 Aubrey Jaffer. ; ;Permission to copy this software, to redistribute it, and to use it ;for any purpose is granted, subject to the following restrictions and @@ -20,77 +20,120 @@ (require 'byte) (require 'logical) -(define (make-rng seed) - (define mutex #f) - (define idx 0) - (define idy 0) - (define sta (make-bytes 256)) - ; initialize state - (do ((idx #xff (+ -1 idx))) - ((negative? idx)) - (byte-set! sta idx idx)) - - (if (number? seed) - (set! seed (number->string seed))) - - ; merge seed into state - (do ((idx 0 (+ 1 idx)) - (kdx 0 (modulo (+ 1 kdx) seed-len)) - (seed-len (bytes-length seed))) - ((>= idx 256) (set! idy 0)) - (let ((swp (byte-ref sta idx))) - (set! idy (logand #xff (+ idy (byte-ref seed kdx) swp))) - (byte-set! sta idx (byte-ref sta idy)) - (byte-set! sta idy swp))) - ; spew - (lambda () - (if mutex (slib:error "random state called reentrantly")) - (set! mutex #t) - (set! idx (logand #xff (+ 1 idx))) - (let ((xtm (byte-ref sta idx))) - (set! idy (logand #xff (+ idy xtm))) - (let ((ytm (byte-ref sta idy))) - (byte-set! sta idy xtm) - (byte-set! sta idx ytm) - (let ((ans (byte-ref sta (logand #xff (+ ytm xtm))))) - (set! mutex #f) - ans))))) - -(define *random-state* - (make-rng "http://swissnet.ai.mit.edu/~jaffer/SLIB.html")) - ;;; random:chunk returns an integer in the range of 0 to 255. -(define (random:chunk v) (v)) +(define (random:chunk sta) + (cond ((positive? (byte-ref sta 258)) + (byte-set! sta 258 0) + (slib:error "random state called reentrantly"))) + (byte-set! sta 258 1) + (let* ((idx (logand #xff (+ 1 (byte-ref sta 256)))) + (xtm (byte-ref sta idx)) + (idy (logand #xff (+ (byte-ref sta 257) xtm)))) + (byte-set! sta 256 idx) + (byte-set! sta 257 idy) + (let ((ytm (byte-ref sta idy))) + (byte-set! sta idy xtm) + (byte-set! sta idx ytm) + (let ((ans (byte-ref sta (logand #xff (+ ytm xtm))))) + (byte-set! sta 258 0) + ans)))) + -(define (random:random modu . args) +;;@args n +;;@args n state +;;Accepts a positive integer or real @1 and returns a number of the +;;same type between zero (inclusive) and @1 (exclusive). The values +;;returned by @0 are uniformly distributed from 0 to @1. +;; +;;The optional argument @var{state} must be of the type returned by +;;@code{(seed->random-state)} or @code{(make-random-state)}. It defaults +;;to the value of the variable @code{*random-state*}. This object is used +;;to maintain the state of the pseudo-random-number generator and is +;;altered as a side effect of calls to @code{random}. +(define (random modu . args) (let ((state (if (null? args) *random-state* (car args)))) (if (exact? modu) - (let ((bitlen (integer-length (+ -1 modu)))) - (do ((bln bitlen (+ -8 bln)) - (rbs 0 (+ (ash rbs 8) (random:chunk state)))) - ((<= bln 7) - (modulo - (if (zero? bln) rbs - (+ (ash rbs bln) - (logand (bit-field (random:chunk state) 0 bln)))) - modu)))) + (letrec ((bitlen (integer-length (+ -1 modu))) + (rnd (lambda () + (do ((bln bitlen (+ -8 bln)) + (rbs 0 (+ (ash rbs 8) (random:chunk state)))) + ((<= bln 7) + (set! rbs (+ (ash rbs bln) + (bit-field (random:chunk state) 0 bln))) + (and (< rbs modu) rbs)))))) + (do ((ans (rnd) (rnd))) (ans ans))) + (* (random:uniform1 state) modu)))) - (* (random:uniform state) modu)))) +(define random:random random) ;;;random:uniform is in randinex.scm. It is needed only if inexact is ;;;supported. + +;;@defvar *random-state* +;;Holds a data structure that encodes the internal state of the +;;random-number generator that @code{random} uses by default. The nature +;;of this data structure is implementation-dependent. It may be printed +;;out and successfully read back in, but may or may not function correctly +;;as a random-number state object in another implementation. +;;@end defvar + + +;;@args state +;;Returns a new copy of argument @1. +;; +;;@args +;;Returns a new copy of @code{*random-state*}. +(define (copy-random-state . sta) + (copy-string (if (null? sta) *random-state* (car sta)))) + + +;;@body +;;Returns a new object of type suitable for use as the value of the +;;variable @code{*random-state*} or as a second argument to @code{random}. +;;The number or string @1 is used to initialize the state. If +;;@0 is called twice with arguments which are +;;@code{equal?}, then the returned data structures will be @code{equal?}. +;;Calling @0 with unequal arguments will nearly +;;always return unequal states. +(define (seed->random-state seed) + (define sta (make-bytes (+ 3 256) 0)) + (if (number? seed) (set! seed (number->string seed))) + ; initialize state + (do ((idx #xff (+ -1 idx))) + ((negative? idx)) + (byte-set! sta idx idx)) + ; merge seed into state + (do ((i 0 (+ 1 i)) + (j 0 (modulo (+ 1 j) seed-len)) + (seed-len (bytes-length seed)) + (k 0)) + ((>= i 256)) + (let ((swp (byte-ref sta i))) + (set! k (logand #xff (+ k (byte-ref seed j) swp))) + (byte-set! sta i (byte-ref sta k)) + (byte-set! sta k swp))) + sta) + + +;;@args +;;@args obj +;;Returns a new object of type suitable for use as the value of the +;;variable @code{*random-state*} or as a second argument to @code{random}. +;;If the optional argument @var{obj} is given, it should be a printable +;;Scheme object; the first 50 characters of its printed representation +;;will be used as the seed. Otherwise the value of @code{*random-state*} +;;is used as the seed. (define (make-random-state . args) - (let ((seed (if (null? args) - (do ((bts (make-bytes 10)) - (idx 0 (+ 1 idx))) - ((>= idx 10) bts) - (byte-set! bts idx (random:random 256))) - (let () - (require 'object->string) - (object->limited-string (car args) 20))))) - (make-rng seed))) + (let ((seed (if (null? args) *random-state* (car args)))) + (cond ((string? seed)) + ((number? seed) (set! seed (number->string seed))) + (else (let () + (require 'object->string) + (set! seed (object->limited-string seed 50))))) + (seed->random-state seed))) -(define random random:random) +(define *random-state* + (make-random-state "http://swissnet.ai.mit.edu/~jaffer/SLIB.html")) (provide 'random) ;to prevent loops (if (provided? 'inexact) (require 'random-inexact)) diff --git a/rdms.scm b/rdms.scm index 9f176f9..e0dbd3c 100644 --- a/rdms.scm +++ b/rdms.scm @@ -79,6 +79,7 @@ (not (negative? x)))) integer #f) + (number #f number? number #f) (expression #f #f expression #f) (boolean #f boolean? boolean #f) (symbol #f symbol? symbol #f) @@ -252,6 +253,7 @@ (primary-limit 1) (column-name-alist '()) (column-foreign-list '()) + (column-foreign-check-list '()) (column-domain-list '()) (column-type-list '()) (export-alist '()) @@ -283,24 +285,26 @@ (set! column-domain-list (cons column-domain column-domain-list)) (set! column-foreign-list - (cons - (let ((foreign-name - (row-ref dom:row domains:foreign-pos))) - (cond - ((or (not foreign-name) - (eq? foreign-name table-name)) #f) - (else - (let* ((tab (open-table foreign-name #f)) - (p? (and tab (tab 'get 1)))) - (cond - ((not tab) - (rdms:error "foreign key table missing for:" - foreign-name)) - ((not (= (tab 'primary-limit) 1)) - (rdms:error "foreign key table wrong type:" - foreign-name)) - (else p?)))))) - column-foreign-list)))) + (cons (let ((foreign-name + (row-ref dom:row domains:foreign-pos))) + (and (not (eq? foreign-name table-name)) + foreign-name)) + column-foreign-list)) + (set! column-foreign-check-list + (cons + (let ((foreign-name (car column-foreign-list))) + (and foreign-name + (let* ((tab (open-table foreign-name #f)) + (p? (and tab (tab 'get 1)))) + (cond + ((not tab) + (rdms:error "foreign key table missing for:" + foreign-name)) + ((not (= (tab 'primary-limit) 1)) + (rdms:error "foreign key table wrong type:" + foreign-name)) + (else p?))))) + column-foreign-check-list)))) (else (rdms:error "missing domain for column:" ci column-name))) (cond @@ -409,7 +413,7 @@ (rdms:error "foreign key missing:" table-name column-name value)))) cirs dirs row column-name-alist column-domain-list - column-foreign-list) + column-foreign-check-list) (cond ((and uir (not (uir row))) (rdms:error "violated user integrity rule:" row))))) diff --git a/recobj.scm b/recobj.scm new file mode 100644 index 0000000..36ab6d2 --- /dev/null +++ b/recobj.scm @@ -0,0 +1,55 @@ +;;; "recobj.scm" Records implemented as objects. +;;;From: whumeniu@datap.ca (Wade Humeniuk) + +(require 'object) +(require 'common-list-functions) + +(define record-type-name (make-generic-method)) +(define record-accessor (make-generic-method)) +(define record-modifier (make-generic-method)) +(define record? (make-generic-predicate)) +(define record-constructor (make-generic-method)) + +(define (make-record-type type-name field-names) + (define self (make-object)) + + (make-method! self record-type-name + (lambda (self) + type-name)) + (make-method! self record-accessor + (lambda (self field-name) + (let ((index (comlist:position field-name field-names))) + (if (not index) + (slib:error "record-accessor: invalid field-name argument." + field-name)) + (lambda (obj) + (record-accessor obj index))))) + + (make-method! self record-modifier + (lambda (self field-name) + (let ((index (comlist:position field-name field-names))) + (if (not index) + (slib:error "record-accessor: invalid field-name argument." + field-name)) + (lambda (obj newval) + (record-modifier obj index newval))))) + + (make-method! self record? (lambda (self) #t)) + + (make-method! self record-constructor + (lambda (class . field-values) + (let ((values (apply vector field-values))) + (define self (make-object)) + (make-method! self record-accessor + (lambda (self index) + (vector-ref values index))) + (make-method! self record-modifier + (lambda (self index newval) + (vector-set! values index newval))) + (make-method! self record-type-name + (lambda (self) (record-type-name class))) + self))) + self) + +(provide 'record-object) +(provide 'record) \ No newline at end of file diff --git a/require.scm b/require.scm index ebaf49f..a578349 100644 --- a/require.scm +++ b/require.scm @@ -17,7 +17,7 @@ ;promotional, or sales literature without prior written consent in ;each case. -(define *SLIB-VERSION* "2c3") +(define *SLIB-VERSION* "2c7") ;;; Standardize msdos -> ms-dos. (define software-type @@ -31,44 +31,43 @@ (else ""))) (define *load-pathname* #f) -(define program-vicinity - (let ((*vicinity-suffix* +(define vicinity:suffix? + (let ((suffi (case (software-type) - ((AMIGA) '(#\: #\/)) + ((AMIGA) '(#\: #\/)) + ((MACOS THINKC) '(#\:)) ((MS-DOS WINDOWS ATARIST OS/2) '(#\\ #\/)) - ((MACOS THINKC) '(#\:)) - ((NOSVE) '(#\: #\.)) - ((UNIX COHERENT) '(#\/)) - ((VMS) '(#\: #\]))))) - (lambda () - (if *load-pathname* - (let loop ((i (- (string-length *load-pathname*) 1))) - (cond ((negative? i) "") - ((memv (string-ref *load-pathname* i) *vicinity-suffix*) - (substring *load-pathname* 0 (+ i 1))) - (else (loop (- i 1))))) - (slib:error "Not loading but called" 'program-vicinity))))) + ((NOSVE) '(#\: #\.)) + ((UNIX COHERENT) '(#\/)) + ((VMS) '(#\: #\]))))) + (lambda (chr) (memv chr suffi)))) +(define (program-vicinity) + (if *load-pathname* + (let loop ((i (- (string-length *load-pathname*) 1))) + (cond ((negative? i) "") + ((vicinity:suffix? (string-ref *load-pathname* i)) + (substring *load-pathname* 0 (+ i 1))) + (else (loop (- i 1))))) + (slib:error "Not loading but called" 'program-vicinity))) (define sub-vicinity (case (software-type) - ((VMS) - (lambda - (vic name) - (let ((l (string-length vic))) - (if (or (zero? (string-length vic)) - (not (char=? #\] (string-ref vic (- l 1))))) - (string-append vic "[" name "]") - (string-append (substring vic 0 (- l 1)) - "." name "]"))))) - (else - (let ((*vicinity-suffix* - (case (software-type) - ((NOSVE) ".") - ((UNIX COHERENT AMIGA) "/") - ((MACOS THINKC) ":") - ((MS-DOS WINDOWS ATARIST OS/2) "\\")))) - (lambda (vic name) - (string-append vic name *vicinity-suffix*)))))) + ((VMS) (lambda + (vic name) + (let ((l (string-length vic))) + (if (or (zero? (string-length vic)) + (not (char=? #\] (string-ref vic (- l 1))))) + (string-append vic "[" name "]") + (string-append (substring vic 0 (- l 1)) + "." name "]"))))) + (else (let ((*vicinity-suffix* + (case (software-type) + ((NOSVE) ".") + ((MACOS THINKC) ":") + ((MS-DOS WINDOWS ATARIST OS/2) "\\") + ((UNIX COHERENT AMIGA) "/")))) + (lambda (vic name) + (string-append vic name *vicinity-suffix*)))))) (define (make-vicinity ) ) diff --git a/root.scm b/root.scm index 3c764a6..d561af6 100644 --- a/root.scm +++ b/root.scm @@ -149,3 +149,69 @@ df+sqrt-H df-sqrt-H))))) (loop next-z (f next-z)))))))) + +(define (secant:find-root-1 f x0 x1 prec must-bracket?) + (letrec ((stop? + (cond ((procedure? prec) prec) + ((and (integer? prec) (negative? prec)) + (lambda (x0 x1 fmax count) + (>= count (- prec)))) + (else + (lambda (x0 f0 x1 f1 count) + (and (< (abs f0) prec) + (< (abs f1) prec)))))) + (bracket-iter + (lambda (xlo flo glo xhi fhi ghi count) + (define (step xnew fnew) + (cond ((or (= xnew xlo) + (= xnew xhi)) + (let ((xmid (+ xlo (* 1/2 (- xhi xlo))))) + (if (= xnew xmid) + xmid + (step xmid (f xmid))))) + ((positive? fnew) + (bracket-iter xlo flo (if glo (* 0.5 glo) 1) + xnew fnew #f + (+ count 1))) + (else + (bracket-iter xnew fnew #f + xhi fhi (if ghi (* 0.5 ghi) 1) + (+ count 1))))) + (if (stop? xlo flo xhi fhi count) + (if (> (abs flo) (abs fhi)) xhi xlo) + (let* ((fflo (if glo (* glo flo) flo)) + (ffhi (if ghi (* ghi fhi) fhi)) + (del (- (/ fflo (- ffhi fflo)))) + (xnew (+ xlo (* del (- xhi xlo)))) + (fnew (f xnew))) + (step xnew fnew)))))) + (let ((f0 (f x0)) + (f1 (f x1))) + (cond ((<= f0 0 f1) + (bracket-iter x0 f0 #f x1 f1 #f 0)) + ((<= f1 0 f0) + (bracket-iter x1 f1 #f x0 f0 #f 0)) + (must-bracket? #f) + (else + (let secant-iter ((x0 x0) + (f0 f0) + (x1 x1) + (f1 f1) + (count 0)) + (cond ((stop? x0 f0 x1 f1 count) + (if (> (abs f0) (abs f1)) x1 x0)) + ((<= f0 0 f1) + (bracket-iter x0 f0 #f x1 f1 #f count)) + ((>= f0 0 f1) + (bracket-iter x1 f1 #f x0 f0 #f count)) + ((= f0 f1) #f) + (else + (let* ((xnew (+ x0 (* (- (/ f0 (- f1 f0))) (- x1 x0)))) + (fnew (f xnew)) + (fmax (max (abs f1) (abs fnew)))) + (secant-iter x1 f1 xnew fnew (+ count 1))))))))))) + +(define (secant:find-root f x0 x1 prec) + (secant:find-root-1 f x0 x1 prec #f)) +(define (secant:find-bracketed-root f x0 x1 prec) + (secant:find-root-1 f x0 x1 prec #t)) diff --git a/sc4sc3.scm b/sc4sc3.scm index a120c5d..9687856 100644 --- a/sc4sc3.scm +++ b/sc4sc3.scm @@ -28,7 +28,7 @@ (and (pair? fast) (let ((fast (cdr fast))) (or (null? fast) - (and (pair? fast) + (and (pair? fast) (let ((fast (cdr fast)) (slow (cdr slow))) (and (not (eq? fast slow)) diff --git a/scanf.scm b/scanf.scm index e4fc919..6d3ee6e 100644 --- a/scanf.scm +++ b/scanf.scm @@ -160,7 +160,7 @@ (let* ((dot? #f) (mantissa (read-word width - (lambda (c) + (lambda (c) (not (or (char-numeric? c) (cond (dot? #f) ((eqv? #\. c) diff --git a/scheme2c.init b/scheme2c.init index 0743113..233285a 100644 --- a/scheme2c.init +++ b/scheme2c.init @@ -1,22 +1,7 @@ -;"scheme2c.init" Initialisation for SLIB for Scheme->C on Sun -*-scheme-*- -;Copyright 1991, 1992, 1993, 1994, 1997 Aubrey Jaffer -;Copyright 1991 David Love -; -;Permission to copy this software, to redistribute it, and to use it -;for any purpose is granted, subject to the following restrictions and -;understandings. -; -;1. Any copy made of this software must include this copyright notice -;in full. -; -;2. I have made no warrantee or representation that the operation of -;this software will be error-free, and I am under no obligation to -;provide any services, by way of maintenance, update, or otherwise. -; -;3. In conjunction with products arising from the use of this -;material, there shall be no use of my name in any advertising, -;promotional, or sales literature without prior written consent in -;each case. +;;; "scheme2c.init" Initialisation for SLIB for Scheme->C on Sun -*-scheme-*- +;;; Authors: David Love and Aubrey Jaffer +;;; +;;; This code is in the public domain. ;;Modified by David Love (d.love@daresbury.ac.uk) 10/12/91 ;; NB this is for the 01nov91 (and, presumably, later ones, @@ -36,6 +21,12 @@ (define (scheme-implementation-type) 'Scheme->C) +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) #f) + ;;; (scheme-implementation-version) should return a string describing ;;; the version the scheme implementation loading this file. diff --git a/scheme48.init b/scheme48.init index 6df37b8..8258d97 100644 --- a/scheme48.init +++ b/scheme48.init @@ -1,21 +1,7 @@ ;;;"scheme48.init" Initialisation for SLIB for Scheme48 -*-scheme-*- -;;; Copyright (C) 1992, 1993, 1994, 1995, 1997 Aubrey Jaffer. -; -;Permission to copy this software, to redistribute it, and to use it -;for any purpose is granted, subject to the following restrictions and -;understandings. -; -;1. Any copy made of this software must include this copyright notice -;in full. -; -;2. I have made no warrantee or representation that the operation of -;this software will be error-free, and I am under no obligation to -;provide any services, by way of maintenance, update, or otherwise. -; -;3. In conjunction with products arising from the use of this -;material, there shall be no use of my name in any advertising, -;promotional, or sales literature without prior written consent in -;each case. +;;; Author: Aubrey Jaffer +;;; +;;; This code is in the public domain. ;;; If you know the magic incantation to make a "," command available ;;; as a scheme procedure, you can make a nifty slib function to do @@ -32,6 +18,13 @@ (define (scheme-implementation-type) 'Scheme48) +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) + "http://www.neci.nj.nec.com/homepages/kelsey.html") + ;;; (scheme-implementation-version) should return a string describing ;;; the version of the scheme implementation loading this file. @@ -39,9 +32,7 @@ (cond ((= -86400 (modulo -2177452800 -86400)) (display "scheme48-0.36 has been superseded by") (newline) - (display "ftp@ftp-swiss.ai.mit.edu:pub/s48/scheme48-0.46.tgz") - (newline) - (display "ftp://ftp-swiss.ai.mit.edu/pub/s48/scheme48-0.46.tgz") + (display "http://swissnet.ai.mit.edu/ftpdir/s48/scheme48-0.46.tgz") (newline) (lambda () "0.36")) (else (lambda () "0.46")))) diff --git a/schmooz.scm b/schmooz.scm index 9664ac3..a09f3df 100644 --- a/schmooz.scm +++ b/schmooz.scm @@ -1,4 +1,4 @@ -;;; schmooz.scm: Program for extracting texinfo comments from Scheme. +;;; "schmooz.scm" Program for extracting texinfo comments from Scheme. ;;; Copyright (C) 1998 Radey Shouman and Aubrey Jaffer. ; ;Permission to copy this software, to redistribute it, and to use it @@ -17,7 +17,7 @@ ;promotional, or sales literature without prior written consent in ;each case. -;;$Header: /usr/local/cvsroot/slib/schmooz.scm,v 1.7 1998/09/10 20:34:26 radey Exp $ +;;$Header: /usr/local/cvsroot/slib/schmooz.scm,v 1.12 1999/10/11 03:36:29 jaffer Exp $ ;;$Name: $ ;;; REPORT an error or warning @@ -75,10 +75,10 @@ (display a *derived-txi*)) ((string? a) (display a *derived-txi*) - #+f - (cond ((string-index a #\nl) - (set! *output-line* (+ 1 *output-line*)) - (report "newline in string" a)))) +; (cond ((string-index a #\newline) +; (set! *output-line* (+ 1 *output-line*)) +; (report "newline in string" a))) + ) (else (display a *derived-txi*)))) args)) @@ -97,7 +97,7 @@ (if close (slib:error close "not found in" line) (cons iend - (reverse + (reverse (if (> iend istrt) (cons (substring line istrt iend) args) args))))) @@ -127,7 +127,7 @@ (tok1 (+ 1 istrt) #\} (lambda (c) (eqv? c #\,)) #f)) ((eqv? #\( (string-ref line istrt)) (tok1 (+ 1 istrt) #\) char-whitespace? ".")) - (else + (else (tok1 istrt #f char-whitespace? #f))))) @@ -150,15 +150,15 @@ (res '())) (cond ((>= i (string-length line)) (list - (apply string-append - (reverse + (apply string-append + (reverse (cons (substring line istrt (string-length line)) res))))) ((char=? #\@ (string-ref line i)) (let* ((w (get-word i)) (symw (string->symbol w))) (cond ((eq? '@cname symw) - (let ((args (parse-args + (let ((args (parse-args line (+ i (string-length w))))) (cond ((and args (= 2 (length args))) (loop (car args) (car args) @@ -234,7 +234,7 @@ (else (slib:error 'schmooz "doesn't look like definition" sexp)))) ;; Generate alist of argument macro definitions. -;; If ARGS is a symbol or string, then the definitions will be used in a +;; If ARGS is a symbol or string, then the definitions will be used in a ;; `defvar', if ARGS is a (possibly improper) list, they will be used in ;; a `defun'. (define (scheme-args->macros args) @@ -250,7 +250,7 @@ (args (if fun? (cdr args) '()))) (let ((m0 (string-append (if fun? "@code{" "@var{") (arg->string arg0) "}"))) - (append + (append (list (cons '@arg0 m0) (cons '@0 m0)) (let recur ((i 1) (args args)) @@ -262,7 +262,7 @@ (append (arg->macros (car args) i) (recur (+ i 1) (cdr args)))))))))) -;; Extra processing to be done for @dfn +;; Extra processing to be done for @dfn (define (out-cindex arg) (out 0 "@cindex " arg)) @@ -285,7 +285,7 @@ args)) " @dots{}")) ((pair? args) - (out CONTLINE " " + (out CONTLINE " " (if (or (eq? '... (car args)) (equal? "..." (car args))) "@dots{}" @@ -309,7 +309,7 @@ ((@dfn) (out-cindex (cadr l))) ((@args) - (out-header + (out-header (cons (car args) (cdr l)) (cdr ops))))) (cdr subl))) @@ -348,7 +348,9 @@ (texi? (filename:match-ci?? "*??texi"))) (lambda (filename) (or (txi-file? filename) (tex? filename) - (texi? filename)))))) + (texi? filename))))) + (txi->scm (filename:substitute?? "*txi" "*scm")) + (scm->txi (filename:substitute?? "*scm" "*txi"))) (define (schmooz-texi-file file) (call-with-input-file file (lambda (port) @@ -358,10 +360,8 @@ (let ((fname #f)) (cond ((not (eqv? 1 (fscanf port " %s" fname)))) ((not (txi-file? fname))) - ((not (file-exists? - (replace-suffix fname "txi" "scm")))) - (else (schmooz - (replace-suffix fname "txi" "scm"))))))))) + ((not (file-exists? (txi->scm fname)))) + (else (schmooz (txi->scm fname))))))))) (define (schmooz-scm-file file txi-name) (display "Schmoozing ") (write file) (display " -> ") (write txi-name) (newline) @@ -378,7 +378,7 @@ (define sl (string-length file)) (cond ((scheme-file? file) (schmooz-scm-file - file (replace-suffix file "scm" "txi"))) + file (scm->txi file))) ((texi-file? file) (schmooz-texi-file file)))) files)))) @@ -407,19 +407,13 @@ (read-cmt-line)) (else (read-line *scheme-source*)))) - (define (read-newline) - (if (char=? #\cr (read-char *scheme-source*)) - (if (char=? #\nl (peek-char *scheme-source*)) - (read-char *scheme-source*) - (report "stranded #\\cr")))) - (define (lp c) (cond ((eof-object? c) (cond ((pair? doc-lines) (report "No definition found for @body doc lines" (reverse doc-lines))))) - ((memv c '(#\cr #\nl)) - (read-newline) + ((eqv? c #\newline) + (read-char *scheme-source*) (set! *output-line* (+ 1 *output-line*)) (newline *derived-txi*) (lp (peek-char *scheme-source*))) @@ -428,20 +422,25 @@ (lp (peek-char *scheme-source*))) ((char=? c #\;) (c-cmt c)) - (else + (else (sx)))) (define (sx) (let* ((s1 (read *scheme-source*)) - (ss ;Read all forms separated only by single newlines. - (let recur () - (case (peek-char *scheme-source*) - ((#\cr) (read-char *scheme-source*) (recur)) - ((#\nl) (read-char *scheme-source*) - (if (eqv? #\( (peek-char *scheme-source*)) - (cons (read *scheme-source*) (recur)) - '())) - (else '()))))) + ;;Read all forms separated only by single newlines + ;;and trailing whitespace. + (ss (let recur () + (let ((c (peek-char *scheme-source*))) + (cond ((eqv? c #\newline) + (read-char *scheme-source*) + (if (eqv? #\( (peek-char *scheme-source*)) + (let ((s (read *scheme-source*))) + (cons s (recur))) + '())) + ((char-whitespace? c) + (read-char *scheme-source*) + (recur)) + (else '())))))) (cond ((eof-object? s1)) (else (schmooz-top s1 ss (reverse doc-lines) doc-args) @@ -453,12 +452,12 @@ (let ((subl (substitute-macs line '()))) (newline *derived-txi*) (display (car subl) *derived-txi*) - (for-each + (for-each (lambda (l) (case (car l) ((@dfn) (out-cindex (cadr l))) - (else + (else (report "bad macro" line)))) (cdr subl)))) @@ -474,8 +473,8 @@ (tok (tok1 line))) (cond ((or (string=? tok "@body") (string=? tok "@text")) - (set! doc-lines - (cons (skip-ws line (string-length tok)) + (set! doc-lines + (cons (skip-ws line (string-length tok)) doc-lines)) (body-cmt (peek-char *scheme-source*))) ((string=? tok "@args") @@ -504,14 +503,14 @@ ((eqv? #\; c) (set! doc-lines (cons (read-cmt-line) doc-lines)) (body-cmt (peek-char *scheme-source*))) - ((memv c '(#\nl #\cr)) - (read-newline) + ((eqv? c #\newline) + (read-char *scheme-source*) (lp (peek-char *scheme-source*))) ;; Allow whitespace before ; in doc comments. ((char-whitespace? c) (read-char *scheme-source*) (body-cmt (peek-char *scheme-source*))) - (else + (else (lp (peek-char *scheme-source*))))) ;;Comments incorporated in generated Texinfo files. @@ -523,15 +522,15 @@ (out-cmt (read-cmt-line)) ;;(out-c-cmt (car ls)) (doc-cmt (peek-char *scheme-source*))) - ((memv c '(#\nl #\cr)) - (read-newline) + ((eqv? c #\newline) + (read-char *scheme-source*) (newline *derived-txi*) (lp (peek-char *scheme-source*))) ;; Allow whitespace before ; in doc comments. ((char-whitespace? c) (read-char *scheme-source*) (doc-cmt (peek-char *scheme-source*))) - (else + (else (newline *derived-txi*) (lp (peek-char *scheme-source*))))) (lp (peek-char *scheme-source*)))) @@ -559,10 +558,10 @@ (let ((a (def->args (car ss)))) (loop (cdr ss) (if args - (if a + (if a (cons a smatch) smatch) - (if a + (if a smatch (cons (def->var-name (car ss)) smatch))))))))))))) @@ -571,7 +570,8 @@ (define (schmooz-top sexp1 sexps doc proc-args) (cond ((not (pair? sexp1))) ((pair? sexps) - (schmooz-top-doc-begin sexp1 sexps doc proc-args) + (if (pair? doc) + (schmooz-top-doc-begin sexp1 sexps doc proc-args)) (set! doc '())) (else (case (car sexp1) @@ -599,7 +599,7 @@ (schmooz-var (car sexp1) (cadr sexp1) doc '()) (set! doc '())))))))))) (or (null? doc) - (report + (report "SCHMOOZ: no definition found for Texinfo documentation" doc sexp)) (set! *procedure* #f)) diff --git a/scsh.init b/scsh.init index ac6d1b9..04d4818 100644 --- a/scsh.init +++ b/scsh.init @@ -1,4 +1,7 @@ -;"scsh.init" Initialisation for SLIB for Scsh 0.5.1 -*-scheme-*- +;;; "scsh.init" Initialisation for SLIB for Scsh 0.5.1 -*-scheme-*- +;;; Author: Aubrey Jaffer +;;; +;;; This code is in the public domain. ;;; (software-type) should be set to the generic operating system type. ;;; UNIX, VMS, MACOS, AMIGA and MS-DOS are supported. @@ -10,6 +13,13 @@ (define (scheme-implementation-type) 'Scsh) +;;; (scheme-implementation-home-page) should return a (string) URL +;;; (Uniform Resource Locator) for this scheme implementation's home +;;; page; or false if there isn't one. + +(define (scheme-implementation-home-page) + "http://swissnet.ai.mit.edu/scsh/") + ;;; (scheme-implementation-version) should return a string describing ;;; the version the scheme implementation loading this file. diff --git a/sierpinski.scm b/sierpinski.scm index a4de2d6..6300e8a 100644 --- a/sierpinski.scm +++ b/sierpinski.scm @@ -10,7 +10,7 @@ (lambda (x y) (if (not (and (<= 0 x max-coordinate) (<= 0 y max-coordinate))) - (slib:error 'sierpinski-index + (slib:error 'sierpinski-index "Coordinate exceeds specified maximum.") ; ; The following two mutually recursive procedures diff --git a/slib.info b/slib.info new file mode 100644 index 0000000..8e62273 --- /dev/null +++ b/slib.info @@ -0,0 +1,11240 @@ +This is Info file slib.info, produced by Makeinfo version 1.68 from the +input file slib.texi. + +INFO-DIR-SECTION The Algorithmic Language Scheme +START-INFO-DIR-ENTRY +* SLIB: (slib). Scheme Library +END-INFO-DIR-ENTRY + + This file documents SLIB, the portable Scheme library. + + Copyright (C) 1993 Todd R. Eigenschink +Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999 Aubrey Jaffer | + + Permission is granted to make and distribute verbatim copies of this +manual provided the copyright notice and this permission notice are +preserved on all copies. + + Permission is granted to copy and distribute modified versions of this +manual under the conditions for verbatim copying, provided that the +entire resulting derived work is distributed under the terms of a +permission notice identical to this one. + + Permission is granted to copy and distribute translations of this +manual into another language, under the above conditions for modified +versions, except that this permission notice may be stated in a +translation approved by the author. + + +File: slib.info, Node: Top, Next: The Library System, Prev: (dir), Up: (dir) + +"SLIB" is a portable library for the programming language "Scheme". It | +provides a platform independent framework for using "packages" of | +Scheme procedures and syntax. As distributed, SLIB contains useful +packages for all Scheme implementations. Its catalog can be | +transparently extended to accomodate packages specific to a site, | +implementation, user, or directory. | + +* Menu: + +* The Library System:: How to use and customize. +* Scheme Syntax Extension Packages:: +* Textual Conversion Packages:: +* Mathematical Packages:: +* Database Packages:: +* Other Packages:: +* About SLIB:: Install, etc. +* Index:: + + +File: slib.info, Node: The Library System, Next: Scheme Syntax Extension Packages, Prev: Top, Up: Top + +The Library System +****************** + +* Menu: + +* Feature:: SLIB names. +* Requesting Features:: +* Library Catalogs:: +* Catalog Compilation:: +* Built-in Support:: +* About this manual:: + + +File: slib.info, Node: Feature, Next: Requesting Features, Prev: The Library System, Up: The Library System + +Feature +======= + +SLIB denotes "features" by symbols. SLIB maintains a list of features +supported by the Scheme "session". The set of features provided by a +session may change over time. Some features are properties of the +Scheme implementation being used. The following features detail what +sort of numbers are available from an implementation. + + * 'inexact + + * 'rational + + * 'real + + * 'complex + + * 'bignum + +Other features correspond to the presence of sets of Scheme procedures +or syntax (macros). + + - Function: provided? FEATURE + Returns `#t' if FEATURE is supported by the current Scheme session. + + - Procedure: provide FEATURE + Informs SLIB that FEATURE is supported. Henceforth `(provided? + FEATURE)' will return `#t'. + + (provided? 'foo) => #f + (provide 'foo) + (provided? 'foo) => #t + + +File: slib.info, Node: Requesting Features, Next: Library Catalogs, Prev: Feature, Up: The Library System + +Requesting Features +=================== + +SLIB creates and maintains a "catalog" mapping features to locations of +files introducing procedures and syntax denoted by those features. + +At the beginning of each section of this manual, there is a line like +`(require 'FEATURE)'. The Scheme files comprising SLIB are cataloged +so that these feature names map to the corresponding files. + +SLIB provides a form, `require', which loads the files providing the +requested feature. + + - Procedure: require FEATURE + * If `(provided? FEATURE)' is true, then `require' just returns + an unspecified value. + + * Otherwise, if FEATURE is found in the catalog, then the + corresponding files will be loaded and an unspecified value + returned. + + Subsequently `(provided? FEATURE)' will return `#t'. + + * Otherwise (FEATURE not found in the catalog), an error is + signaled. + +The catalog can also be queried using `require:feature->path'. + + - Function: require:feature->path FEATURE + * If FEATURE is already provided, then returns `#t'. + + * Otherwise, if FEATURE is in the catalog, the path or list of + paths associated with FEATURE is returned. + + * Otherwise, returns `#f'. + + +File: slib.info, Node: Library Catalogs, Next: Catalog Compilation, Prev: Requesting Features, Up: The Library System + +Library Catalogs +================ + +At the start of a session no catalog is present, but is created with the +first catalog inquiry (such as `(require 'random)'). Several sources +of catalog information are combined to produce the catalog: + + * standard SLIB packages. + + * additional packages of interest to this site. + + * packages specifically for the variety of Scheme which this session + is running. + + * packages this user wants to always have available. This catalog + is the file `homecat' in the user's "HOME" directory. + + * packages germane to working in this (current working) directory. + This catalog is the file `usercat' in the directory to which it + applies. One would typically `cd' to this directory before + starting the Scheme session. + +Catalog files consist of one or more "association list"s. In the +circumstance where a feature symbol appears in more than one list, the +latter list's association is retrieved. Here are the supported formats +for elements of catalog lists: + +`(FEATURE . )' + Redirects to the feature named . + +`(FEATURE . "")' + Loads file . + +`(FEATURE source "")' + `slib:load's the Scheme source file . + +`(FEATURE compiled "" ...)' + `slib:load-compiled's the files .... + +The various macro styles first `require' the named macro package, then +just load or load-and-macro-expand as appropriate for the +implementation. + +`(FEATURE defmacro "")' + `defmacro:load's the Scheme source file . + +`(FEATURE macro-by-example "")' + `defmacro:load's the Scheme source file . + +`(FEATURE macro "")' + `macro:load's the Scheme source file . + +`(FEATURE macros-that-work "")' + `macro:load's the Scheme source file . + +`(FEATURE syntax-case "")' + `macro:load's the Scheme source file . + +`(FEATURE syntactic-closures "")' + `macro:load's the Scheme source file . + +Here is an example of a `usercat' catalog. A Program in this directory +can invoke the `run' feature with `(require 'run)'. + + ;;; "usercat": SLIB catalog additions for SIMSYNCH. -*-scheme-*- + + ( + (simsynch . "../synch/simsynch.scm") + (run . "../synch/run.scm") + (schlep . "schlep.scm") + ) + + +File: slib.info, Node: Catalog Compilation, Next: Built-in Support, Prev: Library Catalogs, Up: The Library System + +Catalog Compilation +=================== + +SLIB combines the catalog information which doesn't vary per user into +the file `slibcat' in the implementation-vicinity. Therefore `slibcat' +needs change only when new software is installed or compiled. Because +the actual pathnames of files can differ from installation to +installation, SLIB builds a separate catalog for each implementation it +is used with. + +The definition of `*SLIB-VERSION*' in SLIB file `require.scm' is +checked against the catalog association of `*SLIB-VERSION*' to +ascertain when versions have changed. I recommend that the definition +of `*SLIB-VERSION*' be changed whenever the library is changed. If +multiple implementations of Scheme use SLIB, remember that recompiling +one `slibcat' will fix only that implementation's catalog. + +The compilation scripts of Scheme implementations which work with SLIB +can automatically trigger catalog compilation by deleting `slibcat' or +by invoking a special form of `require': + + - Procedure: require 'new-catalog + This will load `mklibcat', which compiles and writes a new + `slibcat'. + +Another special form of `require' erases SLIB's catalog, forcing it to +be reloaded the next time the catalog is queried. + + - Procedure: require #f + Removes SLIB's catalog information. This should be done before + saving an executable image so that, when restored, its catalog + will be loaded afresh. + +Each file in the table below is descibed in terms of its file-system +independent "vicinity" (*note Vicinity::.). The entries of a catalog +in the table override those of catalogs above it in the table. + +`implementation-vicinity' `slibcat' + This file contains the associations for the packages comprising + SLIB, the `implcat' and the `sitecat's. The associations in the + other catalogs override those of the standard catalog. + +`library-vicinity' `mklibcat.scm' + creates `slibcat'. + +`library-vicinity' `sitecat' + This file contains the associations specific to an SLIB + installation. + +`implementation-vicinity' `implcat' + This file contains the associations specific to an implementation + of Scheme. Different implementations of Scheme should have + different `implementation-vicinity'. + +`implementation-vicinity' `mkimpcat.scm' + if present, creates `implcat'. + +`implementation-vicinity' `sitecat' + This file contains the associations specific to a Scheme + implementation installation. + +`home-vicinity' `homecat' + This file contains the associations specific to an SLIB user. + +`user-vicinity' `usercat' + This file contains associations effecting only those sessions whose + "working directory" is `user-vicinity'. + + +File: slib.info, Node: Built-in Support, Next: About this manual, Prev: Catalog Compilation, Up: The Library System + +Built-in Support +================ + +The procedures described in these sections are supported by all +implementations as part of the `*.init' files or by `require.scm'. + +* Menu: + +* Require:: Module Management +* Vicinity:: Pathname Management +* Configuration:: Characteristics of Scheme Implementation +* Input/Output:: Things not provided by the Scheme specs. +* Legacy:: +* System:: LOADing, EVALing, ERRORing, and EXITing + + +File: slib.info, Node: Require, Next: Vicinity, Prev: Built-in Support, Up: Built-in Support + +Require +------- + + - Variable: *features* + Is a list of symbols denoting features supported in this + implementation. *FEATURES* can grow as modules are `require'd. + *FEATURES* must be defined by all implementations (*note + Porting::.). + + Here are features which SLIB (`require.scm') adds to *FEATURES* + when appropriate. + + * 'inexact + + * 'rational + + * 'real + + * 'complex + + * 'bignum + + For each item, `(provided? 'FEATURE)' will return `#t' if that + feature is available, and `#f' if not. + + - Variable: *modules* + Is a list of pathnames denoting files which have been loaded. + + - Variable: *catalog* + Is an association list of features (symbols) and pathnames which + will supply those features. The pathname can be either a string + or a pair. If pathname is a pair then the first element should be + a macro feature symbol, `source', or `compiled'. The cdr of the + pathname should be either a string or a list. + +In the following functions if the argument FEATURE is not a symbol it +is assumed to be a pathname. + + - Function: provided? FEATURE + Returns `#t' if FEATURE is a member of `*features*' or `*modules*' + or if FEATURE is supported by a file already loaded and `#f' + otherwise. + + - Procedure: require FEATURE + FEATURE is a symbol. If `(provided? FEATURE)' is true `require' + returns. Otherwise, if `(assq FEATURE *catalog*)' is not `#f', + the associated files will be loaded and `(provided? FEATURE)' will + henceforth return `#t'. An unspecified value is returned. If + FEATURE is not found in `*catalog*', then an error is signaled. + + - Procedure: require PATHNAME + PATHNAME is a string. If PATHNAME has not already been given as + an argument to `require', PATHNAME is loaded. An unspecified + value is returned. + + - Procedure: provide FEATURE + Assures that FEATURE is contained in `*features*' if FEATURE is a + symbol and `*modules*' otherwise. + + - Function: require:feature->path FEATURE + Returns `#t' if FEATURE is a member of `*features*' or `*modules*' + or if FEATURE is supported by a file already loaded. Returns a + path if one was found in `*catalog*' under the feature name, and + `#f' otherwise. The path can either be a string suitable as an + argument to load or a pair as described above for *catalog*. + + +File: slib.info, Node: Vicinity, Next: Configuration, Prev: Require, Up: Built-in Support + +Vicinity +-------- + +A vicinity is a descriptor for a place in the file system. Vicinities +hide from the programmer the concepts of host, volume, directory, and +version. Vicinities express only the concept of a file environment +where a file name can be resolved to a file in a system independent +manner. Vicinities can even be used on "flat" file systems (which have +no directory structure) by having the vicinity express constraints on +the file name. On most systems a vicinity would be a string. All of +these procedures are file system dependent. + +These procedures are provided by all implementations. + + - Function: make-vicinity PATH + Returns the vicinity of PATH for use by `in-vicinity'. + + - Function: program-vicinity + Returns the vicinity of the currently loading Scheme code. For an + interpreter this would be the directory containing source code. + For a compiled system (with multiple files) this would be the + directory where the object or executable files are. If no file is + currently loading it the result is undefined. *Warning:* + `program-vicinity' can return incorrect values if your program + escapes back into a `load'. + + - Function: library-vicinity + Returns the vicinity of the shared Scheme library. + + - Function: implementation-vicinity + Returns the vicinity of the underlying Scheme implementation. This + vicinity will likely contain startup code and messages and a + compiler. + + - Function: user-vicinity + Returns the vicinity of the current directory of the user. On most + systems this is `""' (the empty string). + + - Function: home-vicinity + Returns the vicinity of the user's "HOME" directory, the directory + which typically contains files which customize a computer + environment for a user. If scheme is running without a user (eg. + a daemon) or if this concept is meaningless for the platform, then + `home-vicinity' returns `#f'. + + - Function: in-vicinity VICINITY FILENAME + Returns a filename suitable for use by `slib:load', + `slib:load-source', `slib:load-compiled', `open-input-file', + `open-output-file', etc. The returned filename is FILENAME in + VICINITY. `in-vicinity' should allow FILENAME to override + VICINITY when FILENAME is an absolute pathname and VICINITY is + equal to the value of `(user-vicinity)'. The behavior of + `in-vicinity' when FILENAME is absolute and VICINITY is not equal + to the value of `(user-vicinity)' is unspecified. For most systems + `in-vicinity' can be `string-append'. + + - Function: sub-vicinity VICINITY NAME + Returns the vicinity of VICINITY restricted to NAME. This is used + for large systems where names of files in subsystems could + conflict. On systems with directory structure `sub-vicinity' will + return a pathname of the subdirectory NAME of VICINITY. + + +File: slib.info, Node: Configuration, Next: Input/Output, Prev: Vicinity, Up: Built-in Support + +Configuration +------------- + +These constants and procedures describe characteristics of the Scheme +and underlying operating system. They are provided by all +implementations. + + - Constant: char-code-limit + An integer 1 larger that the largest value which can be returned by + `char->integer'. + + - Constant: most-positive-fixnum + In implementations which support integers of practically unlimited + size, MOST-POSITIVE-FIXNUM is a large exact integer within the + range of exact integers that may result from computing the length + of a list, vector, or string. + + In implementations which do not support integers of practically + unlimited size, MOST-POSITIVE-FIXNUM is the largest exact integer + that may result from computing the length of a list, vector, or + string. + + - Constant: slib:tab + The tab character. + + - Constant: slib:form-feed + The form-feed character. + + - Function: software-type + Returns a symbol denoting the generic operating system type. For + instance, `unix', `vms', `macos', `amiga', or `ms-dos'. + + - Function: slib:report-version + Displays the versions of SLIB and the underlying Scheme + implementation and the name of the operating system. An + unspecified value is returned. + + (slib:report-version) => slib "2c7" on scm "5b1" on unix | + + - Function: slib:report + Displays the information of `(slib:report-version)' followed by + almost all the information neccessary for submitting a problem + report. An unspecified value is returned. + + - Function: slib:report #T + provides a more verbose listing. + + - Function: slib:report FILENAME + Writes the report to file `filename'. + + (slib:report) + => + slib "2c7" on scm "5b1" on unix | + (implementation-vicinity) is "/home/jaffer/scm/" + (library-vicinity) is "/home/jaffer/slib/" + (scheme-file-suffix) is ".scm" + loaded *features* : + trace alist qp sort + common-list-functions macro values getopt + compiled + implementation *features* : + bignum complex real rational + inexact vicinity ed getenv + tmpnam abort transcript with-file + ieee-p1178 rev4-report rev4-optional-procedures hash + object-hash delay eval dynamic-wind + multiarg-apply multiarg/and- logical defmacro + string-port source current-time record + rev3-procedures rev2-procedures sun-dl string-case + array dump char-ready? full-continuation + system + implementation *catalog* : + (i/o-extensions compiled "/home/jaffer/scm/ioext.so") + ... + + +File: slib.info, Node: Input/Output, Next: Legacy, Prev: Configuration, Up: Built-in Support + +Input/Output +------------ + +These procedures are provided by all implementations. + + - Procedure: file-exists? FILENAME + Returns `#t' if the specified file exists. Otherwise, returns + `#f'. If the underlying implementation does not support this + feature then `#f' is always returned. + + - Procedure: delete-file FILENAME + Deletes the file specified by FILENAME. If FILENAME can not be + deleted, `#f' is returned. Otherwise, `#t' is returned. + + - Procedure: tmpnam + Returns a pathname for a file which will likely not be used by any + other process. Successive calls to `(tmpnam)' will return + different pathnames. + + - Procedure: current-error-port + Returns the current port to which diagnostic and error output is + directed. + + - Procedure: force-output + - Procedure: force-output PORT + Forces any pending output on PORT to be delivered to the output + device and returns an unspecified value. The PORT argument may be + omitted, in which case it defaults to the value returned by + `(current-output-port)'. + + - Procedure: output-port-width + - Procedure: output-port-width PORT + Returns the width of PORT, which defaults to + `(current-output-port)' if absent. If the width cannot be + determined 79 is returned. + + - Procedure: output-port-height + - Procedure: output-port-height PORT + Returns the height of PORT, which defaults to + `(current-output-port)' if absent. If the height cannot be + determined 24 is returned. + + +File: slib.info, Node: Legacy, Next: System, Prev: Input/Output, Up: Built-in Support + +Legacy +------ + + These procedures are provided by all implementations. + + - Function: identity X + IDENTITY returns its argument. + + Example: + (identity 3) + => 3 + (identity '(foo bar)) + => (foo bar) + (map identity LST) + == (copy-list LST) + +The following procedures were present in Scheme until R4RS (*note +Language changes: (r4rs)Notes.). They are provided by all SLIB +implementations. + + - Constant: t + Derfined as `#t'. + + - Constant: nil + Defined as `#f'. + + - Function: last-pair L + Returns the last pair in the list L. Example: + (last-pair (cons 1 2)) + => (1 . 2) + (last-pair '(1 2)) + => (2) + == (cons 2 '()) + + +File: slib.info, Node: System, Prev: Legacy, Up: Built-in Support + +System +------ + +These procedures are provided by all implementations. + + - Procedure: slib:load-source NAME + Loads a file of Scheme source code from NAME with the default + filename extension used in SLIB. For instance if the filename + extension used in SLIB is `.scm' then `(slib:load-source "foo")' + will load from file `foo.scm'. + + - Procedure: slib:load-compiled NAME + On implementations which support separtely loadable compiled + modules, loads a file of compiled code from NAME with the + implementation's filename extension for compiled code appended. + + - Procedure: slib:load NAME + Loads a file of Scheme source or compiled code from NAME with the + appropriate suffixes appended. If both source and compiled code + are present with the appropriate names then the implementation + will load just one. It is up to the implementation to choose + which one will be loaded. + + If an implementation does not support compiled code then + `slib:load' will be identical to `slib:load-source'. + + - Procedure: slib:eval OBJ + `eval' returns the value of OBJ evaluated in the current top level + environment. *Note Eval:: provides a more general evaluation + facility. + + - Procedure: slib:eval-load FILENAME EVAL + FILENAME should be a string. If filename names an existing file, + the Scheme source code expressions and definitions are read from + the file and EVAL called with them sequentially. The + `slib:eval-load' procedure does not affect the values returned by + `current-input-port' and `current-output-port'. + + - Procedure: slib:warn ARG1 ARG2 ... + Outputs a warning message containing the arguments. + + - Procedure: slib:error ARG1 ARG2 ... + Outputs an error message containing the arguments, aborts + evaluation of the current form and responds in a system dependent + way to the error. Typical responses are to abort the program or + to enter a read-eval-print loop. + + - Procedure: slib:exit N + - Procedure: slib:exit + Exits from the Scheme session returning status N to the system. + If N is omitted or `#t', a success status is returned to the + system (if possible). If N is `#f' a failure is returned to the + system (if possible). If N is an integer, then N is returned to + the system (if possible). If the Scheme session cannot exit an + unspecified value is returned from `slib:exit'. + + +File: slib.info, Node: About this manual, Prev: Built-in Support, Up: The Library System + +About this manual +================= + + * Entries that are labeled as Functions are called for their return + values. Entries that are labeled as Procedures are called + primarily for their side effects. + + * Examples in this text were produced using the `scm' Scheme + implementation. + + * At the beginning of each section, there is a line that looks like + `(require 'feature)'. Include this line in your code prior to + using the package. + + +File: slib.info, Node: Scheme Syntax Extension Packages, Next: Textual Conversion Packages, Prev: The Library System, Up: Top + +Scheme Syntax Extension Packages +******************************** + +* Menu: + +* Defmacro:: Supported by all implementations + +* R4RS Macros:: 'macro +* Macro by Example:: 'macro-by-example +* Macros That Work:: 'macros-that-work +* Syntactic Closures:: 'syntactic-closures +* Syntax-Case Macros:: 'syntax-case + +Syntax extensions (macros) included with SLIB. Also *Note Structures::. + +* Fluid-Let:: 'fluid-let +* Yasos:: 'yasos, 'oop, 'collect + + +File: slib.info, Node: Defmacro, Next: R4RS Macros, Prev: Scheme Syntax Extension Packages, Up: Scheme Syntax Extension Packages + +Defmacro +======== + + Defmacros are supported by all implementations. + + - Function: gentemp + Returns a new (interned) symbol each time it is called. The symbol + names are implementation-dependent + (gentemp) => scm:G0 + (gentemp) => scm:G1 + + - Function: defmacro:eval E + Returns the `slib:eval' of expanding all defmacros in scheme + expression E. + + - Function: defmacro:load FILENAME + FILENAME should be a string. If filename names an existing file, + the `defmacro:load' procedure reads Scheme source code expressions + and definitions from the file and evaluates them sequentially. + These source code expressions and definitions may contain defmacro + definitions. The `macro:load' procedure does not affect the values + returned by `current-input-port' and `current-output-port'. + + - Function: defmacro? SYM + Returns `#t' if SYM has been defined by `defmacro', `#f' otherwise. + + - Function: macroexpand-1 FORM + - Function: macroexpand FORM + If FORM is a macro call, `macroexpand-1' will expand the macro + call once and return it. A FORM is considered to be a macro call + only if it is a cons whose `car' is a symbol for which a `defmacr' + has been defined. + + `macroexpand' is similar to `macroexpand-1', but repeatedly + expands FORM until it is no longer a macro call. + + - Macro: defmacro NAME LAMBDA-LIST FORM ... + When encountered by `defmacro:eval', `defmacro:macroexpand*', or + `defmacro:load' defines a new macro which will henceforth be + expanded when encountered by `defmacro:eval', + `defmacro:macroexpand*', or `defmacro:load'. + +Defmacroexpand +-------------- + + `(require 'defmacroexpand)' + + - Function: defmacro:expand* E + Returns the result of expanding all defmacros in scheme expression + E. + + +File: slib.info, Node: R4RS Macros, Next: Macro by Example, Prev: Defmacro, Up: Scheme Syntax Extension Packages + +R4RS Macros +=========== + + `(require 'macro)' is the appropriate call if you want R4RS +high-level macros but don't care about the low level implementation. If +an SLIB R4RS macro implementation is already loaded it will be used. +Otherwise, one of the R4RS macros implemetations is loaded. + + The SLIB R4RS macro implementations support the following uniform +interface: + + - Function: macro:expand SEXPRESSION + Takes an R4RS expression, macro-expands it, and returns the result + of the macro expansion. + + - Function: macro:eval SEXPRESSION + Takes an R4RS expression, macro-expands it, evals the result of the + macro expansion, and returns the result of the evaluation. + + - Procedure: macro:load FILENAME + FILENAME should be a string. If filename names an existing file, + the `macro:load' procedure reads Scheme source code expressions and + definitions from the file and evaluates them sequentially. These + source code expressions and definitions may contain macro + definitions. The `macro:load' procedure does not affect the + values returned by `current-input-port' and `current-output-port'. + + +File: slib.info, Node: Macro by Example, Next: Macros That Work, Prev: R4RS Macros, Up: Scheme Syntax Extension Packages + +Macro by Example +================ + + `(require 'macro-by-example)' + + A vanilla implementation of `Macro by Example' (Eugene Kohlbecker, +R4RS) by Dorai Sitaram, (dorai@cs.rice.edu) using `defmacro'. + + * generating hygienic global `define-syntax' Macro-by-Example macros + *cheaply*. + + * can define macros which use `...'. + + * needn't worry about a lexical variable in a macro definition + clashing with a variable from the macro use context + + * don't suffer the overhead of redefining the repl if `defmacro' + natively supported (most implementations) + +Caveat +------ + + These macros are not referentially transparent (*note Macros: +(r4rs)Macros.). Lexically scoped macros (i.e., `let-syntax' and +`letrec-syntax') are not supported. In any case, the problem of +referential transparency gains poignancy only when `let-syntax' and +`letrec-syntax' are used. So you will not be courting large-scale +disaster unless you're using system-function names as local variables +with unintuitive bindings that the macro can't use. However, if you +must have the full `r4rs' macro functionality, look to the more +featureful (but also more expensive) versions of syntax-rules available +in slib *Note Macros That Work::, *Note Syntactic Closures::, and *Note +Syntax-Case Macros::. + + - Macro: define-syntax KEYWORD TRANSFORMER-SPEC + The KEYWORD is an identifier, and the TRANSFORMER-SPEC should be + an instance of `syntax-rules'. + + The top-level syntactic environment is extended by binding the + KEYWORD to the specified transformer. + + (define-syntax let* + (syntax-rules () + ((let* () body1 body2 ...) + (let () body1 body2 ...)) + ((let* ((name1 val1) (name2 val2) ...) + body1 body2 ...) + (let ((name1 val1)) + (let* (( name2 val2) ...) + body1 body2 ...))))) + + - Macro: syntax-rules LITERALS SYNTAX-RULE ... + LITERALS is a list of identifiers, and each SYNTAX-RULE should be + of the form + + `(PATTERN TEMPLATE)' + + where the PATTERN and TEMPLATE are as in the grammar above. + + An instance of `syntax-rules' produces a new macro transformer by + specifying a sequence of hygienic rewrite rules. A use of a macro + whose keyword is associated with a transformer specified by + `syntax-rules' is matched against the patterns contained in the + SYNTAX-RULEs, beginning with the leftmost SYNTAX-RULE. When a + match is found, the macro use is trancribed hygienically according + to the template. + + Each pattern begins with the keyword for the macro. This keyword + is not involved in the matching and is not considered a pattern + variable or literal identifier. + + +File: slib.info, Node: Macros That Work, Next: Syntactic Closures, Prev: Macro by Example, Up: Scheme Syntax Extension Packages + +Macros That Work +================ + + `(require 'macros-that-work)' + + `Macros That Work' differs from the other R4RS macro implementations +in that it does not expand derived expression types to primitive +expression types. + + - Function: macro:expand EXPRESSION + - Function: macwork:expand EXPRESSION + Takes an R4RS expression, macro-expands it, and returns the result + of the macro expansion. + + - Function: macro:eval EXPRESSION + - Function: macwork:eval EXPRESSION + `macro:eval' returns the value of EXPRESSION in the current top + level environment. EXPRESSION can contain macro definitions. + Side effects of EXPRESSION will affect the top level environment. + + - Procedure: macro:load FILENAME + - Procedure: macwork:load FILENAME + FILENAME should be a string. If filename names an existing file, + the `macro:load' procedure reads Scheme source code expressions and + definitions from the file and evaluates them sequentially. These + source code expressions and definitions may contain macro + definitions. The `macro:load' procedure does not affect the + values returned by `current-input-port' and `current-output-port'. + + References: + + The `Revised^4 Report on the Algorithmic Language Scheme' Clinger and +Rees [editors]. To appear in LISP Pointers. Also available as a +technical report from the University of Oregon, MIT AI Lab, and Cornell. + + Macros That Work. Clinger and Rees. POPL '91. + + The supported syntax differs from the R4RS in that vectors are allowed +as patterns and as templates and are not allowed as pattern or template +data. + + transformer spec ==> (syntax-rules literals rules) + + rules ==> () + | (rule . rules) + + rule ==> (pattern template) + + pattern ==> pattern_var ; a symbol not in literals + | symbol ; a symbol in literals + | () + | (pattern . pattern) + | (ellipsis_pattern) + | #(pattern*) ; extends R4RS + | #(pattern* ellipsis_pattern) ; extends R4RS + | pattern_datum + + template ==> pattern_var + | symbol + | () + | (template2 . template2) + | #(template*) ; extends R4RS + | pattern_datum + + template2 ==> template + | ellipsis_template + + pattern_datum ==> string ; no vector + | character + | boolean + | number + + ellipsis_pattern ==> pattern ... + + ellipsis_template ==> template ... + + pattern_var ==> symbol ; not in literals + + literals ==> () + | (symbol . literals) + +Definitions +----------- + +Scope of an ellipsis + Within a pattern or template, the scope of an ellipsis (`...') is + the pattern or template that appears to its left. + +Rank of a pattern variable + The rank of a pattern variable is the number of ellipses within + whose scope it appears in the pattern. + +Rank of a subtemplate + The rank of a subtemplate is the number of ellipses within whose + scope it appears in the template. + +Template rank of an occurrence of a pattern variable + The template rank of an occurrence of a pattern variable within a + template is the rank of that occurrence, viewed as a subtemplate. + +Variables bound by a pattern + The variables bound by a pattern are the pattern variables that + appear within it. + +Referenced variables of a subtemplate + The referenced variables of a subtemplate are the pattern + variables that appear within it. + +Variables opened by an ellipsis template + The variables opened by an ellipsis template are the referenced + pattern variables whose rank is greater than the rank of the + ellipsis template. + +Restrictions +------------ + + No pattern variable appears more than once within a pattern. + + For every occurrence of a pattern variable within a template, the +template rank of the occurrence must be greater than or equal to the +pattern variable's rank. + + Every ellipsis template must open at least one variable. + + For every ellipsis template, the variables opened by an ellipsis +template must all be bound to sequences of the same length. + + The compiled form of a RULE is + + rule ==> (pattern template inserted) + + pattern ==> pattern_var + | symbol + | () + | (pattern . pattern) + | ellipsis_pattern + | #(pattern) + | pattern_datum + + template ==> pattern_var + | symbol + | () + | (template2 . template2) + | #(pattern) + | pattern_datum + + template2 ==> template + | ellipsis_template + + pattern_datum ==> string + | character + | boolean + | number + + pattern_var ==> #(V symbol rank) + + ellipsis_pattern ==> #(E pattern pattern_vars) + + ellipsis_template ==> #(E template pattern_vars) + + inserted ==> () + | (symbol . inserted) + + pattern_vars ==> () + | (pattern_var . pattern_vars) + + rank ==> exact non-negative integer + + where V and E are unforgeable values. + + The pattern variables associated with an ellipsis pattern are the +variables bound by the pattern, and the pattern variables associated +with an ellipsis template are the variables opened by the ellipsis +template. + + If the template contains a big chunk that contains no pattern +variables or inserted identifiers, then the big chunk will be copied +unnecessarily. That shouldn't matter very often. + + +File: slib.info, Node: Syntactic Closures, Next: Syntax-Case Macros, Prev: Macros That Work, Up: Scheme Syntax Extension Packages + +Syntactic Closures +================== + + `(require 'syntactic-closures)' + + - Function: macro:expand EXPRESSION + - Function: synclo:expand EXPRESSION + Returns scheme code with the macros and derived expression types of + EXPRESSION expanded to primitive expression types. + + - Function: macro:eval EXPRESSION + - Function: synclo:eval EXPRESSION + `macro:eval' returns the value of EXPRESSION in the current top + level environment. EXPRESSION can contain macro definitions. + Side effects of EXPRESSION will affect the top level environment. + + - Procedure: macro:load FILENAME + - Procedure: synclo:load FILENAME + FILENAME should be a string. If filename names an existing file, + the `macro:load' procedure reads Scheme source code expressions and + definitions from the file and evaluates them sequentially. These + source code expressions and definitions may contain macro + definitions. The `macro:load' procedure does not affect the + values returned by `current-input-port' and `current-output-port'. + +Syntactic Closure Macro Facility +-------------------------------- + + A Syntactic Closures Macro Facility + + by Chris Hanson + + 9 November 1991 + + This document describes "syntactic closures", a low-level macro +facility for the Scheme programming language. The facility is an +alternative to the low-level macro facility described in the `Revised^4 +Report on Scheme.' This document is an addendum to that report. + + The syntactic closures facility extends the BNF rule for TRANSFORMER +SPEC to allow a new keyword that introduces a low-level macro +transformer: + TRANSFORMER SPEC := (transformer EXPRESSION) + + Additionally, the following procedures are added: + make-syntactic-closure + capture-syntactic-environment + identifier? + identifier=? + + The description of the facility is divided into three parts. The +first part defines basic terminology. The second part describes how +macro transformers are defined. The third part describes the use of +"identifiers", which extend the syntactic closure mechanism to be +compatible with `syntax-rules'. + +Terminology +........... + + This section defines the concepts and data types used by the syntactic +closures facility. + + * "Forms" are the syntactic entities out of which programs are + recursively constructed. A form is any expression, any + definition, any syntactic keyword, or any syntactic closure. The + variable name that appears in a `set!' special form is also a + form. Examples of forms: + 17 + #t + car + (+ x 4) + (lambda (x) x) + (define pi 3.14159) + if + define + + * An "alias" is an alternate name for a given symbol. It can appear + anywhere in a form that the symbol could be used, and when quoted + it is replaced by the symbol; however, it does not satisfy the + predicate `symbol?'. Macro transformers rarely distinguish + symbols from aliases, referring to both as identifiers. + + * A "syntactic" environment maps identifiers to their meanings. + More precisely, it determines whether an identifier is a syntactic + keyword or a variable. If it is a keyword, the meaning is an + interpretation for the form in which that keyword appears. If it + is a variable, the meaning identifies which binding of that + variable is referenced. In short, syntactic environments contain + all of the contextual information necessary for interpreting the + meaning of a particular form. + + * A "syntactic closure" consists of a form, a syntactic environment, + and a list of identifiers. All identifiers in the form take their + meaning from the syntactic environment, except those in the given + list. The identifiers in the list are to have their meanings + determined later. A syntactic closure may be used in any context + in which its form could have been used. Since a syntactic closure + is also a form, it may not be used in contexts where a form would + be illegal. For example, a form may not appear as a clause in the + cond special form. A syntactic closure appearing in a quoted + structure is replaced by its form. + +Transformer Definition +...................... + + This section describes the `transformer' special form and the +procedures `make-syntactic-closure' and `capture-syntactic-environment'. + + - Syntax: transformer EXPRESSION + Syntax: It is an error if this syntax occurs except as a + TRANSFORMER SPEC. + + Semantics: The EXPRESSION is evaluated in the standard transformer + environment to yield a macro transformer as described below. This + macro transformer is bound to a macro keyword by the special form + in which the `transformer' expression appears (for example, + `let-syntax'). + + A "macro transformer" is a procedure that takes two arguments, a + form and a syntactic environment, and returns a new form. The + first argument, the "input form", is the form in which the macro + keyword occurred. The second argument, the "usage environment", + is the syntactic environment in which the input form occurred. + The result of the transformer, the "output form", is automatically + closed in the "transformer environment", which is the syntactic + environment in which the `transformer' expression occurred. + + For example, here is a definition of a push macro using + `syntax-rules': + (define-syntax push + (syntax-rules () + ((push item list) + (set! list (cons item list))))) + + Here is an equivalent definition using `transformer': + (define-syntax push + (transformer + (lambda (exp env) + (let ((item + (make-syntactic-closure env '() (cadr exp))) + (list + (make-syntactic-closure env '() (caddr exp)))) + `(set! ,list (cons ,item ,list)))))) + + In this example, the identifiers `set!' and `cons' are closed in + the transformer environment, and thus will not be affected by the + meanings of those identifiers in the usage environment `env'. + + Some macros may be non-hygienic by design. For example, the + following defines a loop macro that implicitly binds `exit' to an + escape procedure. The binding of `exit' is intended to capture + free references to `exit' in the body of the loop, so `exit' must + be left free when the body is closed: + (define-syntax loop + (transformer + (lambda (exp env) + (let ((body (cdr exp))) + `(call-with-current-continuation + (lambda (exit) + (let f () + ,@(map (lambda (exp) + (make-syntactic-closure env '(exit) + exp)) + body) + (f)))))))) + + To assign meanings to the identifiers in a form, use + `make-syntactic-closure' to close the form in a syntactic + environment. + + - Function: make-syntactic-closure ENVIRONMENT FREE-NAMES FORM + ENVIRONMENT must be a syntactic environment, FREE-NAMES must be a + list of identifiers, and FORM must be a form. + `make-syntactic-closure' constructs and returns a syntactic closure + of FORM in ENVIRONMENT, which can be used anywhere that FORM could + have been used. All the identifiers used in FORM, except those + explicitly excepted by FREE-NAMES, obtain their meanings from + ENVIRONMENT. + + Here is an example where FREE-NAMES is something other than the + empty list. It is instructive to compare the use of FREE-NAMES in + this example with its use in the `loop' example above: the examples + are similar except for the source of the identifier being left + free. + (define-syntax let1 + (transformer + (lambda (exp env) + (let ((id (cadr exp)) + (init (caddr exp)) + (exp (cadddr exp))) + `((lambda (,id) + ,(make-syntactic-closure env (list id) exp)) + ,(make-syntactic-closure env '() init)))))) + + `let1' is a simplified version of `let' that only binds a single + identifier, and whose body consists of a single expression. When + the body expression is syntactically closed in its original + syntactic environment, the identifier that is to be bound by + `let1' must be left free, so that it can be properly captured by + the `lambda' in the output form. + + To obtain a syntactic environment other than the usage + environment, use `capture-syntactic-environment'. + + - Function: capture-syntactic-environment PROCEDURE + `capture-syntactic-environment' returns a form that will, when + transformed, call PROCEDURE on the current syntactic environment. + PROCEDURE should compute and return a new form to be transformed, + in that same syntactic environment, in place of the form. + + An example will make this clear. Suppose we wanted to define a + simple `loop-until' keyword equivalent to + (define-syntax loop-until + (syntax-rules () + ((loop-until id init test return step) + (letrec ((loop + (lambda (id) + (if test return (loop step))))) + (loop init))))) + + The following attempt at defining `loop-until' has a subtle bug: + (define-syntax loop-until + (transformer + (lambda (exp env) + (let ((id (cadr exp)) + (init (caddr exp)) + (test (cadddr exp)) + (return (cadddr (cdr exp))) + (step (cadddr (cddr exp))) + (close + (lambda (exp free) + (make-syntactic-closure env free exp)))) + `(letrec ((loop + (lambda (,id) + (if ,(close test (list id)) + ,(close return (list id)) + (loop ,(close step (list id))))))) + (loop ,(close init '()))))))) + + This definition appears to take all of the proper precautions to + prevent unintended captures. It carefully closes the + subexpressions in their original syntactic environment and it + leaves the `id' identifier free in the `test', `return', and + `step' expressions, so that it will be captured by the binding + introduced by the `lambda' expression. Unfortunately it uses the + identifiers `if' and `loop' within that `lambda' expression, so if + the user of `loop-until' just happens to use, say, `if' for the + identifier, it will be inadvertently captured. + + The syntactic environment that `if' and `loop' want to be exposed + to is the one just outside the `lambda' expression: before the + user's identifier is added to the syntactic environment, but after + the identifier loop has been added. + `capture-syntactic-environment' captures exactly that environment + as follows: + (define-syntax loop-until + (transformer + (lambda (exp env) + (let ((id (cadr exp)) + (init (caddr exp)) + (test (cadddr exp)) + (return (cadddr (cdr exp))) + (step (cadddr (cddr exp))) + (close + (lambda (exp free) + (make-syntactic-closure env free exp)))) + `(letrec ((loop + ,(capture-syntactic-environment + (lambda (env) + `(lambda (,id) + (,(make-syntactic-closure env '() `if) + ,(close test (list id)) + ,(close return (list id)) + (,(make-syntactic-closure env '() + `loop) + ,(close step (list id))))))))) + (loop ,(close init '()))))))) + + In this case, having captured the desired syntactic environment, + it is convenient to construct syntactic closures of the + identifiers `if' and the `loop' and use them in the body of the + `lambda'. + + A common use of `capture-syntactic-environment' is to get the + transformer environment of a macro transformer: + (transformer + (lambda (exp env) + (capture-syntactic-environment + (lambda (transformer-env) + ...)))) + +Identifiers +........... + + This section describes the procedures that create and manipulate +identifiers. Previous syntactic closure proposals did not have an +identifier data type - they just used symbols. The identifier data +type extends the syntactic closures facility to be compatible with the +high-level `syntax-rules' facility. + + As discussed earlier, an identifier is either a symbol or an "alias". +An alias is implemented as a syntactic closure whose "form" is an +identifier: + (make-syntactic-closure env '() 'a) + => an "alias" + + Aliases are implemented as syntactic closures because they behave just +like syntactic closures most of the time. The difference is that an +alias may be bound to a new value (for example by `lambda' or +`let-syntax'); other syntactic closures may not be used this way. If +an alias is bound, then within the scope of that binding it is looked +up in the syntactic environment just like any other identifier. + + Aliases are used in the implementation of the high-level facility +`syntax-rules'. A macro transformer created by `syntax-rules' uses a +template to generate its output form, substituting subforms of the +input form into the template. In a syntactic closures implementation, +all of the symbols in the template are replaced by aliases closed in +the transformer environment, while the output form itself is closed in +the usage environment. This guarantees that the macro transformation +is hygienic, without requiring the transformer to know the syntactic +roles of the substituted input subforms. + + - Function: identifier? OBJECT + Returns `#t' if OBJECT is an identifier, otherwise returns `#f'. + Examples: + (identifier? 'a) + => #t + (identifier? (make-syntactic-closure env '() 'a)) + => #t + (identifier? "a") + => #f + (identifier? #\a) + => #f + (identifier? 97) + => #f + (identifier? #f) + => #f + (identifier? '(a)) + => #f + (identifier? '#(a)) + => #f + + The predicate `eq?' is used to determine if two identifers are + "the same". Thus `eq?' can be used to compare identifiers exactly + as it would be used to compare symbols. Often, though, it is + useful to know whether two identifiers "mean the same thing". For + example, the `cond' macro uses the symbol `else' to identify the + final clause in the conditional. A macro transformer for `cond' + cannot just look for the symbol `else', because the `cond' form + might be the output of another macro transformer that replaced the + symbol `else' with an alias. Instead the transformer must look + for an identifier that "means the same thing" in the usage + environment as the symbol `else' means in the transformer + environment. + + - Function: identifier=? ENVIRONMENT1 IDENTIFIER1 ENVIRONMENT2 + IDENTIFIER2 + ENVIRONMENT1 and ENVIRONMENT2 must be syntactic environments, and + IDENTIFIER1 and IDENTIFIER2 must be identifiers. `identifier=?' + returns `#t' if the meaning of IDENTIFIER1 in ENVIRONMENT1 is the + same as that of IDENTIFIER2 in ENVIRONMENT2, otherwise it returns + `#f'. Examples: + + (let-syntax + ((foo + (transformer + (lambda (form env) + (capture-syntactic-environment + (lambda (transformer-env) + (identifier=? transformer-env 'x env 'x))))))) + (list (foo) + (let ((x 3)) + (foo)))) + => (#t #f) + + (let-syntax ((bar foo)) + (let-syntax + ((foo + (transformer + (lambda (form env) + (capture-syntactic-environment + (lambda (transformer-env) + (identifier=? transformer-env 'foo + env (cadr form)))))))) + (list (foo foo) + (foobar)))) + => (#f #t) + +Acknowledgements +................ + + The syntactic closures facility was invented by Alan Bawden and +Jonathan Rees. The use of aliases to implement `syntax-rules' was +invented by Alan Bawden (who prefers to call them "synthetic names"). +Much of this proposal is derived from an earlier proposal by Alan +Bawden. + + +File: slib.info, Node: Syntax-Case Macros, Next: Fluid-Let, Prev: Syntactic Closures, Up: Scheme Syntax Extension Packages + +Syntax-Case Macros +================== + + `(require 'syntax-case)' + + - Function: macro:expand EXPRESSION + - Function: syncase:expand EXPRESSION + Returns scheme code with the macros and derived expression types of + EXPRESSION expanded to primitive expression types. + + - Function: macro:eval EXPRESSION + - Function: syncase:eval EXPRESSION + `macro:eval' returns the value of EXPRESSION in the current top + level environment. EXPRESSION can contain macro definitions. + Side effects of EXPRESSION will affect the top level environment. + + - Procedure: macro:load FILENAME + - Procedure: syncase:load FILENAME + FILENAME should be a string. If filename names an existing file, + the `macro:load' procedure reads Scheme source code expressions and + definitions from the file and evaluates them sequentially. These + source code expressions and definitions may contain macro + definitions. The `macro:load' procedure does not affect the + values returned by `current-input-port' and `current-output-port'. + + This is version 2.1 of `syntax-case', the low-level macro facility +proposed and implemented by Robert Hieb and R. Kent Dybvig. + + This version is further adapted by Harald Hanche-Olsen + to make it compatible with, and easily usable +with, SLIB. Mainly, these adaptations consisted of: + + * Removing white space from `expand.pp' to save space in the + distribution. This file is not meant for human readers anyway... + + * Removed a couple of Chez scheme dependencies. + + * Renamed global variables used to minimize the possibility of name + conflicts. + + * Adding an SLIB-specific initialization file. + + * Removing a couple extra files, most notably the documentation (but + see below). + + If you wish, you can see exactly what changes were done by reading the +shell script in the file `syncase.sh'. + + The two PostScript files were omitted in order to not burden the SLIB +distribution with them. If you do intend to use `syntax-case', +however, you should get these files and print them out on a PostScript +printer. They are available with the original `syntax-case' +distribution by anonymous FTP in +`cs.indiana.edu:/pub/scheme/syntax-case'. + + In order to use syntax-case from an interactive top level, execute: + (require 'syntax-case) + (require 'repl) + (repl:top-level macro:eval) + See the section Repl (*note Repl::.) for more information. + + To check operation of syntax-case get +`cs.indiana.edu:/pub/scheme/syntax-case', and type + (require 'syntax-case) + (syncase:sanity-check) + + Beware that `syntax-case' takes a long time to load - about 20s on a +SPARCstation SLC (with SCM) and about 90s on a Macintosh SE/30 (with +Gambit). + +Notes +----- + + All R4RS syntactic forms are defined, including `delay'. Along with +`delay' are simple definitions for `make-promise' (into which `delay' +expressions expand) and `force'. + + `syntax-rules' and `with-syntax' (described in `TR356') are defined. + + `syntax-case' is actually defined as a macro that expands into calls +to the procedure `syntax-dispatch' and the core form `syntax-lambda'; +do not redefine these names. + + Several other top-level bindings not documented in TR356 are created: + * the "hooks" in `hooks.ss' + + * the `build-' procedures in `output.ss' + + * `expand-syntax' (the expander) + + The syntax of define has been extended to allow `(define ID)', which +assigns ID to some unspecified value. + + We have attempted to maintain R4RS compatibility where possible. The +incompatibilities should be confined to `hooks.ss'. Please let us know +if there is some incompatibility that is not flagged as such. + + Send bug reports, comments, suggestions, and questions to Kent Dybvig +(dyb@iuvax.cs.indiana.edu). + +Note from maintainer +-------------------- + + Included with the `syntax-case' files was `structure.scm' which +defines a macro `define-structure'. There is no documentation for this +macro and it is not used by any code in SLIB. + + +File: slib.info, Node: Fluid-Let, Next: Yasos, Prev: Syntax-Case Macros, Up: Scheme Syntax Extension Packages + +Fluid-Let +========= + + `(require 'fluid-let)' + + - Syntax: fluid-let `(BINDINGS ...)' FORMS... + + (fluid-let ((VARIABLE INIT) ...) + EXPRESSION EXPRESSION ...) + + The INITs are evaluated in the current environment (in some +unspecified order), the current values of the VARIABLEs are saved, the +results are assigned to the VARIABLEs, the EXPRESSIONs are evaluated +sequentially in the current environment, the VARIABLEs are restored to +their original values, and the value of the last EXPRESSION is returned. + + The syntax of this special form is similar to that of `let', but +`fluid-let' temporarily rebinds existing VARIABLEs. Unlike `let', +`fluid-let' creates no new bindings; instead it *assigns* the values of +each INIT to the binding (determined by the rules of lexical scoping) +of its corresponding VARIABLE. + + +File: slib.info, Node: Yasos, Prev: Fluid-Let, Up: Scheme Syntax Extension Packages + +Yasos +===== + + `(require 'oop)' or `(require 'yasos)' + + `Yet Another Scheme Object System' is a simple object system for +Scheme based on the paper by Norman Adams and Jonathan Rees: `Object +Oriented Programming in Scheme', Proceedings of the 1988 ACM Conference +on LISP and Functional Programming, July 1988 [ACM #552880]. + + Another reference is: + + Ken Dickey. Scheming with Objects `AI Expert' Volume 7, Number 10 +(October 1992), pp. 24-33. + +* Menu: + +* Yasos terms:: Definitions and disclaimer. +* Yasos interface:: The Yasos macros and procedures. +* Setters:: Dylan-like setters in Yasos. +* Yasos examples:: Usage of Yasos and setters. + + +File: slib.info, Node: Yasos terms, Next: Yasos interface, Prev: Yasos, Up: Yasos + +Terms +----- + +"Object" + Any Scheme data object. + +"Instance" + An instance of the OO system; an "object". + +"Operation" + A METHOD. + +*Notes:* + The object system supports multiple inheritance. An instance can + inherit from 0 or more ancestors. In the case of multiple + inherited operations with the same identity, the operation used is + that from the first ancestor which contains it (in the ancestor + `let'). An operation may be applied to any Scheme data + object--not just instances. As code which creates instances is + just code, there are no "classes" and no meta-ANYTHING. Method + dispatch is by a procedure call a la CLOS rather than by `send' + syntax a la Smalltalk. + +*Disclaimer:* + There are a number of optimizations which can be made. This + implementation is expository (although performance should be quite + reasonable). See the L&FP paper for some suggestions. + + +File: slib.info, Node: Yasos interface, Next: Setters, Prev: Yasos terms, Up: Yasos + +Interface +--------- + + - Syntax: define-operation `('OPNAME SELF ARG ...`)' DEFAULT-BODY + Defines a default behavior for data objects which don't handle the + operation OPNAME. The default behavior (for an empty + DEFAULT-BODY) is to generate an error. + + - Syntax: define-predicate OPNAME? + Defines a predicate OPNAME?, usually used for determining the + "type" of an object, such that `(OPNAME? OBJECT)' returns `#t' if + OBJECT has an operation OPNAME? and `#f' otherwise. + + - Syntax: object `((NAME SELF ARG ...) BODY)' ... + Returns an object (an instance of the object system) with + operations. Invoking `(NAME OBJECT ARG ...' executes the BODY of + the OBJECT with SELF bound to OBJECT and with argument(s) ARG.... + + - Syntax: object-with-ancestors `(('ANCESTOR1 INIT1`)' ...`)' + OPERATION ... + A `let'-like form of `object' for multiple inheritance. It + returns an object inheriting the behaviour of ANCESTOR1 etc. An + operation will be invoked in an ancestor if the object itself does + not provide such a method. In the case of multiple inherited + operations with the same identity, the operation used is the one + found in the first ancestor in the ancestor list. + + - Syntax: operate-as COMPONENT OPERATION SELF ARG ... + Used in an operation definition (of SELF) to invoke the OPERATION + in an ancestor COMPONENT but maintain the object's identity. Also + known as "send-to-super". + + - Procedure: print OBJ PORT + A default `print' operation is provided which is just `(format + PORT OBJ)' (*note Format::.) for non-instances and prints OBJ + preceded by `#' for instances. + + - Function: size OBJ + The default method returns the number of elements in OBJ if it is + a vector, string or list, `2' for a pair, `1' for a character and + by default id an error otherwise. Objects such as collections + (*note Collections::.) may override the default in an obvious way. + + +File: slib.info, Node: Setters, Next: Yasos examples, Prev: Yasos interface, Up: Yasos + +Setters +------- + + "Setters" implement "generalized locations" for objects associated +with some sort of mutable state. A "getter" operation retrieves a +value from a generalized location and the corresponding setter +operation stores a value into the location. Only the getter is named - +the setter is specified by a procedure call as below. (Dylan uses +special syntax.) Typically, but not necessarily, getters are access +operations to extract values from Yasos objects (*note Yasos::.). +Several setters are predefined, corresponding to getters `car', `cdr', +`string-ref' and `vector-ref' e.g., `(setter car)' is equivalent to +`set-car!'. + + This implementation of setters is similar to that in Dylan(TM) +(`Dylan: An object-oriented dynamic language', Apple Computer Eastern +Research and Technology). Common LISP provides similar facilities +through `setf'. + + - Function: setter GETTER + Returns the setter for the procedure GETTER. E.g., since + `string-ref' is the getter corresponding to a setter which is + actually `string-set!': + (define foo "foo") + ((setter string-ref) foo 0 #\F) ; set element 0 of foo + foo => "Foo" + + - Syntax: set PLACE NEW-VALUE + If PLACE is a variable name, `set' is equivalent to `set!'. + Otherwise, PLACE must have the form of a procedure call, where the + procedure name refers to a getter and the call indicates an + accessible generalized location, i.e., the call would return a + value. The return value of `set' is usually unspecified unless + used with a setter whose definition guarantees to return a useful + value. + (set (string-ref foo 2) #\O) ; generalized location with getter + foo => "FoO" + (set foo "foo") ; like set! + foo => "foo" + + - Procedure: add-setter GETTER SETTER + Add procedures GETTER and SETTER to the (inaccessible) list of + valid setter/getter pairs. SETTER implements the store operation + corresponding to the GETTER access operation for the relevant + state. The return value is unspecified. + + - Procedure: remove-setter-for GETTER + Removes the setter corresponding to the specified GETTER from the + list of valid setters. The return value is unspecified. + + - Syntax: define-access-operation GETTER-NAME + Shorthand for a Yasos `define-operation' defining an operation + GETTER-NAME that objects may support to return the value of some + mutable state. The default operation is to signal an error. The + return value is unspecified. + + +File: slib.info, Node: Yasos examples, Prev: Setters, Up: Yasos + +Examples +-------- + + ;;; These definitions for PRINT and SIZE are + ;;; already supplied by + (require 'yasos) + + (define-operation (print obj port) + (format port + (if (instance? obj) "#" "~s") + obj)) + + (define-operation (size obj) + (cond + ((vector? obj) (vector-length obj)) + ((list? obj) (length obj)) + ((pair? obj) 2) + ((string? obj) (string-length obj)) + ((char? obj) 1) + (else + (error "Operation not supported: size" obj)))) + + (define-predicate cell?) + (define-operation (fetch obj)) + (define-operation (store! obj newValue)) + + (define (make-cell value) + (object + ((cell? self) #t) + ((fetch self) value) + ((store! self newValue) + (set! value newValue) + newValue) + ((size self) 1) + ((print self port) + (format port "#" (fetch self))))) + + (define-operation (discard obj value) + (format #t "Discarding ~s~%" value)) + + (define (make-filtered-cell value filter) + (object-with-ancestors + ((cell (make-cell value))) + ((store! self newValue) + (if (filter newValue) + (store! cell newValue) + (discard self newValue))))) + + (define-predicate array?) + (define-operation (array-ref array index)) + (define-operation (array-set! array index value)) + + (define (make-array num-slots) + (let ((anArray (make-vector num-slots))) + (object + ((array? self) #t) + ((size self) num-slots) + ((array-ref self index) + (vector-ref anArray index)) + ((array-set! self index newValue) + (vector-set! anArray index newValue)) + ((print self port) + (format port "#" (size self)))))) + + (define-operation (position obj)) + (define-operation (discarded-value obj)) + + (define (make-cell-with-history value filter size) + (let ((pos 0) (most-recent-discard #f)) + (object-with-ancestors + ((cell (make-filtered-call value filter)) + (sequence (make-array size))) + ((array? self) #f) + ((position self) pos) + ((store! self newValue) + (operate-as cell store! self newValue) + (array-set! self pos newValue) + (set! pos (+ pos 1))) + ((discard self value) + (set! most-recent-discard value)) + ((discarded-value self) most-recent-discard) + ((print self port) + (format port "#" + (fetch self)))))) + + (define-access-operation fetch) + (add-setter fetch store!) + (define foo (make-cell 1)) + (print foo #f) + => "#" + (set (fetch foo) 2) + => + (print foo #f) + => "#" + (fetch foo) + => 2 + + +File: slib.info, Node: Textual Conversion Packages, Next: Mathematical Packages, Prev: Scheme Syntax Extension Packages, Up: Top + +Textual Conversion Packages +*************************** + +* Menu: + +* Precedence Parsing:: +* Format:: Common-Lisp Format +* Standard Formatted I/O:: Posix printf and scanf +* Programs and Arguments:: +* HTML HTTP and CGI:: Generate pages and serve WWW sites +* Printing Scheme:: Nicely +* Time and Date:: +* Vector Graphics:: +* Schmooz:: Documentation markup for Scheme programs + + +File: slib.info, Node: Precedence Parsing, Next: Format, Prev: Textual Conversion Packages, Up: Textual Conversion Packages + +Precedence Parsing +================== + + `(require 'precedence-parse)' or `(require 'parse)' + +This package implements: + + * a Pratt style precedence parser; + + * a "tokenizer" which congeals tokens according to assigned classes + of constituent characters; + + * procedures giving direct control of parser rulesets; + + * procedures for higher level specification of rulesets. + +* Menu: + +* Precedence Parsing Overview:: +* Ruleset Definition and Use:: +* Token definition:: +* Nud and Led Definition:: +* Grammar Rule Definition:: + + +File: slib.info, Node: Precedence Parsing Overview, Next: Ruleset Definition and Use, Prev: Precedence Parsing, Up: Precedence Parsing + +Precedence Parsing Overview +--------------------------- + +This package offers improvements over previous parsers. + + * Common computer language constructs are concisely specified. + + * Grammars can be changed dynamically. Operators can be assigned + different meanings within a lexical context. + + * Rulesets don't need compilation. Grammars can be changed + incrementally. + + * Operator precedence is specified by integers. + + * All possibilities of bad input are handled (1) and return as much + structure as was parsed when the error occured; The symbol `?' is + substituted for missing input. + +Here are the higher-level syntax types and an example of each. +Precedence considerations are omitted for clarity. See *Note Grammar +Rule Definition:: for full details. + + - Grammar: nofix bye exit + bye + calls the function `exit' with no arguments. + + - Grammar: prefix - negate + - 42 + Calls the function `negate' with the argument `42'. + + - Grammar: infix - difference + x - y + Calls the function `difference' with arguments `x' and `y'. + + - Grammar: nary + sum + x + y + z + Calls the function `sum' with arguments `x', `y', and `y'. + + - Grammar: postfix ! factorial + 5 ! + Calls the function `factorial' with the argument `5'. + + - Grammar: prestfix set set! + set foo bar + Calls the function `set!' with the arguments `foo' and `bar'. + + - Grammar: commentfix /* */ + /* almost any text here */ + Ignores the comment delimited by `/*' and `*/'. + + - Grammar: matchfix { list } + {0, 1, 2} + Calls the function `list' with the arguments `0', `1', and `2'. + + - Grammar: inmatchfix ( funcall ) + f(x, y) + Calls the function `funcall' with the arguments `f', `x', and `y'. + + - Grammar: delim ; + set foo bar; + delimits the extent of the restfix operator `set'. + + ---------- Footnotes ---------- + + (1) How do I know this? I parsed 250kbyte of random input (an e-mail +file) with a non-trivial grammar utilizing all constructs. + + +File: slib.info, Node: Ruleset Definition and Use, Next: Token definition, Prev: Precedence Parsing Overview, Up: Precedence Parsing + +Ruleset Definition and Use +-------------------------- + + - Variable: *syn-defs* + A grammar is built by one or more calls to `prec:define-grammar'. + The rules are appended to *SYN-DEFS*. The value of *SYN-DEFS* is + the grammar suitable for passing as an argument to `prec:parse'. + + - Constant: *syn-ignore-whitespace* + Is a nearly empty grammar with whitespace characters set to group + 0, which means they will not be made into tokens. Most rulesets + will want to start with `*syn-ignore-whitespace*' + +In order to start defining a grammar, either + + (set! *syn-defs* '()) + +or + + (set! *syn-defs* *syn-ignore-whitespace*) + + - Function: prec:define-grammar RULE1 ... + Appends RULE1 ... to *SYN-DEFS*. `prec:define-grammar' is used to + define both the character classes and rules for tokens. + +Once your grammar is defined, save the value of `*syn-defs*' in a +variable (for use when calling `prec:parse'). + + (define my-ruleset *syn-defs*) + + - Function: prec:parse RULESET DELIM + - Function: prec:parse RULESET DELIM PORT + The RULESET argument must be a list of rules as constructed by + `prec:define-grammar' and extracted from *SYN-DEFS*. + + The token DELIM may be a character, symbol, or string. A + character DELIM argument will match only a character token; i.e. a + character for which no token-group is assigned. A symbols or + string will match only a token string; i.e. a token resulting from + a token group. + + `prec:parse' reads a RULESET grammar expression delimited by DELIM + from the given input PORT. `prec:parse' returns the next object + parsable from the given input PORT, updating PORT to point to the + first character past the end of the external representation of the + object. + + If an end of file is encountered in the input before any + characters are found that can begin an object, then an end of file + object is returned. If a delimiter (such as DELIM) is found + before any characters are found that can begin an object, then + `#f' is returned. + + The PORT argument may be omitted, in which case it defaults to the + value returned by `current-input-port'. It is an error to parse + from a closed port. + + +File: slib.info, Node: Token definition, Next: Nud and Led Definition, Prev: Ruleset Definition and Use, Up: Precedence Parsing + +Token definition +---------------- + + - Function: tok:char-group GROUP CHARS CHARS-PROC + The argument CHARS may be a single character, a list of + characters, or a string. Each character in CHARS is treated as + though `tok:char-group' was called with that character alone. + + The argument CHARS-PROC must be a procedure of one argument, a + list of characters. After `tokenize' has finished accumulating + the characters for a token, it calls CHARS-PROC with the list of + characters. The value returned is the token which `tokenize' + returns. + + The argument GROUP may be an exact integer or a procedure of one + character argument. The following discussion concerns the + treatment which the tokenizing routine, `tokenize', will accord to + characters on the basis of their groups. + + When GROUP is a non-zero integer, characters whose group number is + equal to or exactly one less than GROUP will continue to + accumulate. Any other character causes the accumulation to stop + (until a new token is to be read). + + The GROUP of zero is special. These characters are ignored when + parsed pending a token, and stop the accumulation of token + characters when the accumulation has already begun. Whitespace + characters are usually put in group 0. + + If GROUP is a procedure, then, when triggerd by the occurence of + an initial (no accumulation) CHARS character, this procedure will + be repeatedly called with each successive character from the input + stream until the GROUP procedure returns a non-false value. + +The following convenient constants are provided for use with +`tok:char-group'. + + - Constant: tok:decimal-digits + Is the string `"0123456789"'. + + - Constant: tok:upper-case + Is the string consisting of all upper-case letters + ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"). + + - Constant: tok:lower-case + Is the string consisting of all lower-case letters + ("abcdefghijklmnopqrstuvwxyz"). + + - Constant: tok:whitespaces + Is the string consisting of all characters between 0 and 255 for + which `char-whitespace?' returns true. + + +File: slib.info, Node: Nud and Led Definition, Next: Grammar Rule Definition, Prev: Token definition, Up: Precedence Parsing + +Nud and Led Definition +---------------------- + + This section describes advanced features. You can skip this section +on first reading. + +The "Null Denotation" (or "nud") of a token is the procedure and +arguments applying for that token when "Left", an unclaimed parsed +expression is not extant. + +The "Left Denotation" (or "led") of a token is the procedure, +arguments, and lbp applying for that token when there is a "Left", an +unclaimed parsed expression. + +In his paper, + + Pratt, V. R. Top Down Operator Precendence. `SIGACT/SIGPLAN + Symposium on Principles of Programming Languages', Boston, 1973, + pages 41-51 + + the "left binding power" (or "lbp") was an independent property of +tokens. I think this was done in order to allow tokens with NUDs but +not LEDs to also be used as delimiters, which was a problem for +statically defined syntaxes. It turns out that *dynamically binding* +NUDs and LEDs allows them independence. + +For the rule-defining procedures that follow, the variable TK may be a +character, string, or symbol, or a list composed of characters, +strings, and symbols. Each element of TK is treated as though the +procedure were called for each element. + +Character TK arguments will match only character tokens; i.e. +characters for which no token-group is assigned. Symbols and strings +will both match token strings; i.e. tokens resulting from token groups. + + - Function: prec:make-nud TK SOP ARG1 ... + Returns a rule specifying that SOP be called when TK is parsed. + If SOP is a procedure, it is called with TK and ARG1 ... as its + arguments; the resulting value is incorporated into the expression + being built. Otherwise, `(list SOP ARG1 ...)' is incorporated. + +If no NUD has been defined for a token; then if that token is a string, +it is converted to a symbol and returned; if not a string, the token is +returned. + + - Function: prec:make-led TK SOP ARG1 ... + Returns a rule specifying that SOP be called when TK is parsed and + LEFT has an unclaimed parsed expression. If SOP is a procedure, + it is called with LEFT, TK, and ARG1 ... as its arguments; the + resulting value is incorporated into the expression being built. + Otherwise, LEFT is incorporated. + +If no LED has been defined for a token, and LEFT is set, the parser +issues a warning. + + +File: slib.info, Node: Grammar Rule Definition, Prev: Nud and Led Definition, Up: Precedence Parsing + +Grammar Rule Definition +----------------------- + +Here are procedures for defining rules for the syntax types introduced +in *Note Precedence Parsing Overview::. + +For the rule-defining procedures that follow, the variable TK may be a +character, string, or symbol, or a list composed of characters, +strings, and symbols. Each element of TK is treated as though the +procedure were called for each element. + +For procedures prec:delim, ..., prec:prestfix, if the SOP argument is +`#f', then the token which triggered this rule is converted to a symbol +and returned. A false SOP argument to the procedures prec:commentfix, +prec:matchfix, or prec:inmatchfix has a different meaning. + +Character TK arguments will match only character tokens; i.e. +characters for which no token-group is assigned. Symbols and strings +will both match token strings; i.e. tokens resulting from token groups. + + - Function: prec:delim TK + Returns a rule specifying that TK should not be returned from + parsing; i.e. TK's function is purely syntactic. The end-of-file + is always treated as a delimiter. + + - Function: prec:nofix TK SOP + Returns a rule specifying the following actions take place when TK + is parsed: + * If SOP is a procedure, it is called with no arguments; the + resulting value is incorporated into the expression being + built. Otherwise, the list of SOP is incorporated. + + - Function: prec:prefix TK SOP BP RULE1 ... + Returns a rule specifying the following actions take place when TK + is parsed: + * The rules RULE1 ... augment and, in case of conflict, override + rules currently in effect. + + * `prec:parse1' is called with binding-power BP. + + * If SOP is a procedure, it is called with the expression + returned from `prec:parse1'; the resulting value is + incorporated into the expression being built. Otherwise, the + list of SOP and the expression returned from `prec:parse1' is + incorporated. + + * The ruleset in effect before TK was parsed is restored; RULE1 + ... are forgotten. + + - Function: prec:infix TK SOP LBP BP RULE1 ... + Returns a rule declaring the left-binding-precedence of the token + TK is LBP and specifying the following actions take place when TK + is parsed: + * The rules RULE1 ... augment and, in case of conflict, override + rules currently in effect. + + * One expression is parsed with binding-power LBP. If instead a + delimiter is encountered, a warning is issued. + + * If SOP is a procedure, it is applied to the list of LEFT and + the parsed expression; the resulting value is incorporated + into the expression being built. Otherwise, the list of SOP, + the LEFT expression, and the parsed expression is + incorporated. + + * The ruleset in effect before TK was parsed is restored; RULE1 + ... are forgotten. + + - Function: prec:nary TK SOP BP + Returns a rule declaring the left-binding-precedence of the token + TK is BP and specifying the following actions take place when TK + is parsed: + * Expressions are parsed with binding-power BP as far as they + are interleaved with the token TK. + + * If SOP is a procedure, it is applied to the list of LEFT and + the parsed expressions; the resulting value is incorporated + into the expression being built. Otherwise, the list of SOP, + the LEFT expression, and the parsed expressions is + incorporated. + + - Function: prec:postfix TK SOP LBP + Returns a rule declaring the left-binding-precedence of the token + TK is LBP and specifying the following actions take place when TK + is parsed: + * If SOP is a procedure, it is called with the LEFT expression; + the resulting value is incorporated into the expression being + built. Otherwise, the list of SOP and the LEFT expression is + incorporated. + + - Function: prec:prestfix TK SOP BP RULE1 ... + Returns a rule specifying the following actions take place when TK + is parsed: + * The rules RULE1 ... augment and, in case of conflict, override + rules currently in effect. + + * Expressions are parsed with binding-power BP until a + delimiter is reached. + + * If SOP is a procedure, it is applied to the list of parsed + expressions; the resulting value is incorporated into the + expression being built. Otherwise, the list of SOP and the + parsed expressions is incorporated. + + * The ruleset in effect before TK was parsed is restored; RULE1 + ... are forgotten. + + - Function: prec:commentfix TK STP MATCH RULE1 ... + Returns rules specifying the following actions take place when TK + is parsed: + * The rules RULE1 ... augment and, in case of conflict, override + rules currently in effect. + + * Characters are read until and end-of-file or a sequence of + characters is read which matches the *string* MATCH. + + * If STP is a procedure, it is called with the string of all + that was read between the TK and MATCH (exclusive). + + * The ruleset in effect before TK was parsed is restored; RULE1 + ... are forgotten. + + Parsing of commentfix syntax differs from the others in several + ways. It reads directly from input without tokenizing; It calls + STP but does not return its value; nay any value. I added the STP + argument so that comment text could be echoed. + + - Function: prec:matchfix TK SOP SEP MATCH RULE1 ... + Returns a rule specifying the following actions take place when TK + is parsed: + * The rules RULE1 ... augment and, in case of conflict, override + rules currently in effect. + + * A rule declaring the token MATCH a delimiter takes effect. + + * Expressions are parsed with binding-power `0' until the token + MATCH is reached. If the token SEP does not appear between + each pair of expressions parsed, a warning is issued. + + * If SOP is a procedure, it is applied to the list of parsed + expressions; the resulting value is incorporated into the + expression being built. Otherwise, the list of SOP and the + parsed expressions is incorporated. + + * The ruleset in effect before TK was parsed is restored; RULE1 + ... are forgotten. + + - Function: prec:inmatchfix TK SOP SEP MATCH LBP RULE1 ... + Returns a rule declaring the left-binding-precedence of the token + TK is LBP and specifying the following actions take place when TK + is parsed: + * The rules RULE1 ... augment and, in case of conflict, override + rules currently in effect. + + * A rule declaring the token MATCH a delimiter takes effect. + + * Expressions are parsed with binding-power `0' until the token + MATCH is reached. If the token SEP does not appear between + each pair of expressions parsed, a warning is issued. + + * If SOP is a procedure, it is applied to the list of LEFT and + the parsed expressions; the resulting value is incorporated + into the expression being built. Otherwise, the list of SOP, + the LEFT expression, and the parsed expressions is + incorporated. + + * The ruleset in effect before TK was parsed is restored; RULE1 + ... are forgotten. + + +File: slib.info, Node: Format, Next: Standard Formatted I/O, Prev: Precedence Parsing, Up: Textual Conversion Packages + +Format (version 3.0) +==================== + + `(require 'format)' + +* Menu: + +* Format Interface:: +* Format Specification:: + + +File: slib.info, Node: Format Interface, Next: Format Specification, Prev: Format, Up: Format + +Format Interface +---------------- + + - Function: format DESTINATION FORMAT-STRING . ARGUMENTS + An almost complete implementation of Common LISP format description + according to the CL reference book `Common LISP' from Guy L. + Steele, Digital Press. Backward compatible to most of the + available Scheme format implementations. + + Returns `#t', `#f' or a string; has side effect of printing + according to FORMAT-STRING. If DESTINATION is `#t', the output is + to the current output port and `#t' is returned. If DESTINATION + is `#f', a formatted string is returned as the result of the call. + NEW: If DESTINATION is a string, DESTINATION is regarded as the + format string; FORMAT-STRING is then the first argument and the + output is returned as a string. If DESTINATION is a number, the + output is to the current error port if available by the + implementation. Otherwise DESTINATION must be an output port and + `#t' is returned. + + FORMAT-STRING must be a string. In case of a formatting error + format returns `#f' and prints a message on the current output or + error port. Characters are output as if the string were output by + the `display' function with the exception of those prefixed by a + tilde (~). For a detailed description of the FORMAT-STRING syntax + please consult a Common LISP format reference manual. For a test + suite to verify this format implementation load `formatst.scm'. + Please send bug reports to `lutzeb@cs.tu-berlin.de'. + + Note: `format' is not reentrant, i.e. only one `format'-call may + be executed at a time. + + + +File: slib.info, Node: Format Specification, Prev: Format Interface, Up: Format + +Format Specification (Format version 3.0) +----------------------------------------- + + Please consult a Common LISP format reference manual for a detailed +description of the format string syntax. For a demonstration of the +implemented directives see `formatst.scm'. + + This implementation supports directive parameters and modifiers (`:' +and `@' characters). Multiple parameters must be separated by a comma +(`,'). Parameters can be numerical parameters (positive or negative), +character parameters (prefixed by a quote character (`''), variable +parameters (`v'), number of rest arguments parameter (`#'), empty and +default parameters. Directive characters are case independent. The +general form of a directive is: + +DIRECTIVE ::= ~{DIRECTIVE-PARAMETER,}[:][@]DIRECTIVE-CHARACTER + +DIRECTIVE-PARAMETER ::= [ [-|+]{0-9}+ | 'CHARACTER | v | # ] + +Implemented CL Format Control Directives +........................................ + + Documentation syntax: Uppercase characters represent the corresponding +control directive characters. Lowercase characters represent control +directive parameter descriptions. + +`~A' + Any (print as `display' does). + `~@A' + left pad. + + `~MINCOL,COLINC,MINPAD,PADCHARA' + full padding. + +`~S' + S-expression (print as `write' does). + `~@S' + left pad. + + `~MINCOL,COLINC,MINPAD,PADCHARS' + full padding. + +`~D' + Decimal. + `~@D' + print number sign always. + + `~:D' + print comma separated. + + `~MINCOL,PADCHAR,COMMACHARD' + padding. + +`~X' + Hexadecimal. + `~@X' + print number sign always. + + `~:X' + print comma separated. + + `~MINCOL,PADCHAR,COMMACHARX' + padding. + +`~O' + Octal. + `~@O' + print number sign always. + + `~:O' + print comma separated. + + `~MINCOL,PADCHAR,COMMACHARO' + padding. + +`~B' + Binary. + `~@B' + print number sign always. + + `~:B' + print comma separated. + + `~MINCOL,PADCHAR,COMMACHARB' + padding. + +`~NR' + Radix N. + `~N,MINCOL,PADCHAR,COMMACHARR' + padding. + +`~@R' + print a number as a Roman numeral. + +`~:@R' + print a number as an "old fashioned" Roman numeral. + +`~:R' + print a number as an ordinal English number. + +`~:@R' + print a number as a cardinal English number. + +`~P' + Plural. + `~@P' + prints `y' and `ies'. + + `~:P' + as `~P but jumps 1 argument backward.' + + `~:@P' + as `~@P but jumps 1 argument backward.' + +`~C' + Character. + `~@C' + prints a character as the reader can understand it (i.e. `#\' + prefixing). + + `~:C' + prints a character as emacs does (eg. `^C' for ASCII 03). + +`~F' + Fixed-format floating-point (prints a flonum like MMM.NNN). + `~WIDTH,DIGITS,SCALE,OVERFLOWCHAR,PADCHARF' + + `~@F' + If the number is positive a plus sign is printed. + +`~E' + Exponential floating-point (prints a flonum like MMM.NNN`E'EE). + `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARE' + + `~@E' + If the number is positive a plus sign is printed. + +`~G' + General floating-point (prints a flonum either fixed or + exponential). + `~WIDTH,DIGITS,EXPONENTDIGITS,SCALE,OVERFLOWCHAR,PADCHAR,EXPONENTCHARG' + + `~@G' + If the number is positive a plus sign is printed. + +`~$' + Dollars floating-point (prints a flonum in fixed with signs + separated). + `~DIGITS,SCALE,WIDTH,PADCHAR$' + + `~@$' + If the number is positive a plus sign is printed. + + `~:@$' + A sign is always printed and appears before the padding. + + `~:$' + The sign appears before the padding. + +`~%' + Newline. + `~N%' + print N newlines. + +`~&' + print newline if not at the beginning of the output line. + `~N&' + prints `~&' and then N-1 newlines. + +`~|' + Page Separator. + `~N|' + print N page separators. + +`~~' + Tilde. + `~N~' + print N tildes. + +`~' + Continuation Line. + `~:' + newline is ignored, white space left. + + `~@' + newline is left, white space ignored. + +`~T' + Tabulation. + `~@T' + relative tabulation. + + `~COLNUM,COLINCT' + full tabulation. + +`~?' + Indirection (expects indirect arguments as a list). + `~@?' + extracts indirect arguments from format arguments. + +`~(STR~)' + Case conversion (converts by `string-downcase'). + `~:(STR~)' + converts by `string-capitalize'. + + `~@(STR~)' + converts by `string-capitalize-first'. + + `~:@(STR~)' + converts by `string-upcase'. + +`~*' + Argument Jumping (jumps 1 argument forward). + `~N*' + jumps N arguments forward. + + `~:*' + jumps 1 argument backward. + + `~N:*' + jumps N arguments backward. + + `~@*' + jumps to the 0th argument. + + `~N@*' + jumps to the Nth argument (beginning from 0) + +`~[STR0~;STR1~;...~;STRN~]' + Conditional Expression (numerical clause conditional). + `~N[' + take argument from N. + + `~@[' + true test conditional. + + `~:[' + if-else-then conditional. + + `~;' + clause separator. + + `~:;' + default clause follows. + +`~{STR~}' + Iteration (args come from the next argument (a list)). + `~N{' + at most N iterations. + + `~:{' + args from next arg (a list of lists). + + `~@{' + args from the rest of arguments. + + `~:@{' + args from the rest args (lists). + +`~^' + Up and out. + `~N^' + aborts if N = 0 + + `~N,M^' + aborts if N = M + + `~N,M,K^' + aborts if N <= M <= K + +Not Implemented CL Format Control Directives +............................................ + +`~:A' + print `#f' as an empty list (see below). + +`~:S' + print `#f' as an empty list (see below). + +`~<~>' + Justification. + +`~:^' + (sorry I don't understand its semantics completely) + +Extended, Replaced and Additional Control Directives +.................................................... + +`~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHD' + +`~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHX' + +`~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHO' + +`~MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHB' + +`~N,MINCOL,PADCHAR,COMMACHAR,COMMAWIDTHR' + COMMAWIDTH is the number of characters between two comma + characters. + +`~I' + print a R4RS complex number as `~F~@Fi' with passed parameters for + `~F'. + +`~Y' + Pretty print formatting of an argument for scheme code lists. + +`~K' + Same as `~?.' + +`~!' + Flushes the output if format DESTINATION is a port. + +`~_' + Print a `#\space' character + `~N_' + print N `#\space' characters. + +`~/' + Print a `#\tab' character + `~N/' + print N `#\tab' characters. + +`~NC' + Takes N as an integer representation for a character. No arguments + are consumed. N is converted to a character by `integer->char'. N + must be a positive decimal number. + +`~:S' + Print out readproof. Prints out internal objects represented as + `#<...>' as strings `"#<...>"' so that the format output can always + be processed by `read'. + +`~:A' + Print out readproof. Prints out internal objects represented as + `#<...>' as strings `"#<...>"' so that the format output can always + be processed by `read'. + +`~Q' + Prints information and a copyright notice on the format + implementation. + `~:Q' + prints format version. + +`~F, ~E, ~G, ~$' + may also print number strings, i.e. passing a number as a string + and format it accordingly. + +Configuration Variables +....................... + + Format has some configuration variables at the beginning of +`format.scm' to suit the systems and users needs. There should be no +modification necessary for the configuration that comes with SLIB. If +modification is desired the variable should be set after the format +code is loaded. Format detects automatically if the running scheme +system implements floating point numbers and complex numbers. + +FORMAT:SYMBOL-CASE-CONV + Symbols are converted by `symbol->string' so the case type of the + printed symbols is implementation dependent. + `format:symbol-case-conv' is a one arg closure which is either + `#f' (no conversion), `string-upcase', `string-downcase' or + `string-capitalize'. (default `#f') + +FORMAT:IOBJ-CASE-CONV + As FORMAT:SYMBOL-CASE-CONV but applies for the representation of + implementation internal objects. (default `#f') + +FORMAT:EXPCH + The character prefixing the exponent value in `~E' printing. + (default `#\E') + +Compatibility With Other Format Implementations +............................................... + +SLIB format 2.x: + See `format.doc'. + +SLIB format 1.4: + Downward compatible except for padding support and `~A', `~S', + `~P', `~X' uppercase printing. SLIB format 1.4 uses C-style + `printf' padding support which is completely replaced by the CL + `format' padding style. + +MIT C-Scheme 7.1: + Downward compatible except for `~', which is not documented + (ignores all characters inside the format string up to a newline + character). (7.1 implements `~a', `~s', ~NEWLINE, `~~', `~%', + numerical and variable parameters and `:/@' modifiers in the CL + sense). + +Elk 1.5/2.0: + Downward compatible except for `~A' and `~S' which print in + uppercase. (Elk implements `~a', `~s', `~~', and `~%' (no + directive parameters or modifiers)). + +Scheme->C 01nov91: + Downward compatible except for an optional destination parameter: + S2C accepts a format call without a destination which returns a + formatted string. This is equivalent to a #f destination in S2C. + (S2C implements `~a', `~s', `~c', `~%', and `~~' (no directive + parameters or modifiers)). + + This implementation of format is solely useful in the SLIB context +because it requires other components provided by SLIB. + + +File: slib.info, Node: Standard Formatted I/O, Next: Programs and Arguments, Prev: Format, Up: Textual Conversion Packages + +Standard Formatted I/O +====================== + +* Menu: + +* Standard Formatted Output:: 'printf +* Standard Formatted Input:: 'scanf + +stdio +----- + + `(require 'stdio)' + + `require's `printf' and `scanf' and additionally defines the symbols: + + - Variable: stdin + Defined to be `(current-input-port)'. + + - Variable: stdout + Defined to be `(current-output-port)'. + + - Variable: stderr + Defined to be `(current-error-port)'. + + +File: slib.info, Node: Standard Formatted Output, Next: Standard Formatted Input, Prev: Standard Formatted I/O, Up: Standard Formatted I/O + +Standard Formatted Output +------------------------- + + `(require 'printf)' + + - Procedure: printf FORMAT ARG1 ... + - Procedure: fprintf PORT FORMAT ARG1 ... + - Procedure: sprintf STR FORMAT ARG1 ... + - Procedure: sprintf #F FORMAT ARG1 ... + - Procedure: sprintf K FORMAT ARG1 ... + Each function converts, formats, and outputs its ARG1 ... + arguments according to the control string FORMAT argument and + returns the number of characters output. + + `printf' sends its output to the port `(current-output-port)'. + `fprintf' sends its output to the port PORT. `sprintf' + `string-set!'s locations of the non-constant string argument STR + to the output characters. + + Two extensions of `sprintf' return new strings. If the first + argument is `#f', then the returned string's length is as many + characters as specified by the FORMAT and data; if the first + argument is a non-negative integer K, then the length of the + returned string is also bounded by K. + + The string FORMAT contains plain characters which are copied to + the output stream, and conversion specifications, each of which + results in fetching zero or more of the arguments ARG1 .... The + results are undefined if there are an insufficient number of + arguments for the format. If FORMAT is exhausted while some of the + ARG1 ... arguments remain unused, the excess ARG1 ... arguments + are ignored. + + The conversion specifications in a format string have the form: + + % [ FLAGS ] [ WIDTH ] [ . PRECISION ] [ TYPE ] CONVERSION + + An output conversion specifications consist of an initial `%' + character followed in sequence by: + + * Zero or more "flag characters" that modify the normal + behavior of the conversion specification. + + `-' + Left-justify the result in the field. Normally the + result is right-justified. + + `+' + For the signed `%d' and `%i' conversions and all inexact + conversions, prefix a plus sign if the value is positive. + + ` ' + For the signed `%d' and `%i' conversions, if the result + doesn't start with a plus or minus sign, prefix it with + a space character instead. Since the `+' flag ensures + that the result includes a sign, this flag is ignored if + both are specified. + + `#' + For inexact conversions, `#' specifies that the result + should always include a decimal point, even if no digits + follow it. For the `%g' and `%G' conversions, this also + forces trailing zeros after the decimal point to be + printed where they would otherwise be elided. + + For the `%o' conversion, force the leading digit to be + `0', as if by increasing the precision. For `%x' or + `%X', prefix a leading `0x' or `0X' (respectively) to + the result. This doesn't do anything useful for the + `%d', `%i', or `%u' conversions. Using this flag + produces output which can be parsed by the `scanf' + functions with the `%i' conversion (*note Standard + Formatted Input::.). + + `0' + Pad the field with zeros instead of spaces. The zeros + are placed after any indication of sign or base. This + flag is ignored if the `-' flag is also specified, or if + a precision is specified for an exact converson. + + * An optional decimal integer specifying the "minimum field + width". If the normal conversion produces fewer characters + than this, the field is padded (with spaces or zeros per the + `0' flag) to the specified width. This is a *minimum* width; + if the normal conversion produces more characters than this, + the field is *not* truncated. + + Alternatively, if the field width is `*', the next argument + in the argument list (before the actual value to be printed) + is used as the field width. The width value must be an + integer. If the value is negative it is as though the `-' + flag is set (see above) and the absolute value is used as the + field width. + + * An optional "precision" to specify the number of digits to be + written for numeric conversions and the maximum field width + for string conversions. The precision is specified by a + period (`.') followed optionally by a decimal integer (which + defaults to zero if omitted). + + Alternatively, if the precision is `.*', the next argument in + the argument list (before the actual value to be printed) is + used as the precision. The value must be an integer, and is + ignored if negative. If you specify `*' for both the field + width and precision, the field width argument precedes the + precision argument. The `.*' precision is an enhancement. C + library versions may not accept this syntax. + + For the `%f', `%e', and `%E' conversions, the precision + specifies how many digits follow the decimal-point character. + The default precision is `6'. If the precision is + explicitly `0', the decimal point character is suppressed. + + For the `%g' and `%G' conversions, the precision specifies how + many significant digits to print. Significant digits are the + first digit before the decimal point, and all the digits + after it. If the precision is `0' or not specified for `%g' + or `%G', it is treated like a value of `1'. If the value + being printed cannot be expressed accurately in the specified + number of digits, the value is rounded to the nearest number + that fits. + + For exact conversions, if a precision is supplied it + specifies the minimum number of digits to appear; leading + zeros are produced if necessary. If a precision is not + supplied, the number is printed with as many digits as + necessary. Converting an exact `0' with an explicit + precision of zero produces no characters. + + * An optional one of `l', `h' or `L', which is ignored for + numeric conversions. It is an error to specify these + modifiers for non-numeric conversions. + + * A character that specifies the conversion to be applied. + +Exact Conversions +................. + + `d', `i' + Print an integer as a signed decimal number. `%d' and `%i' + are synonymous for output, but are different when used with + `scanf' for input (*note Standard Formatted Input::.). + + `o' + Print an integer as an unsigned octal number. + + `u' + Print an integer as an unsigned decimal number. + + `x', `X' + Print an integer as an unsigned hexadecimal number. `%x' + prints using the digits `0123456789abcdef'. `%X' prints + using the digits `0123456789ABCDEF'. + +Inexact Conversions +................... + + `f' + Print a floating-point number in fixed-point notation. + + `e', `E' + Print a floating-point number in exponential notation. `%e' + prints `e' between mantissa and exponont. `%E' prints `E' + between mantissa and exponont. + + `g', `G' + Print a floating-point number in either fixed or exponential | + notation, whichever is more appropriate for its magnitude. + Unless an `#' flag has been supplied trailing zeros after a + decimal point will be stripped off. `%g' prints `e' between + mantissa and exponont. `%G' prints `E' between mantissa and + exponent. + +Other Conversions +................. + + `c' + Print a single character. The `-' flag is the only one which + can be specified. It is an error to specify a precision. + + `s' + Print a string. The `-' flag is the only one which can be + specified. A precision specifies the maximum number of + characters to output; otherwise all characters in the string + are output. + + `a', `A' + Print a scheme expression. The `-' flag left-justifies the + output. The `#' flag specifies that strings and characters + should be quoted as by `write' (which can be read using + `read'); otherwise, output is as `display' prints. A + precision specifies the maximum number of characters to + output; otherwise as many characters as needed are output. + + *Note:* `%a' and `%A' are SLIB extensions. + + `%' + Print a literal `%' character. No argument is consumed. It + is an error to specifiy flags, field width, precision, or + type modifiers with `%%'. + + +File: slib.info, Node: Standard Formatted Input, Prev: Standard Formatted Output, Up: Standard Formatted I/O + +Standard Formatted Input +------------------------ + + `(require 'scanf)' + + - Function: scanf-read-list FORMAT + - Function: scanf-read-list FORMAT PORT + - Function: scanf-read-list FORMAT STRING + + - Macro: scanf FORMAT ARG1 ... + - Macro: fscanf PORT FORMAT ARG1 ... + - Macro: sscanf STR FORMAT ARG1 ... + Each function reads characters, interpreting them according to the + control string FORMAT argument. + + `scanf-read-list' returns a list of the items specified as far as + the input matches FORMAT. `scanf', `fscanf', and `sscanf' return + the number of items successfully matched and stored. `scanf', + `fscanf', and `sscanf' also set the location corresponding to ARG1 + ... using the methods: + + symbol + `set!' + + car expression + `set-car!' + + cdr expression + `set-cdr!' + + vector-ref expression + `vector-set!' + + substring expression + `substring-move-left!' + + The argument to a `substring' expression in ARG1 ... must be a + non-constant string. Characters will be stored starting at the + position specified by the second argument to `substring'. The + number of characters stored will be limited by either the position + specified by the third argument to `substring' or the length of the + matched string, whichever is less. + + The control string, FORMAT, contains conversion specifications and + other characters used to direct interpretation of input sequences. + The control string contains: + + * White-space characters (blanks, tabs, newlines, or formfeeds) + that cause input to be read (and discarded) up to the next + non-white-space character. + + * An ordinary character (not `%') that must match the next + character of the input stream. + + * Conversion specifications, consisting of the character `%', an + optional assignment suppressing character `*', an optional + numerical maximum-field width, an optional `l', `h' or `L' + which is ignored, and a conversion code. + + Unless the specification contains the `n' conversion character + (described below), a conversion specification directs the + conversion of the next input field. The result of a conversion + specification is returned in the position of the corresponding + argument points, unless `*' indicates assignment suppression. + Assignment suppression provides a way to describe an input field + to be skipped. An input field is defined as a string of + characters; it extends to the next inappropriate character or + until the field width, if specified, is exhausted. + + *Note:* This specification of format strings differs from the + `ANSI C' and `POSIX' specifications. In SLIB, white space + before an input field is not skipped unless white space + appears before the conversion specification in the format + string. In order to write format strings which work + identically with `ANSI C' and SLIB, prepend whitespace to all + conversion specifications except `[' and `c'. + + The conversion code indicates the interpretation of the input + field; For a suppressed field, no value is returned. The + following conversion codes are legal: + + `%' + A single % is expected in the input at this point; no value + is returned. + + `d', `D' + A decimal integer is expected. + + `u', `U' + An unsigned decimal integer is expected. + + `o', `O' + An octal integer is expected. + + `x', `X' + A hexadecimal integer is expected. + + `i' + An integer is expected. Returns the value of the next input + item, interpreted according to C conventions; a leading `0' + implies octal, a leading `0x' implies hexadecimal; otherwise, + decimal is assumed. + + `n' + Returns the total number of bytes (including white space) + read by `scanf'. No input is consumed by `%n'. + + `f', `F', `e', `E', `g', `G' + A floating-point number is expected. The input format for + floating-point numbers is an optionally signed string of + digits, possibly containing a radix character `.', followed + by an optional exponent field consisting of an `E' or an `e', + followed by an optional `+', `-', or space, followed by an + integer. + + `c', `C' + WIDTH characters are expected. The normal + skip-over-white-space is suppressed in this case; to read the + next non-space character, use `%1s'. If a field width is + given, a string is returned; up to the indicated number of + characters is read. + + `s', `S' + A character string is expected The input field is terminated + by a white-space character. `scanf' cannot read a null + string. + + `[' + Indicates string data and the normal + skip-over-leading-white-space is suppressed. The left + bracket is followed by a set of characters, called the + scanset, and a right bracket; the input field is the maximal + sequence of input characters consisting entirely of + characters in the scanset. `^', when it appears as the first + character in the scanset, serves as a complement operator and + redefines the scanset as the set of all characters not + contained in the remainder of the scanset string. + Construction of the scanset follows certain conventions. A + range of characters may be represented by the construct + first-last, enabling `[0123456789]' to be expressed `[0-9]'. + Using this convention, first must be lexically less than or + equal to last; otherwise, the dash stands for itself. The + dash also stands for itself when it is the first or the last + character in the scanset. To include the right square + bracket as an element of the scanset, it must appear as the + first character (possibly preceded by a `^') of the scanset, + in which case it will not be interpreted syntactically as the + closing bracket. At least one character must match for this + conversion to succeed. + + The `scanf' functions terminate their conversions at end-of-file, + at the end of the control string, or when an input character + conflicts with the control string. In the latter case, the + offending character is left unread in the input stream. + + +File: slib.info, Node: Programs and Arguments, Next: HTML HTTP and CGI, Prev: Standard Formatted I/O, Up: Textual Conversion Packages + +Program and Arguments +===================== + +* Menu: + +* Getopt:: Command Line option parsing +* Command Line:: A command line reader for Scheme shells +* Parameter lists:: 'parameters +* Getopt Parameter lists:: 'getopt-parameters +* Filenames:: 'glob or 'filename +* Batch:: 'batch + + +File: slib.info, Node: Getopt, Next: Command Line, Prev: Programs and Arguments, Up: Programs and Arguments + +Getopt +------ + + `(require 'getopt)' + + This routine implements Posix command line argument parsing. Notice +that returning values through global variables means that `getopt' is +*not* reentrant. + + - Variable: *optind* + Is the index of the current element of the command line. It is + initially one. In order to parse a new command line or reparse an + old one, *OPTING* must be reset. + + - Variable: *optarg* + Is set by getopt to the (string) option-argument of the current + option. + + - Procedure: getopt ARGC ARGV OPTSTRING + Returns the next option letter in ARGV (starting from `(vector-ref + argv *optind*)') that matches a letter in OPTSTRING. ARGV is a + vector or list of strings, the 0th of which getopt usually + ignores. ARGC is the argument count, usually the length of ARGV. + OPTSTRING is a string of recognized option characters; if a + character is followed by a colon, the option takes an argument + which may be immediately following it in the string or in the next + element of ARGV. + + *OPTIND* is the index of the next element of the ARGV vector to be + processed. It is initialized to 1 by `getopt.scm', and `getopt' + updates it when it finishes with each element of ARGV. + + `getopt' returns the next option character from ARGV that matches + a character in OPTSTRING, if there is one that matches. If the + option takes an argument, `getopt' sets the variable *OPTARG* to + the option-argument as follows: + + * If the option was the last character in the string pointed to + by an element of ARGV, then *OPTARG* contains the next + element of ARGV, and *OPTIND* is incremented by 2. If the + resulting value of *OPTIND* is greater than or equal to ARGC, + this indicates a missing option argument, and `getopt' + returns an error indication. + + * Otherwise, *OPTARG* is set to the string following the option + character in that element of ARGV, and *OPTIND* is + incremented by 1. + + If, when `getopt' is called, the string `(vector-ref argv + *optind*)' either does not begin with the character `#\-' or is + just `"-"', `getopt' returns `#f' without changing *OPTIND*. If + `(vector-ref argv *optind*)' is the string `"--"', `getopt' + returns `#f' after incrementing *OPTIND*. + + If `getopt' encounters an option character that is not contained in + OPTSTRING, it returns the question-mark `#\?' character. If it + detects a missing option argument, it returns the colon character + `#\:' if the first character of OPTSTRING was a colon, or a + question-mark character otherwise. In either case, `getopt' sets + the variable GETOPT:OPT to the option character that caused the + error. + + The special option `"--"' can be used to delimit the end of the + options; `#f' is returned, and `"--"' is skipped. + + RETURN VALUE + + `getopt' returns the next option character specified on the command + line. A colon `#\:' is returned if `getopt' detects a missing + argument and the first character of OPTSTRING was a colon `#\:'. + + A question-mark `#\?' is returned if `getopt' encounters an option + character not in OPTSTRING or detects a missing argument and the + first character of OPTSTRING was not a colon `#\:'. + + Otherwise, `getopt' returns `#f' when all command line options + have been parsed. + + Example: + #! /usr/local/bin/scm + ;;;This code is SCM specific. + (define argv (program-arguments)) + (require 'getopt) + + (define opts ":a:b:cd") + (let loop ((opt (getopt (length argv) argv opts))) + (case opt + ((#\a) (print "option a: " *optarg*)) + ((#\b) (print "option b: " *optarg*)) + ((#\c) (print "option c")) + ((#\d) (print "option d")) + ((#\?) (print "error" getopt:opt)) + ((#\:) (print "missing arg" getopt:opt)) + ((#f) (if (< *optind* (length argv)) + (print "argv[" *optind* "]=" + (list-ref argv *optind*))) + (set! *optind* (+ *optind* 1)))) + (if (< *optind* (length argv)) + (loop (getopt (length argv) argv opts)))) + + (slib:exit) + +Getopt- +------- + + - Function: getopt- ARGC ARGV OPTSTRING + The procedure `getopt--' is an extended version of `getopt' which + parses "long option names" of the form `--hold-the-onions' and + `--verbosity-level=extreme'. `Getopt--' behaves as `getopt' + except for non-empty options beginning with `--'. + + Options beginning with `--' are returned as strings rather than + characters. If a value is assigned (using `=') to a long option, + `*optarg*' is set to the value. The `=' and value are not + returned as part of the option string. + + No information is passed to `getopt--' concerning which long + options should be accepted or whether such options can take + arguments. If a long option did not have an argument, `*optarg' + will be set to `#f'. The caller is responsible for detecting and + reporting errors. + + (define opts ":-:b:") + (define argc 5) + (define argv '("foo" "-b9" "--f1" "--2=" "--g3=35234.342" "--")) + (define *optind* 1) + (define *optarg* #f) + (require 'qp) + (do ((i 5 (+ -1 i))) + ((zero? i)) + (define opt (getopt-- argc argv opts)) + (print *optind* opt *optarg*))) + -| + 2 #\b "9" + 3 "f1" #f + 4 "2" "" + 5 "g3" "35234.342" + 5 #f "35234.342" + + +File: slib.info, Node: Command Line, Next: Parameter lists, Prev: Getopt, Up: Programs and Arguments + +Command Line +------------ + + `(require 'read-command)' + + - Function: read-command PORT + - Function: read-command + `read-command' converts a "command line" into a list of strings + suitable for parsing by `getopt'. The syntax of command lines + supported resembles that of popular "shell"s. `read-command' + updates PORT to point to the first character past the command + delimiter. + + If an end of file is encountered in the input before any + characters are found that can begin an object or comment, then an + end of file object is returned. + + The PORT argument may be omitted, in which case it defaults to the + value returned by `current-input-port'. + + The fields into which the command line is split are delimited by + whitespace as defined by `char-whitespace?'. The end of a command + is delimited by end-of-file or unescaped semicolon (<;>) or + . Any character can be literally included in a field by + escaping it with a backslach (<\>). + + The initial character and types of fields recognized are: + `\' + The next character has is taken literally and not interpreted + as a field delimiter. If <\> is the last character before a + , that is just ignored. Processing + continues from the characters after the as though + the backslash and were not there. + + `"' + The characters up to the next unescaped <"> are taken + literally, according to [R4RS] rules for literal strings + (*note Strings: (r4rs)Strings.). + + `(', `%'' + One scheme expression is `read' starting with this character. + The `read' expression is evaluated, converted to a string + (using `display'), and replaces the expression in the returned + field. + + `;' + Semicolon delimits a command. Using semicolons more than one + command can appear on a line. Escaped semicolons and + semicolons inside strings do not delimit commands. + + The comment field differs from the previous fields in that it must + be the first character of a command or appear after whitespace in + order to be recognized. <#> can be part of fields if these + conditions are not met. For instance, `ab#c' is just the field + ab#c. + + `#' + Introduces a comment. The comment continues to the end of + the line on which the semicolon appears. Comments are + treated as whitespace by `read-dommand-line' and backslashes + before s in comments are also ignored. + + - Function: read-options-file FILENAME + `read-options-file' converts an "options file" into a list of + strings suitable for parsing by `getopt'. The syntax of options + files is the same as the syntax for command lines, except that + s do not terminate reading (only <;> or end of file). + + If an end of file is encountered before any characters are found + that can begin an object or comment, then an end of file object is + returned. + + +File: slib.info, Node: Parameter lists, Next: Getopt Parameter lists, Prev: Command Line, Up: Programs and Arguments + +Parameter lists +--------------- + + `(require 'parameters)' + +Arguments to procedures in scheme are distinguished from each other by +their position in the procedure call. This can be confusing when a +procedure takes many arguments, many of which are not often used. + +A "parameter-list" is a way of passing named information to a +procedure. Procedures are also defined to set unused parameters to +default values, check parameters, and combine parameter lists. + +A PARAMETER has the form `(parameter-name value1 ...)'. This format +allows for more than one value per parameter-name. + +A PARAMETER-LIST is a list of PARAMETERs, each with a different +PARAMETER-NAME. + + - Function: make-parameter-list PARAMETER-NAMES + Returns an empty parameter-list with slots for PARAMETER-NAMES. + + - Function: parameter-list-ref PARAMETER-LIST PARAMETER-NAME + PARAMETER-NAME must name a valid slot of PARAMETER-LIST. + `parameter-list-ref' returns the value of parameter PARAMETER-NAME + of PARAMETER-LIST. + + - Procedure: adjoin-parameters! PARAMETER-LIST PARAMETER1 ... + Returns PARAMETER-LIST with PARAMETER1 ... merged in. + + - Procedure: parameter-list-expand EXPANDERS PARAMETER-LIST + EXPANDERS is a list of procedures whose order matches the order of + the PARAMETER-NAMEs in the call to `make-parameter-list' which + created PARAMETER-LIST. For each non-false element of EXPANDERS + that procedure is mapped over the corresponding parameter value + and the returned parameter lists are merged into PARAMETER-LIST. + + This process is repeated until PARAMETER-LIST stops growing. The + value returned from `parameter-list-expand' is unspecified. + + - Function: fill-empty-parameters DEFAULTERS PARAMETER-LIST + DEFAULTERS is a list of procedures whose order matches the order + of the PARAMETER-NAMEs in the call to `make-parameter-list' which + created PARAMETER-LIST. `fill-empty-parameters' returns a new + parameter-list with each empty parameter replaced with the list + returned by calling the corresponding DEFAULTER with + PARAMETER-LIST as its argument. + + - Function: check-parameters CHECKS PARAMETER-LIST + CHECKS is a list of procedures whose order matches the order of + the PARAMETER-NAMEs in the call to `make-parameter-list' which + created PARAMETER-LIST. + + `check-parameters' returns PARAMETER-LIST if each CHECK of the + corresponding PARAMETER-LIST returns non-false. If some CHECK + returns `#f' an error is signaled. + +In the following procedures ARITIES is a list of symbols. The elements +of `arities' can be: + +`single' + Requires a single parameter. + +`optional' + A single parameter or no parameter is acceptable. + +`boolean' + A single boolean parameter or zero parameters is acceptable. + +`nary' + Any number of parameters are acceptable. + +`nary1' + One or more of parameters are acceptable. + + - Function: parameter-list->arglist POSITIONS ARITIES TYPES + PARAMETER-LIST + Returns PARAMETER-LIST converted to an argument list. Parameters + of ARITY type `single' and `boolean' are converted to the single + value associated with them. The other ARITY types are converted + to lists of the value(s) of type TYPES. + + POSITIONS is a list of positive integers whose order matches the + order of the PARAMETER-NAMEs in the call to `make-parameter-list' + which created PARAMETER-LIST. The integers specify in which + argument position the corresponding parameter should appear. + + +File: slib.info, Node: Getopt Parameter lists, Next: Filenames, Prev: Parameter lists, Up: Programs and Arguments + +Getopt Parameter lists +---------------------- + + `(require 'getopt-parameters)' + + - Function: getopt->parameter-list ARGC ARGV OPTNAMES ARITIES TYPES + ALIASES + Returns ARGV converted to a parameter-list. OPTNAMES are the + parameter-names. ALIASES is a list of lists of strings and + elements of OPTNAMES. Each of these strings which have length of + 1 will be treated as a single <-> option by `getopt'. Longer + strings will be treated as long-named options (*note getopt-: + Getopt.). + + - Function: getopt->arglist ARGC ARGV OPTNAMES POSITIONS ARITIES TYPES + DEFAULTERS CHECKS ALIASES + Like `getopt->parameter-list', but converts ARGV to an + argument-list as specified by OPTNAMES, POSITIONS, ARITIES, TYPES, + DEFAULTERS, CHECKS, and ALIASES. + +These `getopt' functions can be used with SLIB relational databases. +For an example, *Note make-command-server: Database Utilities. + +If errors are encountered while processing options, directions for using +the options are printed to `current-error-port'. + + (begin + (set! *optind* 1) + (getopt->parameter-list + 2 + '("cmd" "-?") + '(flag number symbols symbols string flag2 flag3 num2 num3) + '(boolean optional nary1 nary single boolean boolean nary nary) + '(boolean integer symbol symbol string boolean boolean integer integer) + '(("flag" flag) + ("f" flag) + ("Flag" flag2) + ("B" flag3) + ("optional" number) + ("o" number) + ("nary1" symbols) + ("N" symbols) + ("nary" symbols) + ("n" symbols) + ("single" string) + ("s" string) + ("a" num2) + ("Abs" num3)))) + -| + Usage: cmd [OPTION ARGUMENT ...] ... + + -f, --flag + -o, --optional= + -n, --nary= ... + -N, --nary1= ... + -s, --single= + --Flag + -B + -a ... + --Abs= ... + + ERROR: getopt->parameter-list "unrecognized option" "-?" + + +File: slib.info, Node: Filenames, Next: Batch, Prev: Getopt Parameter lists, Up: Programs and Arguments + +Filenames +--------- + + `(require 'filename)' or `(require 'glob)' + + - Function: filename:match?? PATTERN + - Function: filename:match-ci?? PATTERN + Returns a predicate which returns a non-false value if its string + argument matches (the string) PATTERN, false otherwise. Filename + matching is like "glob" expansion described the bash manpage, + except that names beginning with `.' are matched and `/' + characters are not treated specially. + + These functions interpret the following characters specially in + PATTERN strings: + `*' + Matches any string, including the null string. + + `?' + Matches any single character. + + `[...]' + Matches any one of the enclosed characters. A pair of + characters separated by a minus sign (-) denotes a range; any + character lexically between those two characters, inclusive, + is matched. If the first character following the `[' is a + `!' or a `^' then any character not enclosed is matched. A + `-' or `]' may be matched by including it as the first or + last character in the set. + + + - Function: filename:substitute?? PATTERN TEMPLATE + - Function: filename:substitute-ci?? PATTERN TEMPLATE + Returns a function transforming a single string argument according + to glob patterns PATTERN and TEMPLATE. PATTERN and TEMPLATE must + have the same number of wildcard specifications, which need not be + identical. PATTERN and TEMPLATE may have a different number of + literal sections. If an argument to the function matches PATTERN + in the sense of `filename:match??' then it returns a copy of + TEMPLATE in which each wildcard specification is replaced by the + part of the argument matched by the corresponding wildcard + specification in PATTERN. A `*' wildcard matches the longest + leftmost string possible. If the argument does not match PATTERN + then false is returned. + + TEMPLATE may be a function accepting the same number of string + arguments as there are wildcard specifications in PATTERN. In the + case of a match the result of applying TEMPLATE to a list of the + substrings matched by wildcard specifications will be returned, + otherwise TEMPLATE will not be called and `#f' will be returned. + + ((filename:substitute?? "scm_[0-9]*.html" "scm5c4_??.htm") + "scm_10.html") + => "scm5c4_10.htm" + ((filename:substitute?? "??" "beg?mid?end") "AZ") + => "begAmidZend" + ((filename:substitute?? "*na*" "?NA?") "banana") + => "banaNA" + ((filename:substitute?? "?*?" (lambda (s1 s2 s3) (string-append s3 s1))) "ABZ") + => "ZA" + + - Function: replace-suffix STR OLD NEW + STR can be a string or a list of strings. Returns a new string + (or strings) similar to `str' but with the suffix string OLD + removed and the suffix string NEW appended. If the end of STR + does not match OLD, an error is signaled. + + (replace-suffix "/usr/local/lib/slib/batch.scm" ".scm" ".c") + => "/usr/local/lib/slib/batch.c" + + +File: slib.info, Node: Batch, Prev: Filenames, Up: Programs and Arguments + +Batch +----- + + `(require 'batch)' + +The batch procedures provide a way to write and execute portable scripts +for a variety of operating systems. Each `batch:' procedure takes as +its first argument a parameter-list (*note Parameter lists::.). This +parameter-list argument PARMS contains named associations. Batch +currently uses 2 of these: + +`batch-port' + The port on which to write lines of the batch file. + +`batch-dialect' + The syntax of batch file to generate. Currently supported are: + * unix + + * dos + + * vms + + * amigados + + * system + + * *unknown* + +`batch.scm' uses 2 enhanced relational tables (*note Database +Utilities::.) to store information linking the names of +`operating-system's to `batch-dialect'es. + + - Function: batch:initialize! DATABASE + Defines `operating-system' and `batch-dialect' tables and adds the + domain `operating-system' to the enhanced relational database + DATABASE. + + - Variable: batch:platform + Is batch's best guess as to which operating-system it is running + under. `batch:platform' is set to `(software-type)' (*note + Configuration::.) unless `(software-type)' is `unix', in which + case finer distinctions are made. + + - Function: batch:call-with-output-script PARMS FILE PROC + PROC should be a procedure of one argument. If FILE is an + output-port, `batch:call-with-output-script' writes an appropriate + header to FILE and then calls PROC with FILE as the only argument. + If FILE is a string, `batch:call-with-output-script' opens a + output-file of name FILE, writes an appropriate header to FILE, + and then calls PROC with the newly opened port as the only + argument. Otherwise, `batch:call-with-output-script' acts as if + it was called with the result of `(current-output-port)' as its + third argument. + | +The rest of the `batch:' procedures write (or execute if +`batch-dialect' is `system') commands to the batch port which has been +added to PARMS or `(copy-tree PARMS)' by the code: + + (adjoin-parameters! PARMS (list 'batch-port PORT)) + + - Function: batch:command PARMS STRING1 STRING2 ... | + Calls `batch:try-command' (below) with arguments, but signals an | + error if `batch:try-command' returns `#f'. | + +These functions return a non-false value if the command was successfully +translated into the batch dialect and `#f' if not. In the case of the +`system' dialect, the value is non-false if the operation suceeded. + + - Function: batch:try-command PARMS STRING1 STRING2 ... | + Writes a command to the `batch-port' in PARMS which executes the + program named STRING1 with arguments STRING2 .... + + - Function: batch:try-chopped-command PARMS ARG1 ARG2 ... LIST | + breaks the last argument LIST into chunks small enough so that the | + command: | + | + ARG1 ARG2 ... CHUNK | + | + fits withing the platform's maximum command-line length. | + | + `batch:try-chopped-command' calls `batch:try-command' with the | + command and returns non-false only if the commands all fit and | + `batch:try-command' of each command line returned non-false. | + | + - Function: batch:run-script PARMS STRING1 STRING2 ... + Writes a command to the `batch-port' in PARMS which executes the + batch script named STRING1 with arguments STRING2 .... + + *Note:* `batch:run-script' and `batch:try-command' are not the | + same for some operating systems (VMS). | + + - Function: batch:comment PARMS LINE1 ... + Writes comment lines LINE1 ... to the `batch-port' in PARMS. + + - Function: batch:lines->file PARMS FILE LINE1 ... + Writes commands to the `batch-port' in PARMS which create a file + named FILE with contents LINE1 .... + + - Function: batch:delete-file PARMS FILE + Writes a command to the `batch-port' in PARMS which deletes the + file named FILE. + + - Function: batch:rename-file PARMS OLD-NAME NEW-NAME + Writes a command to the `batch-port' in PARMS which renames the + file OLD-NAME to NEW-NAME. + +In addition, batch provides some small utilities very useful for writing +scripts: + + - Function: truncate-up-to PATH CHAR + - Function: truncate-up-to PATH STRING + - Function: truncate-up-to PATH CHARLIST + PATH can be a string or a list of strings. Returns PATH sans any + prefixes ending with a character of the second argument. This can + be used to derive a filename moved locally from elsewhere. + + (truncate-up-to "/usr/local/lib/slib/batch.scm" "/") + => "batch.scm" + + - Function: string-join JOINER STRING1 ... + Returns a new string consisting of all the strings STRING1 ... in + order appended together with the string JOINER between each + adjacent pair. + + - Function: must-be-first LIST1 LIST2 + Returns a new list consisting of the elements of LIST2 ordered so + that if some elements of LIST1 are `equal?' to elements of LIST2, + then those elements will appear first and in the order of LIST1. + + - Function: must-be-last LIST1 LIST2 + Returns a new list consisting of the elements of LIST1 ordered so + that if some elements of LIST2 are `equal?' to elements of LIST1, + then those elements will appear last and in the order of LIST2. + + - Function: os->batch-dialect OSNAME + Returns its best guess for the `batch-dialect' to be used for the + operating-system named OSNAME. `os->batch-dialect' uses the + tables added to DATABASE by `batch:initialize!'. + +Here is an example of the use of most of batch's procedures: + + (require 'database-utilities) + (require 'parameters) + (require 'batch) + (require 'glob) + + (define batch (create-database #f 'alist-table)) + (batch:initialize! batch) + + (define my-parameters + (list (list 'batch-dialect (os->batch-dialect batch:platform)) + (list 'platform batch:platform) + (list 'batch-port (current-output-port)))) ;gets filled in later + + (batch:call-with-output-script + my-parameters + "my-batch" + (lambda (batch-port) + (adjoin-parameters! my-parameters (list 'batch-port batch-port)) + (and + (batch:comment my-parameters + "================ Write file with C program.") + (batch:rename-file my-parameters "hello.c" "hello.c~") + (batch:lines->file my-parameters "hello.c" + "#include " + "int main(int argc, char **argv)" + "{" + " printf(\"hello world\\n\");" + " return 0;" + "}" ) + (batch:command my-parameters "cc" "-c" "hello.c") | + (batch:command my-parameters "cc" "-o" "hello" | + (replace-suffix "hello.c" ".c" ".o")) + (batch:command my-parameters "hello") | + (batch:delete-file my-parameters "hello") + (batch:delete-file my-parameters "hello.c") + (batch:delete-file my-parameters "hello.o") + (batch:delete-file my-parameters "my-batch") + ))) + +Produces the file `my-batch': + + #!/bin/sh + # "my-batch" script created by SLIB/batch Sun Oct 31 18:24:10 1999 | + # ================ Write file with C program. + mv -f hello.c hello.c~ + rm -f hello.c + echo '#include '>>hello.c + echo 'int main(int argc, char **argv)'>>hello.c + echo '{'>>hello.c + echo ' printf("hello world\n");'>>hello.c + echo ' return 0;'>>hello.c + echo '}'>>hello.c + cc -c hello.c + cc -o hello hello.o + hello + rm -f hello + rm -f hello.c + rm -f hello.o + rm -f my-batch + +When run, `my-batch' prints: + + bash$ my-batch + mv: hello.c: No such file or directory + hello world + + +File: slib.info, Node: HTML HTTP and CGI, Next: Printing Scheme, Prev: Programs and Arguments, Up: Textual Conversion Packages + +HTML Forms +========== + + `(require 'html-form)' + + - Variable: *html:output-port* + Procedure names starting with `html:' send their output to the + port *HTML:OUTPUT-PORT*. *HTML:OUTPUT-PORT* is initially the + current output port. + + - Function: make-atval TXT + Returns a string with character substitutions appropriate to send + TXT as an "attribute-value". + + - Function: make-plain TXT + Returns a string with character substitutions appropriate to send + TXT as an "plain-text". + + - Function: html:start-page TITLE BACKLINK TAGS ... + - Function: html:start-page TITLE BACKLINK + - Function: html:start-page TITLE + Outputs headers for an HTML page named TITLE. If string arguments + BACKLINK ... are supplied they are printed verbatim within the + section. + + - Function: html:end-page + Outputs HTML codes to end a page. + + - Function: html:pre LINE1 LINE ... + Writes (using `html:printf') the strings LINE1, LINES as + "PRE"formmated plain text (rendered in fixed-width font). + Newlines are inserted between LINE1, LINES. HTML tags (`') + within LINES will be visible verbatim. + + - Function: html:comment LINE1 LINE ... + Writes (using `html:printf') the strings LINE1 as HTML comments. + +HTML Tables +=========== + + - Function: html:start-table CAPTION + + - Function: html:end-table + + - Function: html:heading COLUMNS + Outputs a heading row for the currently-started table. + + - Function: html:href-heading COLUMNS URLS + Outputs a heading row with column-names COLUMNS linked to URLs + URLS. + + - Function: make-row-converter K FOREIGNS + The positive integer K is the primary-key-limit (number of + primary-keys) of the table. FOREIGNS is a list of the filenames of + foreign-key field pages and #f for non foreign-key fields. + + `make-row-converter' returns a procedure taking a row for its + single argument. This returned procedure prints the table row to + *HTML:OUTPUT-PORT*. + + - Function: table-name->filename TABLE-NAME + Returns the symbol TABLE-NAME converted to a filename. + + - Function: table->html CAPTION DB TABLE-NAME MATCH-KEY1 ... + Writes HTML for DB table TABLE-NAME to *HTML:OUTPUT-PORT*. + + The optional MATCH-KEY1 ... arguments restrict actions to a subset + of the table. *Note match-key: Table Operations. + + - Function: table->page DB TABLE-NAME INDEX-FILENAME + Writes a complete HTML page to *HTML:OUTPUT-PORT*. The string + INDEX-FILENAME names the page which refers to this one. + + - Function: catalog->html DB CAPTION + Writes HTML for the catalog table of DB to *HTML:OUTPUT-PORT*. + + - Function: catalog->page DB CAPTION + Writes a complete HTML page for the catalog of DB to + *HTML:OUTPUT-PORT*. + +HTML Forms +========== + + - Function: html:start-form METHOD ACTION + The symbol METHOD is either `get', `head', `post', `put', or + `delete'. `html:start-form' prints the header for an HTML "form". + + - Function: html:end-form PNAME SUBMIT-LABEL + `html:end-form' prints the footer for an HTML "form". The string + SUBMIT-LABEL appears on the button which submits the form. + + - Function: command->html RDB COMMAND-TABLE COMMAND METHOD ACTION + The symbol COMMAND-TABLE names a command table in the RDB + relational database. + + `command->html' writes an HTML-2.0 "form" for command COMMAND to + the current-output-port. The `SUBMIT' button, which is labeled + COMMAND, invokes the URI ACTION with method METHOD with a hidden + attribute `*command*' bound to the command symbol submitted. + + An action may invoke a CGI script + (`http://www.my-site.edu/cgi-bin/search.cgi') or HTTP daemon + (`http://www.my-site.edu:8001'). + + This example demonstrates how to create a HTML-form for the `build' + command. + + (require (in-vicinity (implementation-vicinity) "build.scm")) + (call-with-output-file "buildscm.html" + (lambda (port) + (fluid-let ((*html:output-port* port)) + (html:start-page 'commands) + (command->html + build '*commands* 'build 'post + (or "/cgi-bin/build.cgi" + "http://localhost:8081/buildscm")) + html:end-page))) + +HTTP and CGI service +==================== + + `(require 'html-form)' + + - Function: cgi:serve-command RDB COMMAND-TABLE + Reads a `"POST"' or `"GET"' query from `(current-input-port)' and + executes the encoded command from COMMAND-TABLE in + relational-database RDB. + + This example puts up a plain-text page in response to a CGI query. + + (display "Content-Type: text/plain") (newline) (newline) + (require 'html-form) + (load (in-vicinity (implementation-vicinity) "build.scm")) + (cgi:serve-command build '*commands*) + + - Function: serve-urlencoded-command RDB COMMAND-TABLE URLENCODED + Reads attribute-value pairs from URLENCODED, converts them to + parameters and invokes the RDB command named by the parameter + `*command*'. + + - Function: http:serve-query INPUT-PORT OUTPUT-PORT SERVE-PROC + reads the "query-string" from INPUT-PORT. If this is a valid + `"POST"' or `"GET"' query, then `http:serve-query' calls + SERVE-PROC with two arguments, the query-string and the + header-alist. + + Otherwise, `http:serve-query' replies (to OUTPUT-PORT) with + appropriate HTML describing the problem. + + This example services HTTP queries from port 8081: + + (define socket (make-stream-socket AF_INET 0)) + (socket:bind socket 8081) + (socket:listen socket 10) + (dynamic-wind + (lambda () #f) + (lambda () + (do ((port (socket:accept socket) + (socket:accept socket))) + (#f) + (dynamic-wind + (lambda () #f) + (lambda () + (fluid-let ((*html:output-port* port)) + (http:serve-query + port port + (lambda (query-string header) + (http:send-header + '(("Content-Type" . "text/plain"))) + (with-output-to-port port + (lambda () + (serve-urlencoded-command + build '*commands* query-string))))))) + (lambda () (close-port port))))) + (lambda () (close-port socket))) + + - Function: http:read-request-line PORT + Reads the first non-blank line from PORT and, if successful, + returns a list of three itmes from the request-line: + + 0. Method + + Either one of the symbols `options', `get', `head', `post', + `put', `delete', or `trace'; Or a string. + + 1. Request-URI + + A string. At the minimum, it will be the string `"/"'. + + 2. HTTP-Version + + A string. For example, `HTTP/1.0'. + + - Function: cgi:read-query-string + Reads the "query-string" from `(current-input-port)'. + `cgi:read-query-string' reads a `"POST"' or `"GET"' queries, + depending on the value of `(getenv "REQUEST_METHOD")'. + + +File: slib.info, Node: Printing Scheme, Next: Time and Date, Prev: HTML HTTP and CGI, Up: Textual Conversion Packages + +Printing Scheme +=============== + +* Menu: + +* Generic-Write:: 'generic-write +* Object-To-String:: 'object->string +* Pretty-Print:: 'pretty-print, 'pprint-file + + +File: slib.info, Node: Generic-Write, Next: Object-To-String, Prev: Printing Scheme, Up: Printing Scheme + +Generic-Write +------------- + + `(require 'generic-write)' + + `generic-write' is a procedure that transforms a Scheme data value +(or Scheme program expression) into its textual representation and +prints it. The interface to the procedure is sufficiently general to +easily implement other useful formatting procedures such as pretty +printing, output to a string and truncated output. + + - Procedure: generic-write OBJ DISPLAY? WIDTH OUTPUT + OBJ + Scheme data value to transform. + + DISPLAY? + Boolean, controls whether characters and strings are quoted. + + WIDTH + Extended boolean, selects format: + #f + single line format + + integer > 0 + pretty-print (value = max nb of chars per line) + + OUTPUT + Procedure of 1 argument of string type, called repeatedly with + successive substrings of the textual representation. This + procedure can return `#f' to stop the transformation. + + The value returned by `generic-write' is undefined. + + Examples: + (write obj) == (generic-write obj #f #f DISPLAY-STRING) + (display obj) == (generic-write obj #t #f DISPLAY-STRING) + + where + DISPLAY-STRING == + (lambda (s) (for-each write-char (string->list s)) #t) + + +File: slib.info, Node: Object-To-String, Next: Pretty-Print, Prev: Generic-Write, Up: Printing Scheme + +Object-To-String +---------------- + + `(require 'object->string)' + + - Function: object->string OBJ + Returns the textual representation of OBJ as a string. + + - Function: object->limited-string OBJ LIMIT + Returns the textual representation of OBJ as a string of length at + most LIMIT. + + +File: slib.info, Node: Pretty-Print, Prev: Object-To-String, Up: Printing Scheme + +Pretty-Print +------------ + + `(require 'pretty-print)' + + - Procedure: pretty-print OBJ + - Procedure: pretty-print OBJ PORT + `pretty-print's OBJ on PORT. If PORT is not specified, + `current-output-port' is used. + + Example: + (pretty-print '((1 2 3 4 5) (6 7 8 9 10) (11 12 13 14 15) + (16 17 18 19 20) (21 22 23 24 25))) + -| ((1 2 3 4 5) + -| (6 7 8 9 10) + -| (11 12 13 14 15) + -| (16 17 18 19 20) + -| (21 22 23 24 25)) + + `(require 'pprint-file)' + + - Procedure: pprint-file INFILE + - Procedure: pprint-file INFILE OUTFILE + Pretty-prints all the code in INFILE. If OUTFILE is specified, + the output goes to OUTFILE, otherwise it goes to + `(current-output-port)'. + + - Function: pprint-filter-file INFILE PROC OUTFILE + - Function: pprint-filter-file INFILE PROC + INFILE is a port or a string naming an existing file. Scheme + source code expressions and definitions are read from the port (or + file) and PROC is applied to them sequentially. + + OUTFILE is a port or a string. If no OUTFILE is specified then + `current-output-port' is assumed. These expanded expressions are + then `pretty-print'ed to this port. + + Whitepsace and comments (introduced by `;') which are not part of + scheme expressions are reproduced in the output. This procedure + does not affect the values returned by `current-input-port' and + `current-output-port'. + + `pprint-filter-file' can be used to pre-compile macro-expansion and +thus can reduce loading time. The following will write into +`exp-code.scm' the result of expanding all defmacros in `code.scm'. + (require 'pprint-file) + (require 'defmacroexpand) + (defmacro:load "my-macros.scm") + (pprint-filter-file "code.scm" defmacro:expand* "exp-code.scm") + + +File: slib.info, Node: Time and Date, Next: Vector Graphics, Prev: Printing Scheme, Up: Textual Conversion Packages + +Time and Date +============= + +* Menu: + +* Time Zone:: +* Posix Time:: 'posix-time +* Common-Lisp Time:: 'common-lisp-time + +If `(provided? 'current-time)': + +The procedures `current-time', `difftime', and `offset-time' deal with +a "calendar time" datatype which may or may not be disjoint from other +Scheme datatypes. + + - Function: current-time + Returns the time since 00:00:00 GMT, January 1, 1970, measured in + seconds. Note that the reference time is different from the + reference time for `get-universal-time' in *Note Common-Lisp + Time::. + + - Function: difftime CALTIME1 CALTIME0 + Returns the difference (number of seconds) between twe calendar + times: CALTIME1 - CALTIME0. CALTIME0 may also be a number. + + - Function: offset-time CALTIME OFFSET + Returns the calendar time of CALTIME offset by OFFSET number of + seconds `(+ caltime offset)'. + + +File: slib.info, Node: Time Zone, Next: Posix Time, Prev: Time and Date, Up: Time and Date + +Time Zone +--------- + + (require 'time-zone) + + - Data Format: TZ-string + POSIX standards specify several formats for encoding time-zone + rules. + + : + If the first character of is `/', then + specifies the absolute pathname of a tzfile(5) format + time-zone file. Otherwise, is interpreted as a + pathname within TZFILE:VICINITY (/usr/lib/zoneinfo/) naming a + tzfile(5) format time-zone file. + + + The string consists of 3 or more alphabetic characters. + specifies the time difference from GMT. The + is positive if the local time zone is west of the Prime + Meridian and negative if it is east. can be the + number of hours or hours and minutes (and optionally seconds) + separated by `:'. For example, `-4:30'. + + + is the at least 3 alphabetic characters naming the local + daylight-savings-time. + + + specifies the offset from the Prime Meridian when + daylight-savings-time is in effect. + + The non-tzfile formats can optionally be followed by transition + times specifying the day and time when a zone changes from + standard to daylight-savings and back again. + + ,/