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
4.4-RELEASE, Debian Linux Potato (kernel 2.2r1), OS/2 Warp V4.0,
Windows 2000 and Windows 98. This seems to be exactly in reverse
order if seen from number of users.
UNIX and Linux are flexible enough and easy to use but they are not
as widely used as the others are due to their complicated
settings.
This table shows how I installed the Scheme implementations for each of them.
Scheme implementaions I installed OS SCM Gauche STk guile mit-scheme FreeBSD 4.4 make configure && make configure && make configure && make binary Debian Linux 2.2r1 make / configure && make configure && make binary OS/2 Warp V4.0 make / * * binary Windows 2000 make / * * / Windows 98 make / * * /
* ... I could't install.
/ ... Not tried.- Cygwin environment is used for installing on Windows98 and Windows 2000.
Cygwin environment is available from http://sources.redhat.com/cygwin.- Emx environment is used for installing on OS/2. Gnu make and bash are also needed in addition to gcc.
Emx environment is available from http://hobbes.nmsu.edu.- For the SCM on Windows(MS-DOS), a binary is also available from Mr. Jaffer's site. However, *.scm files have to exist in the (implementation-vicinity) to execute the binary in addition to the SLIB library described below.- On floating point numbers on FreeBSD, there is a problem that its mantissa precision defaults to 53 bits, for which the r4rstest.scm described below fails. The problem could be worked around by embedding some codes for SCM on FreeBSD. Linux has no such a problme.
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.
SCM
SCM is a Scheme implementation made mainly by Mr. Aubrey Jaffer. The latest version is "5d4".
SCM is available from http://swissnet.ai.mit.edu/~jaffer/SCM.html.
SCM is compliant with r5rs and the fastest among all the Scheme implementations I am using.
Remarks I made on SCM installation will be reported at About SCM .
SLIB must be installed before using SCM. SLIB is a library containg 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.
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' put in the home directory. But no special initilization is needed for SCM to use SLIB.
Gauche
Gauche is one of the newest Scheme implementations made 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/. It is scheduled to implement the multi thread at release 0.6 and the GTk interface at release 0.7.Gauche actual version is 0.4.11 at this date and are implemented all r5rs specifications, certain parts of Scheme Requests for Implementation (SRFI), and POSIX and UNIX system interfaces. Gauche seems to have now acquired all practical features as a Scheme implementation. The author knows very 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 and an object system is implemented orthogonally to Scheme.
Gauche features the followings as Scheme implementation.
- Designed to process multi byte characters including Japanese.
Guile once tried it but gave it up. I think there was an inconsistency problem with other systems processing multi byte characters.
- Very quick start up.
Scheme might often be used as a scripting language. A heavy to start implementation is discouraging for me personnally in that case.
- Quick processing
Means a processing speed of Gauche as Scheme interpreter. No one would expect the same speed to an interpreter as for the compiler languages. Gauche as Scheme interpreter 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.
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 makes me expect an implementation we all are dreaming of.
I will follow the Gauche evolution and the ways to use it in a different thread.
STk
STk is a Scheme implementation by Mr. Erick Gallesio, available from http://kaolin.unice.fr/STk. The latest 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 latest version is "1.4".
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 it 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 "2d2".Unzip slib2d2.zip to a convenient directory, 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 OS/2 and Windows) is needed in order to concatenate the file name to the directory path later on.% unzip slib2d2 -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 is set by config.sys with OS/2. Specify the correct drive letter for the drive where the directory resides.
set SCHEME_LIBRARY_PATH=e:/usr/local/lib/slib/
- The envrironment is set by autoexec.bat with Windows98. Specify the correct drive letter for the drive where the directory resides.
set SCHEME_LIBRARY_PATH=e:/usr/local/lib/slib/
Installing SCM
- Unzip scm5d4.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 scm5d4 -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.
Notes on compiling with FreeBSD
The double precision (flonum) mantissa with FreeBSD defaults to 53 bits (IEEE 754). To set the mantissa precision to 64 bits, a function fpsetprec() must be called when the main function begins, #including 'floatingpoint.h' to the compiled units (FreeBSD Q and A). This resets the Intel CPU register for extended 64 bits floating point arithmetic. However, this increases the overflow risk because all the internal double arithmetic is done in 64 bits since then and might induce sometimes incorrectness due to rounding of the extended predision to double precision.
Patch scmmain.c or edit it on your own risk. I myself meet no grave problem so far. The patch is already applied to the developpement version of SCM and will be available from its next release.
FP_PE is declared in 'ieeefp.h' and included when including 'floatingpoint. h'.... /* * FP precision modes */ typedef enum { FP_PS=0, /* 24 bit (single-precision) */ FP_PRS, /* reserved */ FP_PD, /* 53 bit (double-precision) */ FP_PE /* 64 bit (extended-precision) */ } fp_prec_t; ...
- Create scmlit.
make scmlit
- scmlit is prepared for executing 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.- When compiling it with OS/2-emx, the necessary header files are not included with the original 'findexec.c'. Patch or edit it. This is necessary to compile the full featured SCM, too.- Execute build script with arguments.
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.
- -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 OS/2- emx cygwin arrays Multi dimensional arrays o o o o array-for-each Array mapping o o o o bignums Multiple precision data o o o o cautious Number check of arguments o o o o compiled-closure Integration of C functions o o o o curses curses library o o o o debug Error check for debugging / / / / dump Executable image dump * * * * dynamic-linking Dld library * * * * read-line Line editor o o / / engineering-notation Engineering notation o o o o generalized-c-arguments Variable number args C functions o o o o i/o-extensions ANSI C file I/O o o o * inexact Floating point arithmetic o o o o macro r5rs macro o 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 o regex Regular expressions o o * * rev2-procedures r2rs procedures o o / / sicp (eq? () #f)==>#t, etc o o / / socket BSD sockets o o * / tick-interrupts ticks, ticks-interrupt, alarm etc. o o o o
The above specifications normally force compiling and linking to create scm executable. The one or both may fail if the specified features are not supported by the build database.build example 1(FreeBSD) ./build -h system -p freebsd -F arrays array-for-each bignums \ cautious compiled-closure generalized-c-arguments i/o-extensions \ inexact macro record
If failure occurs, try to create a script file instead of executing direct compiling and linking and edit it later:The above creates the following script file:build example 2(FreeBSD) ./build -p freebsd -F arrays array-for-each bignums \ cautious compiled-closure curses generalized-c-arguments \ i/o-extensions inexact macro posix unix record \ regex socket tick-interrupts > makescm chmod +x ./makescm
By executing ./makescm, the macro definitions are written to a file named scmflags.h and scm executable is created, displaying the following messages in present case:#!/bin/sh # unix script created by SLIB/batch # ================ Write file with C defines rm -f scmflags.h echo '#define IMPLINIT "Init5d4.scm"'>>scmflags.h echo '#define INITS init_ramap();init_gsubr();init_ioext();init_posix();init_record();init_rgx();init_sc2();init_socket();init_unix();'>>scmflags.h echo '#define ARRAYS'>>scmflags.h echo '#define BIGNUMS'>>scmflags.h echo '#define CAUTIOUS'>>scmflags.h echo '#define FLOATS'>>scmflags.h echo '#define MACRO'>>scmflags.h echo '#define CCLO'>>scmflags.h echo '#define TICKS'>>scmflags.h # ================ Compile C source files cc -O -c rope.c unif.c subr.c sys.c eval.c scl.c repl.c time.c script.c findexec.c scmmain.c scm.c continue.c unix.c socket.c sc2.c rgx.c record.c posix.c ioext.c gsubr.c ramap.c # ================ Link C object files mv -f scm scm~ cc -o scm -lc -lgnuregex -lm ramap.o gsubr.o ioext.o posix.o record.o rgx.o sc2.o socket.o unix.o continue.o scm.o scmmain.o findexec.o script.o time.o repl.o scl.o eval.o sys.o subr.o unif.o rope.o
Ignore all warnings except that for tmpnam. The above warning for tmpnam is telling that the tmpnam function was unable to be linked with the link options specified in the script file.sys.c: In function `prinport': sys.c:311: warning: passing arg 1 of `lputs' makes pointer from integer without a cast posix.c: In function `l_ttyname': posix.c:322: warning: assignment makes pointer from integer without a cast sys.o: In function `ltmpnam': sys.o(.text+0x40c): warning: tmpnam() possibly used unsafely; consider using mkstemp() /usr/libexec/elf/ld: sys.o: warning: unresolvable relocation against symbol `tmpnam' from .text section
I can't explain the reason why tmpnam was not linked because it exiists in the libc library. What I can tell is that the tmpnam function is linked and becomes available without -lc.
FreeBSD's C compiler is gcc (2.95.2 for 4.2-RELEASE) but its C library seems not from GNU.
FreeBSD strongly recommends to use mkstemp() instead of tmpfile and tmpnam (tmpfile (3)) and there might be a mechanism somewhre which prohibit to link it when the standard C library is specified. I would be grateful if someone teach me.
Anyway, full featured SCM is created by executing the following edited script file. In the following example, I changed the optimization option to the maximal O3. The SCM session prompt "SCM> " is also specified.
This is the case of Debian Linux.#!/bin/sh # unix script created by SLIB/batch # ================ Write file with C defines rm -f scmflags.h echo '#define IMPLINIT "Init5d4.scm"'>>scmflags.h echo '#define INITS init_ramap();init_gsubr();init_ioext();init_posix();init_record();init_rgx();init_sc2();init_socket();init_unix();'>>scmflags.h echo '#define ARRAYS'>>scmflags.h echo '#define BIGNUMS'>>scmflags.h echo '#define CAUTIOUS'>>scmflags.h echo '#define FLOATS'>>scmflags.h echo '#define MACRO'>>scmflags.h echo '#define CCLO'>>scmflags.h echo '#define TICKS'>>scmflags.h echo '#define PROMPT "SCM> "'>>scmflags.h # ================ Compile C source files cc -O3 -c rope.c unif.c subr.c sys.c eval.c scl.c repl.c time.c script.c findexec.c scmmain.c scm.c continue.c unix.c socket.c sc2.c rgx.c record.c posix.c ioext.c gsubr.c ramap.c # ================ Link C object files mv -f scm scm~ cc -o scm -lgnuregex -lm ramap.o gsubr.o ioext.o posix.o record.o rgx.o sc2.o socket.o unix.o continue.o scm.o scmmain.o findexec.o script.o time.o repl.o scl.o eval.o sys.o subr.o unif.o rope.o
the following script file is created.build example 3(linux) ./build -p linux -F arrays array-for-each bignums \ cautious compiled-closure curses generalized-c-arguments \ i/o-extensions inexact macro posix unix record \ regex socket tick-interrupts > makescm
The execution of the script file fails lack of libregex. Laser5 Linux 6.0 (Japanese Redhat Linux 6.0) kernel 2.2.5 did not have libregex neither, I remember. It seems the regular expression library is included in the standard library with Linux. The stript file without -lregex ends successfully, creating the SCM executable with rgx.c module successfully integrated.#!/bin/sh # unix script created by SLIB/batch # ================ Write file with C defines rm -f scmflags.h echo '#define IMPLINIT "Init5d4.scm"'>>scmflags.h echo '#define INITS init_ramap();init_gsubr();init_ioext();init_posix();init_record();init_rgx();init_sc2();init_socket();init_unix();'>>scmflags.h echo '#define ARRAYS'>>scmflags.h echo '#define BIGNUMS'>>scmflags.h echo '#define CAUTIOUS'>>scmflags.h echo '#define FLOATS'>>scmflags.h echo '#define MACRO'>>scmflags.h echo '#define CCLO'>>scmflags.h echo '#define TICKS'>>scmflags.h # ================ Compile C source files gcc -O2 -c rope.c unif.c subr.c sys.c eval.c scl.c repl.c time.c script.c findexec.c scmmain.c scm.c continue.c unix.c socket.c sc2.c rgx.c record.c posix.c ioext.c gsubr.c ramap.c # ================ Link C object files gcc -rdynamic -o scm -lc -lregex -lm ramap.o gsubr.o ioext.o posix.o record.o rgx.o sc2.o socket.o unix.o continue.o scm.o scmmain.o findexec.o script.o time.o repl.o scl.o eval.o sys.o subr.o unif.o rope.o
I used makefile to make the SCM for OS/2.build example 4(cygwin) ./build -p unix -F arrays array-for-each bignums \ cautious compiled-closure curses generalized-c-arguments \ inexact macro posix unix record tick-interrupts > makescm chmod +x makescm ; ./makescm
Of course every OS with C environments accepts the Makefile. Here are the Makefiles I made by editing the one included in SCM version 4e3:
The Makefiles are used for creation of scm and libscm.a. An empty scmflags.h is provided by hand (rm scmflags.h ; touch scmflags.h).
- 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)In my environment (Pentium Pro 200 MHz, 128 MB memory) with FreeBSD, Debian Linux, Windows 2000 and Windows 98--cygwin, every SCM thus created passed the r4rstest. But the SCM for OS/2 failed with the following messages.... errors were: (SECTION (got expected (call))) ((6 5 6) (#f #t (mult-float-print-test #f))) ((6 5 6) (#f #t (mult-float-print-test #f))) ((6 5 6) (#f #t (mult-float-print-test #f))) ((6 5 6) (#f #t (mult-float-print-test #f))) ((6 5 6) (#f #t (mult-float-print-test #f))) ...The first list of numbers shows the r4rs section (6.5.6 -- Numerical input and output corresponding to 6.2.6 of r5rs). The secction defines the procedures string->number and nmber->string. The errors are due to the inaccurracies of the floating point number I/O but do not affect the essential behaviour of Scheme. I don't think this causes any problem for the normal programming with SCM.