Scsh (a Unix Scheme shell) FAQ

Scsh (a Unix Scheme shell) FAQ

Post by Michel Schi » Sun, 14 Jul 1996 04:00:00

Posted-By: auto-faq 3.3 beta (Perl 5.002)
Archive-name: unix-faq/shell/scsh
Posting-Frequency: monthly

Frequently Asked Questions

   This is the scsh Frequently Asked Questions list, version 1.03, 17
June 1996.

   This article is provided as is without any express or implied
warranties.  While every effort has been taken to ensure the accuracy of
the information contained in this article, the maintainer assumes no
responsibility for errors or omissions, or for damages resulting from
the use of the information contained herein.


   This section contains questions and answers about this FAQ, its
author(s), etc.

What is the aim of this FAQ?

   The aim of this FAQ is to provide some help and documentation to
people interested in scsh, a Unix shell that uses Scheme as its
scripting language.  It is mainly aimed towards those who do not know
much about scsh or Scheme.  This explains why some questions that might
seem trivial to the seasoned Scheme programmer are included anyway.

What was changed recently in this FAQ?

   Here is a list of recent changes. The name of the person who
suggested the change (either explicitly by sending a mail, or
implicitly by posting a news) is mentioned in parentheses.

  1. 1996/01/25 v0.1.1 Section about licensing terms added (Paul Wilson)

  2. 1996/01/29 v0.1.2 Many many changes (Brian Carlstrom and Olin

  3. 1996/01/30 v0.1.3 Some text about 9term and wily added (Gary

  4. 1996/01/31 v0.1.4 Minor syntactic changes (Pierre De Pascale)

  5. 1996/01/31 v0.1.5 More information about how to contribute code
     (Olin Shivers)

  6. 1996/02/05 v0.1.6 Section about memory problems added (Brian

  7. 1996/02/22 v0.1.7 RFV for comp.lang.scheme.scsh included

  8. 1996/02/26 v0.1.8 Expiration date of RFV added.

  9. 1996/03/05 v0.1.9 Newsgroup section updated for the new

 10. 1996/04/15 v0.1.10 Paragraph about Shriram Krishnamurthi's notes
     added (Shriram Krishnamurthi)

 11. 1996/04/16 v0.1.11 Section about 64-bit ports updated, and
     reference to Scott Draves' markup system added (Olin Shivers)

 12. 1996/05/06 v0.1.12 Section about networking code bug with Solaris
     and Irix added (Glenn Barry)

 13. 1996/06/03 v1.0 Section about the incompatibilities between scsh
     and R4RS added; section about the module system added; some
     revamping; version bumped to 1.0 to celebrate our entry in the
     *.answers groups.

 14. 1996/06/06 v1.01 Some more revamping.

 15. 1996/06/14 v1.02 URL for Olin's home-page updated (Olin Shivers).

 16. 1996/06/17 v1.03 Small syntax error corrected (Geoffrey S. Knauth).

Where do I get the latest version of this FAQ?

   The latest version of the FAQ can be found at the "scsh FAQ

   This home-page contains three versions of this FAQ: an ASCII
version, an HTML version and an Info version.  If you have access to
the Web, I strongly recommend that you get the HTML version, since all
the hyperlinks can be followed just by clicking on them.

   Please notice that this home-page's location may change in the (near)

   Apart from that, this document is posted on the 13th of each month in
the newsgroups `comp.lang.scheme.scsh', `comp.lang.scheme',
`', `comp.answers' and `news.answers'.

Where do I send comments about this FAQ?

   Comments about this FAQ should be sent to the following address:
<>.  Please include the words `scsh FAQ' in the
subject to help me sort your mail.

   Please help me producing a useful document by sending me suggestions
and material for this FAQ.  What I would especially like is finding
someone with a good knowledge of English who could fix all the typos and
grammatical errors that certainly lie in this document (English is not
my mother tongue, as you have guessed).


   This section contains general questions about scsh: what is it,
where to find it, etc.

What is scsh?

   Scsh is a Scheme shell. That is, a Unix shell which uses Scheme as
its scripting language.  It was designed and written by Olin Shivers and
Brian Carlstrom, and is built on top of Scheme 48, an implementation of
Scheme written by Jonathan Rees and Richard Kelsey.

   Scsh currently includes the following features:

   - An almost complete Posix interface (only signals are missing).

   - A very complete support for networking, with high and low level
     interfaces.  An additional network package, including an HTTP
     server, SMTP support, etc. is also available separately.

   - Powerful string manipulation functions: pattern matching, file-name
     manipulations, etc.

   - AWK-like macros.

   However, it is currently aimed primarily at scripting use, rather
than interactive use (*Note Interactive scsh::).

How do you pronounce scsh?

   According to Olin, scsh is pronounced "skishhhh" (it rhymes with

What is the current version of scsh?

   The current version is 0.4.2.

What are the licensing terms for scsh?

   Scsh is *not* distributed according to the GPL (General Public
License) or some other well known license.  Here are the exact terms,
which can be found in the file `COPYING':

     Copyright (C) 1993, 1994 by Richard Kelsey and Jonathan Rees.
     Copyright (C) 1994, 1995 by Olin Shivers and Brian D. Carlstrom.

     Use of this program for non-commercial purposes is permitted
     provided that such use is acknowledged both in the software itself
     and in accompanying documentation.

     Use of this program for commercial purposes is also permitted, but
     only if, in addition to the acknowledgment required for
     non-commercial users, written notification of such use is provided
     by the commercial user to the authors prior to the fabrication and
     distribution of the resulting software.

     This software is provided "as is" without express or implied

What is Scheme?

   Scheme is a small and elegant programming language of the Lisp
family, originally designed by Guy Lewis Steele Jr. and Gerald Jay
Sussman.  It includes powerful features like first-class procedures and
continuations, and is statically scoped (like Pascal).  For more
information, refer to the Scheme FAQ (*Note Getting the docs::).

What is Scheme 48?

   Scheme 48 is a small and portable Scheme implementation written by
Jonathan Rees and Richard Kelsey.  It is based on a virtual machine
architecture (i.e. it does not compile to native code).

   Scheme 48 implements all the features described in R4RS (*Note
Getting the docs::) as well as new features from the forthcoming R5RS,
and some extensions like exceptions and a module system.

How does scsh compare to other scripting languages, like Perl?

   It is always hard to compare programming languages objectively.
However, here are the main differences between scsh and its "rivals"
(both positive and negative differences are included):

   - Scsh is based on a well-designed and general programming language
     (Scheme) that has been developed over many years. Thus, scsh is a
     general programming tool, not a quickly hacked tool with limited

     Among other things, Scheme (and thus scsh) has serious data
     structures, not just strings like many scripting languages.  It
     also has powerful control structures like continuations and, in
     the case of Scheme 48, exceptions.

   - The interface to Unix functions has been well designed: the names
     are consistent, and their behavior is "Scheme-like".  For example,
     system calls do not use the `errno' global variables to signal
     errors, but raise exceptions instead.

     This approach is fundamentally different from, say, the Perl
     approach, where functions have the same name (often cryptic) and
     behavior (often strange) than their Unix equivalents.

   - Scsh is somewhat slow, especially on startup. This should be fixed
     in future versions, however.

Where can I get scsh?

   The latest version of scsh should be available at the following

   The official scsh home-page is located at:

Where can I find documentation about scsh?

   The main documentation about scsh is the scsh manual.  It is
included in the distribution: the ready-to-print PostScript is in
`doc/' and the LaTeX source in `doc/scsh-manual'.
Moreover, a copy of the PostScript file is available at:

   You may also want to take a look at the technical report describing
the design of scsh.  It is also included in the distribution
(`doc/'), and a copy can be found at:

   Shriram Krishnamurthi <> also wrote some notes
about using scsh, and especially the HTTP server that may be worth
reading.  These notes can be found at:

   The documentation about Scheme 48 is also worth reading.  The user's
guide is in the file `doc/user-guide.txt' and the documentation for the
module system in `doc/'.

   Also, since scsh is written on top of a Scheme system, you have
access to the great power of Scheme.  However, no Scheme documentation
is available with scsh, so you may wish to obtain the standard Scheme
references as well.  Here are some useful pointers:

   - The Scheme FAQ is maintained by Mark Kantrowitz and Barry Margolin
     and is available at:
     It is also posted regularly in the newsgroups `comp.lang.scheme',
     `comp.answers' and `news.answers'.

   - The Scheme home-page is located at:

   - The official specification for Scheme is "The Revised^4 Report on
     the Algorithmic Language Scheme", often abbreviated R4RS. This is
     the document you should use to look up details about Scheme. The
     PostScript version is available at:
     Aubrey Jaffer produced an HTML version of this document, available

   - An article describing the extensions to be included in the future
     report on Scheme (R5RS) is available in `doc/'. This
     article describes, among other things, multiple return values,
     which are used by some of scsh's functions.

   - There are many good books about Scheme, for example: "Structure and
     Interpretation of Computer Programs" by Harold Abelson and Gerald
     Jay Sussman, MIT Press, 1985 or "Scheme and the Art of
     Programming" by George Springer and Daniel P. Friedman, MIT Press,
     1989.  For more references, see the Scheme FAQ.

   - The Scheme 48 home-page is located at
     It contains useful information about Scheme 48, including papers
     describing its implementation.

   The home-pages of the various people involved in the design of
Scheme, Scheme 48 or scsh may also be of interest to you.  Here are
some links:

   - Gerald Jay Sussman:

   - Jonathan A. Rees:

   - Richard Kelsey:

   - Olin Shivers:

   - Brian D. Carlstrom:

Is there some kind of reference card for scsh?

   Not exactly. There is a small list of all of scsh's functions in the
file `doc/cheat.txt'.  However, it would be great to have a nice
TeXified reference card, which would include R4RS functions as well
(you know, something like the great Perl reference card).  If I can find
some time, I'll do it, but if *you* have some time, just go ahead and
type it.  I'm sure it would be useful to a lot of people.

Which newsgroups and mailing-lists are related to scsh?

   Currently, there is a mailing-list and a newsgroup which are
completely equivalent.

   The newsgroup used to be `alt.lang.scheme.scsh', but this has now
been replaced by `comp.lang.scheme.scsh'.  Please don't use the old alt
group, even if it still exists at your site.

   To (un)subscribe to the mailing-list, send a message to
<>. To submit a messages to the
mailing-list, send it to <>.

   Also, `comp.lang.scheme', which talks about Scheme in general, may
be of interest to you.

   And if Scheme is your first functional language, you might also want
to read `comp.lang.functional'.

Does scsh run on my system?

   Currently, scsh runs without modification on the following systems:
DEC Ultrix, Harris CXUX, HP-UX, IBM AIX, Linux, FreeBSD, NetBSD,
NeXTSTEP, SGI IRIX, Solaris, and SunOS.  It should also run without too
many changes on other 32 bits UNIX platforms.

Is scsh easy to port?

   On 32 bits machines, yes, usually.  If your system isn't already
supported, take a look at the file `doc/install.txt' which contains
porting instructions.

   Porting scsh to 64 bits machines (or, more generally, non-32 bits
machines) is currently harder. The main reason is that this requires
modifications to the Scheme 48 virtual machine (VM). This VM is written
in PreScheme, a dialect of Scheme, and the PreScheme compiler isn't
widely available: you should ask it directly to Richard Kelsey
<>.  In any case, never try to hack the C code
generated by the PreScheme compiler (file `scheme48vm.c'), this is ugly
and you'll have to restart from scratch for the next release of Scheme

   However, you should notice that the next public release of Scheme 48
should be more 64-bits-friendly.

   Apart from the problems with the Scheme 48 VM, there are also some
problems with scsh: the current version contains C code that assumes
32-bitness. This occurs mainly in the foreign-function interfaces (that
is, interface between Scheme and C), where integers are converted
between their Scheme and C representation.

Can I run scsh under some other Scheme implementation?

   Currently, scsh is tightly bound to Scheme 48 because it uses two
non-standard features of Scheme 48: its module system and its foreign
function interface. This does not mean that porting it to another Scheme
implementation is impossible, but it is certainly hard.

Installing and using scsh

   Now that you have downloaded scsh, you might want to install and use
it.  Some help about this subject is provided here.

It looks like I do not have enough memory to compile scsh?!?

   If you get errors like "not enough memory" when building scsh, you
may try to adjust the limits on memory usage imposed by your system. To
do this, you have to use the `ulimit' command under `sh' and
derivatives or the `unlimit' command under `csh' and derivatives
(`tcsh' and the like).  See the reference page of your shell for more

Is there some kind of "contributed code archive" for scsh?

   The following two sites may be of interest to you:

  1. The contributed code directory for scsh, which is located at
     Currently, this directory contains only Olin's networking code and
     Scott Draves and Jonathan Rees' markup stuff.  So please go on,
     and send more code.

  2. The various Scheme code repositories, which are all listed in the
     Scheme FAQ. The two main repositories are the Scheme Repository at
     Indiana University:
     and the CMU AI Repository, Scheme Section:

   Also, some useful code is included with Scheme 48 (hash tables
support, sorting functions, etc.) in the Big Scheme module.  Please
notice that you will have to open the module before being able to
access its functions.  For additional information, check the file
`doc/big-scheme.txt' in the scsh distribution.

   On the other hand, if you want to contribute some code, you should
send it directly to Olin Shivers <>.  You can send an
URL or an uuencoded tar file.

   If you want to write some code for scsh but you don't know what, you
might consider writing an ILU interface for scsh.  ILU (Inter-Language
Unification system) is a multi-language object interface system which
enables you to use code written in other languages with an ILU interface
(currently Common Lisp, C++, ANSI-C, Modula-3 and Python).  It can also
be used to write distributed systems, by calling remote procedures (like
RPC).  For more information, check out ILU's home page at:

Can I use "plain" Scheme code with scsh?

   Generally speaking, all the existing Scheme code can be run without
problem with scsh.  There is only *one* possibly annoying
incompatibility between R4RS-compliant interpreters and scsh: Symbols in
scsh are case-sensitive while this is not true for R4RS-compliant
interpreters.  This means for example that the following expression:

     (eq? 'symbol 'Symbol)

evaluates to `#t' with an R4RS-compliant interpreter (including the
original Scheme 48), while it evaluates to `#f' with scsh.

   In practice this shouldn't be a big problem, but if you encounter
code that works perfectly with all Scheme interpreters except scsh, then
this may be the reason.

   If you want to know the design decision behind this choice, you
should read the technical report describing the design of scsh (*Note
Getting the docs::).

   There are also other extensions to R4RS in scsh (e.g. C-like escaped
characters in strings) but they shouldn't break existing Scheme code;
you should have them in mind, however, when trying to write portable
Scheme code under scsh.

Can I use scsh as an interactive shell?

   Well, technically you can: just run the "scsh" command and you will
enter a Scheme 48 session with all scsh functions available.  However,
this is definitely not suitable for interactive work: there is no
command-line editing, no command-line history, no file/function name
completion, no terse syntax, etc.  All these features are planned, and
Olin has a design for much of them.  However, nobody found the time to
implement them yet.

   In the meantime, a nice solution is to use a separate tool which
provides some of these features.  Here is a partial list of such tools:

  1. Emacs: use the `cmuscheme' package, written by Olin.  It is now
     part of Emacs, but if you don't have it on your system, you may
     use the one provided with scsh, which is also a little more
     up-to-date (check the directory `emacs'). This mode enables you to
     run scsh (or any Scheme interpreter by the way) as an inferior
     process.  It provides command-line editing, command-line history,
     dynamic completion, file-name completion, automatic indentation of
     Scheme code and more.

     If you want to give it a try right now, just type `C-u M-x
     run-scheme', and then enter `scsh' at the prompt.

  2. Some terminal emulator that enables input (or output) editing.  An
     example is the 9term terminal emulator, inspired by the Plan 9
     terminal emulator.  Check out 9term's home-page at:

  3. Any text editor that can run a process in one of its windows.  An
     example is wily (although it is more than a text editor), inspired
     by Plan 9's ACME tool.  For more information:

I get "undefined variable" errors when I try to use some functions?!?

   If you get "undefined variable" errors when you use functions from
the big-scheme package or macros like `define-record', then maybe you
didn't open the appropriate packages.  To open them, there are two

  1. use the `,open' command in interactive mode, or

  2. use Scheme 48's module system.

   The first solution is nice for interactive work, while the second is
the one to use for scripts.

   The documentation on Scheme 48 module system can be found in the file

Some basic IO functions (like EOF testing) seem not available in scsh?!?

   Don't forget that scsh is built on top of Scheme. Therefore, you have
access to the full power of Scheme in scsh, and that includes some basic
IO functions, like the test for EOF, etc.  However, these functions are
not documented in the scsh manual, but in the official Scheme
specification (R4RS, *Note Getting the docs::).

How can I return the eof-object?

   Some functions and macros (like the nice AWK macro) take a reader
function as an argument. This reader function is required to return the
eof-object at the end of the input. This is easy when the input is a
port, but much harder when the input is something else (like a list of
lines, etc.). The reason is that R4RS specifies that the eof-object
can't be read by the `read' procedure, and therefore can't be included
literally in your source.  However, it can be defined like that:

     (define eof-object (read (make-string-input-port "")))

Is there support for protocols like HTTP, SMTP, etc.?

   Yes, but it isn't included in the scsh distribution.  You will find
it in the contributed code directory for scsh:

I get strange errors with some network functions?!?

   If you are using scsh 0.4.2 under Solaris 2 or Irix 5, and the errors
you get look like:

     Error: 122
            "Operation not supported on transport endpoint"
            #{Procedure 9398 %listen}

then don't worry, this is a known and easy-to-fix bug.  Here is what you
have to do:

   In scsh's distribution directory, edit the file
`scsh/solaris/netconst.scm' (if you are under Solaris 2 and above) or
`scsh/irix/netconst.scm' (if you are under Irix 5 and above) so that
the following lines:

     (define socket-type/stream 1)              ; stream socket
     (define socket-type/datagram 2)            ; datagram socket
     (define socket-type/raw 3)         ; raw-protocol interface
     ;;(define socket-type/rdm 4)               ; reliably-delivered message
     ;;(define socket-type/seqpacket 5)      ; sequenced packet stream

are replaced by the following lines:

     (define socket-type/stream 2)              ; stream socket
     (define socket-type/datagram 1)            ; datagram socket
     (define socket-type/raw 4)         ; raw-protocol interface
     ;;(define socket-type/rdm 5)               ; reliably-delivered message
     ;;(define socket-type/seqpacket 6)      ; sequenced packet stream

then recompile scsh, by running make in the main directory, and
reinstall it.

How do I get the multiple values returned by a function?

   This is documented in the file `doc/' (this is *not*
documented in the R4RS).  However, with all these continuations, the
documentation might be a little hard to understand for newcomers.  So
here is a little (although not very useful) example that uses `values'
and `call-with-values':

     (call-with-values (lambda () (values 6 7)) *)
       => 42

   As you can see, the first argument to `call-with-values' is a
procedure which return multiple values, and the second is a procedure
which gets these multiple values as arguments.

   Scheme 48 provides another syntax to access multiple values: the
`receive' macro. This macro binds multiple values returned by an
expression to variables, and then evaluates a sequence of expressions
with these bindings active (for Common Lisp fans, this is similar to
`multiple-value-bind').  Here is the above example, rewritten using

     (receive (x y) (values 6 7) (* x y))
       => 42

   For more information on this function, check out

   While this may not be evident here, the `receive' macro is often
easier to use than `call-with-values'.

How do I interface scsh with a C function?

   You should use the `cig' program, written by Olin Shivers.  It is a
nice C interface generator. The program and its documentation are
included in the `cig' directory.

   If you need examples on how to use `cig', just check out the scsh