Re: Learning to program sawfish

Rafal Kolanski <rafalk cse unsw edu au> writes:
> Unfortunately, I know very little lisp. If I were to look at a lisp
> tutorial, which lisp is rep closest to?

These days, I'd say Scheme.  Scheme is a good dialect to start with
anyway, being simple and elegant.  Rep started out as somewhat similar
to Elisp but has been moving towards Scheme.  Elisp is closer to
Common Lisp.

The classic Scheme book is Structure and Interpretation of Computer
Programs by Abelson, Sussman and Sussman, but it is really a book
about programming in general that just uses Scheme for presentation
<URL:>.  A good reference work is the
Revised^5 Report on the Algorithmic Language Scheme, a comprehensive
description of the entire language in only 50 pages
<URL:>.  There is
also the more recent R6RS but it is much longer and you probably do
not care about its new features at this point.

> As I'm also learning a little bit of emacs hacking ... what are the
> main differences between rep and elisp?

Emacs Lisp uses (defun name (args) body) for function definitions,
similar to Common Lisp.  Rep also started out with defun but support
for the Scheme syntax (define (name args) body) was added later.
Newer code generally uses define but support for defun has been
retained for compatibility.  define can be nested like in Scheme (with
similar restrictions).

In Elisp symbols have separate function and variable bindings, like in
Common Lisp.  In Rep and Scheme they do not.  You may come across
the terms Lisp-2 and Lisp-1 that refer to this distinction: Elisp is a
Lisp-2 and Rep a Lisp-1.

Elisp uses dynamic scoping exclusively.  Rep normally uses lexical
scoping but defvar can be used to declare special variables that are
dynamically scoped.  Consider the following:
	(setq foo 'outer)
        (defun bar () foo)
        (let ((foo 'inner)) (bar))
In Elisp the let returns inner whereas in Rep it returns outer.  If
you change the setq to defvar, both dialects return inner.

In Elisp and Common Lisp the symbol nil is the empty list and
evaluates to itself.  The reader converts () to nil.  In Rep the empty
list is a special object denoted by () and nil is just an ordinary
symbol bound to the empty list.  Thus (eq nil 'nil) is true in Elisp
and false in Rep, ditto for (eq '() 'nil).  (eq '() nil) is true in
both dialects.  Note that in Rep the empty list evaluates to itself
but in Scheme it is an error to evaluate it.  The symbol nil is
undefined in Scheme.

In Rep, Elisp and Common Lisp the empty list is the only value
considered false in a Boolean context.  Anything else is considred
true.  Predicates (functions returning Boolean values) generally
return the symbol t for true.  Scheme on the other hand has special
Boolean values denoted by #t and #f.  Only #f is considered false in
Boolean context: all other values including the empty list are
considered true.

Rep does not follow the Scheme convention of suffixing predicates with
"?" and destructive modifications with "!".  Predicates are sometimes
suffixed with "p" and sometimes not, like in Elisp and Common Lisp.

	Timo Korvola		<URL:>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]