| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Now that you have downloaded scsh, you might want to install and use it. Some help about this subject is provided here.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Scsh should compile without problems on most Unix platforms. Particular notes:
--host=powerpc-apple-bsd in the
configure commandline.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Installing scsh on FreeBSD is best done by compiling FreeBSD's scsh
"port" (meaning the FreeBSD term of a port, which is an integrated
third-party package) or by getting a binary "package" from a FreeBSD
ftp server. The FreeBSD port is available under
ports/lang/scsh.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 manual of your
shell for more information.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The following resources may be of interest to you:
Go on and send more code.
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.
If you want to write some code for scsh but you don't know what, you might want to take a look at the scsh home-page (see section 3.8 Where can I get scsh?) which contains a list of interesting projects.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Generally speaking, all of the existing Scheme code can be run without problem with scsh. There is only one possibly annoying incompatibility between R5RS-compliant interpreters and scsh: Symbols in scsh are case-sensitive while this is not true for R5RS-compliant interpreters. This means, for example, that the following expression:
(eq? 'symbol 'Symbol) |
evaluates to #t with an R5RS-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 (see section 3.9 Where can I find documentation about scsh?).
There are also other extensions to R5RS 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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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.
To alleviate these problems, Martin Gasbichler and Eric Knauel have
written Commander S, which runs on top of scsh and provides a
comfortable interactive environment. One of its novel features is that
it can understand the output of many Unix commands, and allows the user
to browse and manipulate it in useful ways. More information about
Commander S can be found in the paper describing it:
http://www-pu.informatik.uni-tuebingen.de/users/knauel/commander-s.pdf
Instructions about how to obtain and install Commander S are available
from the scsh Web site:
http://www.scsh.net/resources/commander-s.html
Another option to obtain interactive features for scsh is to run it inside a tool providing them. A partial list of such tools includes:
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.
rlwrap -c -b '(){}[].,=&^%$#@\;|' scsh
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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
solutions:
,open command in interactive mode, or
The first solution is nice for interactive work, while the second is the one to use for scripts.
Documentation on the Scheme 48 module system can be found in the Scheme 48 documentation. Olin Shivers also posted a message with further explanations to the scsh newsgroup, which is archived at http://groups.google.com/groups?selm=qijyawastzo.fsf%40lambda.ai.mit.edu.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Yes, provided that you get (or write) an initialization file for scsh.
Tomas By wrote one that you can get there:
ftp://ftp.dcs.shef.ac.uk/home/tomas/scsh.init
By the way, more information about SLIB is available by following this
URL:
http://www-swiss.ai.mit.edu/~jaffer/SLIB.html
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 I/O functions, like the test for EOF, etc. However, these functions are not documented in the scsh manual, but in the official Scheme specification (R5RS, see section 3.9 Where can I find documentation about scsh?).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 R5RS 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 ""))) |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Yes, but it isn't included in the scsh distribution. You will find it in
the contributed code directory for scsh:
ftp://ftp.scsh.net/pub/scsh/contrib/
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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 you should switch to a newer version of scsh: this was a known bug of scsh 0.4.2.
If, for some reason, you want to stick with v0.4.2, here is how to fix the bug:
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This is documented in the R5RS. 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:
(receive (x y) (values 6 7) (* x y)) => 42 |
For more information on this function, check out `doc/big-scheme.txt'.
While this may not be evident here, the receive macro is often
easier to use than call-with-values.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Use the Scheme 48 facility to interface with C, documented in the Scheme 48 manual.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Scsh 0.5.2 introduced support for SREs, or Structural Regular Expressions. These provide an s-expression notation for building up and operating on regular expressions. See the SRE section of the manual for further details.
Standard string-based regexps are also available (and in fact SREs compile to string-based regexps). Henry Spencer's POSIX regular expression engine is used to implement the matching. The syntax accepted by this engine is described in its man page, which can be found in the scsh distribution, in file `scsh/regexp/regex.7'.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Scsh raises exceptions instead of passing error status codes via the
errno variable (this makes error handling much simpler). You can
use the with-errno-handler form to handle these errors
gracefully.
Certain error conditions are signalled by calls to the error
primitive. If you wish to intercept these conditions gracefully you can
write your own handler. The following example shows how to intercept the
host-not-found condition on DNS lookup.
#!/usr/local/bin/scsh \
-dm -m whnf -e main -s
!#
(define-structure whnf
(export main)
(open scheme scsh handle)
(begin
(define (with-host-not-found* thunk)
(call-with-current-continuation
(lambda (k)
(with-handler
(lambda (condition next)
(cond ((string-match "^name->host-info" (cadr condition))
(display "No such host")
(newline)
(k '()))
(else (next))))
thunk))))
(define-syntax with-host-not-found
(syntax-rules ()
((with-host-not-found ?body ...)
(with-host-not-found* (lambda () ?body ...)))))
(define (main args)
(with-host-not-found
(host-info "foo.bar.com")))))
|
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |