I am running out of my disk quota on this server and am moving
to
http://www.dinukai.org/programming/scheme/.
Updates will be done on the new server from now on.
A document entitled "Lisp as an Alternative to Java -- Erann Gatt, Jet Propulsion Laboratory, California Institute of Technology", dated November 9 1999, says the following. Their expreriment "results show that Lisp's performance is comparable to or better than C++ in terms of execution speed, with significantly lower variability ... Furthermore, development time is significantly lower and less variable than either C++ or Java. Memory consumption is comparable to Java." It also says "development time for the Lisp programs was significantly lower than the development time for the C, C++ and Java programs" and "the difference cannot be accounted for by programmer experience." The experiment was performed with all the programs compiled to native code. So the execution speed has to be evaluated differently for the interpreted Lisp code but the other results seem to be commonly applicable to all Lisp.
For those who like Lisp, there is nothing to be surprised with the above experiment results. They beleive firmly that Lisp is an excellent programming language. But if Lisp is so excellent, a small puzzling fact remains why Lisp is not widely diffused. It would be of time consuming effort to unriddle it if not impossible. The best way would be to show the Lisp's advantages by practice as Mr. Shiro Kawai's Practical Scheme does.
Scheme is the smallest among all the Lisp dialects providing all the necessary features for programming. Scheme is perfectly specified within 50 pages, including index. This is due partly that Scheme is Lisp but no other languages have these compact specifications. Before Scheme, other languages appear to be obtaining a circle from polygon by increasing the number of sides infinitely .
Because Scheme specifications are extremely clear, Scheme programs are to be simple, correct and beautiful from the very beginning of programming skill.
Scheme was created with the concept that "Programming languages shoud be designed not by piling feature on top of feature, but by removing the weakness and restrictions that make additional features appear necessary." It was so designed that "a very small number of rules for forming expressions, with no restrictions on how they are composed, suffice to form a practical and efficient programming language (Revised5 Report on the Algorithmic Language Scheme--r5rs--Introduction)."
If the rules are correct, the programs on those rules are correct. If the number of necessary and sufficient rules are reduced, the applicable domain of the rules is extended. The rules of a programming language are what provides the ways of expression, which give Scheme a diversiform expressiveness. Because each of the diversiform Scheme programs is subject strictly to Scheme rules, every Scheme program is duly correct and clear.
Scheme, invented by Guy Lewis Steele Jr. and Gerald Jay Sussman was first described in 1975. Guy Lewis Steele Jr. is the author of the "Common Lisp Reference Manual(First edition-1984, Second edition-1989)--Digital Press." He writes that Common Lisp is influenced to some extent by Scheme in its Introduction.
Scheme specifications were almost fixed on "Revised4 Report on the Algorithmic Language Scheme--r4rs-1991" after several revisions with introduction of new features such as Common Lisp's study results. The almost all actual Scheme implementaions are at least compliant with r4rs.
The latest specifications of Scheme are provided by Revised5 Report on the Algorithmic Language Scheme--r5rs-1998. R5rs is a super set of r4rs.
プログラミング言語Scheme kindly makes available my translation of r5rs into Japanese.Scheme was first diffused as educational language due to its above mentioned features but it's not limited to education. This page follows Mr. Shiro Kawai and is intended to care the practical aspect of Scheme application.
My translation was first made for myself when I was compelled to use Scheme unable to find documents on it in Japanese. I dared to make it public hoping to have no grave errors because the programs I wrote worked as my understanding of r5rs. I find inacurcies now in my translation. But once made public, it is difficult to motivate myself to remake the translation. I wish the readers to be tolerant enough.
In the meanwhile, it is known there are other versions of translation of r4rs and r5rs and a new translation appears lately made by Mr. Masaaki Murakami. The original r5rs contains lots of difficulties at least for me. Various translations would be of great help for better understanding of the original one.
The OSs I am using are, in the frequency of use order, too, FreeBSD 5.3-STABLE, 6.0-CURRENT, Debian Linux Unstable (kernel 2.4.26), Woody 3.0 (kernel 2.4.26) and Windows 2000. This seems to be exactly in reverse order if seen from number of users.
This table shows how I installed the Scheme implementations for each of them.
Scheme implementaions I installed OS SCM Gauche stklos STk guile mit-scheme FreeBSD* 6.0-CURRENT**/5.3-STABLE*** rpm or gmake configure && make configure && gmake configure && make ports collection binary Debian Linux Unstable****/Woody(3.0r)***** rpm or make configure && make configure && make configure && make apt-get install binary Windows 2000****** make configure && make or binary / / / /
x ... I couldn't install.
/ ... No try.* For those who install SCM from the ports collection, there is a transitory problem in the FreeBSD's system C compiler. See
http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/71684
** 6.0-CURRENT% cc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.4.2 [FreeBSD] 20040728% gcc34 -v
Reading specs from /usr/local/lib/gcc/i386-portbld-freebsd6.0/3.4.3/specs
Configured with: ./..//gcc-3.4-20041105/configure --disable-nls --with-system-zlib --with-libiconv-prefix=/usr/local --program-suffix=34 --with-gxx-include-dir=/usr/local/lib/gcc/i386-portbld-freebsd6.0/3.4.3/include/c++/ --disable-shared --prefix=/usr/local i386-portbld-freebsd6.0 Thread model: posix
gcc version 3.4.3 [FreeBSD]
*** 5.3-STABLE% cc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.4.2 [FreeBSD] 20040728
% gcc34 -v
Reading specs from /usr/local/lib/gcc/i386-portbld-freebsd5.3/3.4.3/specs
Configured with: ./..//gcc-3.4-20041029/configure --disable-nls --with-system-zlib --with-libiconv-prefix=/usr/local --program-suffix=34 --with-gxx-include-dir=/usr/local/lib/gcc/i386-portbld-freebsd5.3/3.4.3/include/c++/ --disable-shared --prefix=/usr/local i386-portbld-freebsd5.3
Thread model: posix
gcc version 3.4.3 20041029 (prerelease) [FreeBSD]**** Debian Linux Unstable Version% cc -v
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.4/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-debug --enable-java-gc=boehm --enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.4 (Debian 1:3.3.4-4)***** Debian Linux Woody (3.0r)
%cc -v
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.4/specs
gcc version 2.95.4 20011002 (Debian prerelease)****** Cygwin environment is used for installing on Windows 2000.
Cygwin environment is available from http://sources.redhat.com/cygwin.- On floating point numbers: Shiro Kawai develops a detailed consideration about a queer behaviour of gcc compiling on the Intel derived CPUs.
For the floating point numbers, there seems to be implementations leaving some inaccuracies on their input/output (cf.(/ 1448997445238699 (expt 10 15) ≒ 1.448997445238699 and (* 6525704354437806 (expt 2 -52))).
Mr. Shiro Kawai kindly informed me of a paper: "Printing Floating-Point Numbers Quickly and Accurately", Robert G. Burger and R. Kent Dybvig, Proceedings of the SIGPLAN '96 Conference on Programming Language Design and Implementation. It describes a quick and accurate output algorithm of the floating point numbers, justified using Chez Scheme. Chez Scheme, principally developed by Mr. R. Kent Dyvig, seems to implement the algorithm.
Most of Scheme implementations provide, howerver, a formatting module like 'printf' or 'format' (SLIB abandonned it though) and the exact output is assured.
SCM
SCM is a Scheme implementation maintained mainly by Mr. Aubrey Jaffer. The latest version is "5d9(2003-11-30)."
SCM source and rpm packages are available from http://swissnet.ai.mit.edu/~jaffer/SCM.html.
SCM is faithfully compliant with r5rs.
My remarks on SCM installation will be reported at About SCM .
SCM is a highly self-contained Scheme inplementation depending on no other external library than SLIB. As the only external library SLIB is written in Scheme, the only thing to do is to let SCM work to make use of it.
SLIB must therefore be installed beforehand to enjoy SCM. SLIB is a comprehensive library with packages written in r5rs Scheme. It is a collection of packages from I/O extension, Scheme's I/O capability, said weak, extended by Scheme itself, to a full featured relational database. Scheme Requests for Implementation (SRFI)
suppott begins and its Xlib interfaces seem practically finished, of which a quick glance can be taken at http://swissnet.ai.mit.edu/~jaffer/Solid/#Example.Another objective of SLIB is to provide a common environment which absorbs slight specification differences existing among the implementations, thus allowing them to work in the same way. To this end, SLIB provides initialization files for each of Scheme implementations. SCM's initialization file is 'ScmInit.scm' placed in the home directory. But no special initilization is needed for SCM to use SLIB.
Gauche
Gauche is a Scheme implementation supporting SLIB. It is develloped by Mr. Shiro Kawai and is evolving frequently toward the release 1.00. The newest version is available at http://www.shiro.dreamhost.com/scheme/gauche/.The latest Gauche version is 0.8.3 at this date and are implemented all r5rs specifications, quite a lot of Scheme Requests for Implementation (SRFI), and POSIX and UNIX system interfaces. Gauche is acquiring its goal steadily. The author knows well the difficulties for making use of Scheme in practical scenes and has been seeking an easy to use and efficient programming language, which produced this piece of work. Gauche is featuring various new devices. An object system is implemented orthogonally to Scheme.
Gauche features the followings as Scheme implementation.
- Designed to handle multi-byte characters including Japanese.
- Very quick start up.
Scheme might often be used as a scripting language. A heavy to start implementation is discouraging at least for me personnally.
- Quick processing
Means a processing speed of Gauche as Scheme interpreter. Gauche is already one of the fastest among the implementations I am using. Accounts taken that the debuggings and the optimizations are still to be done, Gauche makes me expect a farther convenient Scheme environment. Gauche compiles the program codes into the intermediate ones and executes them on a virtual Scheme machine. I think this will help debugging and multi thread execution, too.
- Module System with static scope.
It would be rare to run short of variables with the standard Scheme. Gauche provides a developping environment of modules with static scope farther. The modules' name scope is static to themselves and there is no need to worry about shadowings. This alleviates the developpement burden of large size programs. See SLIB (especially the relational database packages) for the extreme care taken to confine the names within the packages.
Using Scheme as programming language would mean to prefer to write a program in an hour and execute it in a second, instead of developing the program executed in 20 mili seconds at a few days cost with a compiler language. Gauche tries to be an implementation we are dreaming of.
The Gauche evolution and the ways to use it will be followed in a different thread.
STklos
STklos is being developed by Mr. Erick Gallesio as the successor to STk. The version as of today is "0.60". The latest implementation can be downloaded at STklos Home Page.
The name STklos is derived from the concept that the object oriented layer, dealt as extra in STk, becomes the core of the system.
The numerical computation is strikingly fast due to the use of gmp. SLIB is supported but the initialization file `STklos.init' needs to be rewritten.
STk
STk is a Scheme implementation by Mr. Erick Gallesio, available from http://kaolin.unice.fr/STk. The last version is "4.0.1."
STk is r4rs compliant with its original extensions to Scheme.
STklos is STk's object oriented layer similar to CLOS(Common Lisp Object System), implementing metaclasses, multiple inheritance, generic functions and multi-methods.
STk 4.0.1 implements Tk widgets in its hierarchy of STklos classes, thus allowing to manipulate Tk toolkit 8.0.3.
STk's initialization file is .stkrc. Copying the file STk.init existing in slib directory to the home directory with this name allows to use SLIB with (require 'packagename).
- Mr. Shiro Kawai's Practical Scheme, is available for valuable collection of Scheme libraries for day to day use and useful documents not only for Scheme but also for programming in general. I hope this site gets lots of readers to make a major programming language of Scheme.
- Mr. Shinyama makes public a patch to STk, which localizes its Tk part for Japanese. I myself apply this patch to my STk with the following code in .stkrc.
;;; (implementation-vicinity) should be defined to be the pathname of ;;; the directory where any auxillary files to your Scheme ;;; implementation reside. (define (implementation-vicinity) (if (equal? (scheme-implementation-version) "4.0.1jp") "/usr/local/lib/stk/4.0.1jp/" "/usr/local/lib/stk/4.0.1/"))
guile
Guile is a kind of Scheme implementation developed by FSF (Free Software Foundation) as standard scripting language of the GNU project. FSF was unfond of the defacto standardization of Tcl/Tk. Guile is installed if GNOME is available on the system. Guile is available from ftp://ftp.gnu.org/pub/gnu/guile/.
The guile syntax is not fully clear to me because the guile core and the peripheral application developments are by far preceding that of manuals. It is, however, almost r4rs compliant as Scheme implementation. Setting the environment variable GUILE_LOAD_PATH to the slib directory or appending it to the guile variable %load-path by (set! %load-path (append (list "/usr/local/lib") %load-path))) allows to use SLIB with the issue of the following code from within the guile:You then (require 'the-slib-package-name).(use-modules (ice-9 slib))The difference between guile and Scheme is that guile is case sensitive for identifiers and symbols. This is supposedly to make interfacing easy with other languages which are also case sensitive. If the naming is consistant for variables and constants, Scheme programs work as expected with guile, too.
Guile is made easy to integrate GUIs of Tk, gimp and gtk as modules and reversely to let exploit guile objects from other applications.
Guile was originally based on Mr. Aubrey Jaffer's SCM(version 4e1), but is significantly different now. I remember SCM's nimble footwork was lost since its beginning.
The guile evaluation would depend on whether to see it as Scheme extension or as Scheme thickenings. Guile itself keeps growing actively.mit-scheme
I am using mit-scheme only to confirm the behaviour of Scheme programs developed with other implementations. The initialization file for mit-scheme is scheme.init.
In order to use SCM, SLIB must be installed beforehand so that SCM can require it on need.SLIB
SLIB is available from http://swissnet.ai.mit.edu/~jaffer/SLIB.html maintained by Mr. Aubrey Jaffer. The latest version is "3a1". Packages are increasing which do not support older versions of SCM before 5d9. SCM is to be updated to the newest version to make use of SLIB.Unzip slib3a1.zip to a convenient directory with writing permission, for instance to '/usr/local/lib'.
SLIB libraries are opened out into the directory named `slib' under the specified directory. Set the environment variable 'SCHEME_LIBRARY_PATH' to this directory in the environment initialization file. The last forward slash (backslash for Windows) is needed in order to concatenate the file name to the directory path later on.% unzip slib3a1 -d /usr/local/lib
- UNIX/Linux
- If the login shell is csh or tcsh, the environment initialization file is .login, .cshrc or .tcshrc.
setenv SCHEME_LIBRARY_PATH /usr/local/lib/slib/- If the login shell is sh or bash, the environment initialization file is .profile or .bashrc. If the logging in is done through xdm, write the code in .xsession, for example.
SCHEME_LIRBRARY_PATH="/usr/local/lib/slib/" export SCEHEME_LIBRARY_PATH- The envrironment was set by autoexec.bat with Windows98. Specify the correct drive letter for the drive where the directory resides.
With Windows 2000, set the environmental variable through "start -> settings - >control panel -> syste -> details -> environmetal variables."set SCHEME_LIBRARY_PATH=e:/usr/local/lib/slib/Specify an adequate drive letter for the drive where the path to the slib exists.Variable ... SCHEME_LIBRARY_PATH VAlue ... e:/usr/local/lib/slib/There will be no problem of installing SCM and SLIB as far as the destination directory has the write permission for you. If the system enviroment settings are restricted for any reason, a code like this can be put in "require.scm" in the "scm" directory where SCM related files are installed in order to specify directly where SLIB resides:
(set! library-vicinity (lambda () "/compat/linux/usr/share/slib/"))Installing SCM
- Unzip scm5d9.zip to a convenient directory, for instance to $HOME. SCM source files are opened out into the directory named scm under the specified directory.
unzip scm5d9 -d $HOME- It might be worthwhile to check the followings before compiling SCM.
Using the bignum data format
To make maximum use of SCM's bignum data format, I recommend to set the NUMDIGS_MAX defined in scmfig.h to around 20000 digits. If your own Makefiles are used, -DNUMDIGS_MUX=20000 can be passed to the compiler.
- Create scmlit.
make scmlit (gmake scmlit on FreeBSD)- scmlit is created and ready to execute the script file build written in Scheme.
Scmlit is composed of minimum modules allowing to execute the build script and it is highly possible that it is compiled on any OSs.If `scmlit' is successfully created, "make all" will do all the rest in the Linux environment. In other environment where `executable image dump' is not available like FreeBSD, execute `build'. `build' can be used in the Linux environment, too.
There are two formats for build arguments: short one like '-p freebsd' and long one like '--platform=freebsd'. I am explaining with short formats. See for details 'scm.info' file opened out into the scm directory: SCM -- Installing SCM -- Building SCM -- Build Options.
Executing build without -F creates an scm executable featuring only 'arrays', 'bignums' and 'inexact' as default.
- -h batch-script-format
One of unix, dos, vms, amigados or system can be specified for batch-script-format.
If '-h system' is specified, the compilation is executed actually. Other specifications let the program output the batch script to the standard output. SCM in fact is able to choose the batch script format from the environment where the build is executed. So -h option is not needed except for '-h system' specification.
- -p platform-name
Specify the name build database has for platform-name, one of the followings in present case: freebsd, linux, os/2-emx or unix(for cygwin).
The build program will select from its database the compile options and link options related to the platform-name.
- -F feature-name ...
Specify for -F options the names separated by a space from the following table. The feature names marked with * (asterisk) indicate that I could not compile the feature. See scm.info and source files for details of the features.
Features with ability of compilation(o = I could, * = I couldn't, / = not tested) Feature name Description FreeBSD Debian Linux cygwin arrays Multi dimensional arrays o o o array-for-each Array mapping o o o bignums Multiple precision data o o o cautious Number check of arguments o o o compiled-closure Integration of C functions o o o curses curses library o o o debug Error check for debugging o o o dump Executable image dump * o * dynamic-linking Dl library * o * edit-line Line editor o o / engineering-notation Engineering notation o o o generalized-c-arguments Variable number args C functions o o o i/o-extensions ANSI C file I/O o o * inexact Floating point arithmetic o o o macro r5rs macro o o o posix posix functions (pipe,fork,uname etc.) o o o unix Unix functions other than posix(symlink,nice,mknod etc.) o o * record Record data type o o o regex Regular expressions o o * rev2-procedures r2rs procedures o o / sicp (eq? () #f)==>#t, etc / / / socket BSD sockets o o / tick-interrupts ticks, ticks-interrupt, alarm etc. o o o
- dynamic-linking uses `libdl'. 'libdl' is a separate library with Linux. It is included in 'libc' with FreeBSD.- edit-line uses an external library `libreadline'. It brings conveniences for the interactive use of SCM in Terminal mode. If there is inadequacy in `libreadline' or if it is unwanted, just compile SCM without it. Interactive operations can be provided by calling SCM as a subprocess of Emacs or XEmacs.The above specifications force compiling and linking to create a minimum but general-purpose scm executable.build example 1(FreeBSD) ./build -h system -p freebsd
This will create another scm executable accepting dynamic libraries. Only the specified features are included if -F option is specified and all the necessary features must be specified explicitly.
I usually create scm as follows:build example 2(FreeBSD) ./build -h system -p freebsd -F arrays bignums inexact dynamic-linkingThe scm executable thus created is as big as 345227 bytes. It becomes 307508 bytes after stripping and covers allmost all features specified in r5rs.build example 3 ./build -h system -p freebsd -F arrays array-for-each bignums cautious compiled-closure dynamic-linking inexact i/o-extensions macro tick-interrupts
- Confirm the SCM behaviour by executing r4rstest.scm.
./scm r4rstest SECTION(2 1) SECTION(3 4) #<;primitive-procedure boolean?>; ... Passed all tests To fully test continuations, Scheme 4, and DELAY/FORCE do: (test-cont) (test-sc4) (test-delay) SCM> (test-cont) (test-sc4) (test-delay) ... Passed all tests ... (exit)- Execute syntest1.scm to confirm r5rs macro behaviour.
./scm -l syntest1 (let ((x (quote outer))) \ (let-syntax ((m (syntax-rules () ((m) x)))) \ (let ((x (quote inner))) (m)))) ==> outer (let-syntax ((when (syntax-rules () \ ((when ?test ?stmt1 ?stmt2 ...) (if ?test (begin ?stmt1 ?stmt2 ...)))))) \ (let ((if #t)) (when if (set! if (quote now))) if)) ==> now ... (define-syntax replic \ (syntax-rules () \ ((_ (?x ...) (?y ...)) (let ((?x (list ?y ...)) ...) (list ?x ...))))) (replic (x y z) (1 2)) ==> ((1 2) (1 2) (1 2)) Passed all tests Load "syntest2" to rewrite derived expressions and test- Execute syntest2.scm to try redefining r5rs keywords.
./scm -l syntest2 ;While loading "syntest2.scm", line 53: \ WARNING: "/home/scm/Macro.scm": redefining built-in syntax let ... ;While loading "syntest2.scm", line 182: \ WARNING: "/home/scm/Macro.scm": redefining built-in syntax quasiquote- Install
The install is done into the `prefix' directory specified in the Makefile. The catalog files SCM creates are written into it, too. So the directory must be write permitted. Install as super user or specify to `prefix' a directory to which you have the write permission.
make install (prefix=$HOME/)The executable is installed into the `bin' directory under `prefix' and the intilization files like Init$(VERSION).scm into $(prefix)/lib/scm. If there are dynamically loadable libraries (*.so), they are installed into the same directory, too.
On executing SCM after installation, catalog files are created in `scm'directory. Enjoy Scheme world.