[Top][All Lists]

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

Re: Learning LISP; Scheme vs elisp.

From: Pascal J. Bourguignon
Subject: Re: Learning LISP; Scheme vs elisp.
Date: Fri, 01 Aug 2008 23:51:01 +0200
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/22.2 (gnu/linux)

Adam Funk <address@hidden> writes:

> I've decided I ought to train myself in the most elegant programming
> weapon --- --- so I've started working through
> _The Structure and Interpretation of Computer Programs_.

Notice that this is not a book about scheme, but about programming in
general.  It just happens that it uses scheme for its examples (but
there are blogs and wikis with the sicp examples translated in other
programming languages).

To learn scheme there are easier books such as:

         How to Design Programs -- An Introduction to Computing and Programming  

         Concrete Abstractions -- An Introduction to Computer Science Using 

And of course, the reference:
and documentation of the implementation, eg.
A new version of scheme just came out, R6RS
so be sure to use the version of the report implemented by your scheme.

Nonetheless, SICP is a very good book that you should read anyways,
but it will teach you more general and very important concepts, beyond
the specific knowledge of scheme details.

> In the long term I hope I'll be able to customize Emacs more in its
> native way instead of wrapping external Perl programs in
> shell-command-on-region (as I often do now).


> Any tips on transferring knowledge between Scheme and elisp?

Emacs lisp is closer to Common Lisp than scheme.  The main separation
line being this lisp-1 vs. lisp-2 affair.  But emacs lisp is also
different enough from Common Lisp (the main difference being that all
emacs lisp variables are special, while all scheme variables are
lexical; in Common Lisp, there are both lexical and special

The fundamental lisp "primitives" will be about the same in all lisp
languages.  You will have (eql (car (cons x y)) x) in all lisp, well
(eqv? (car (cons x y)) x) in scheme.  But details may be different
enough that it might be difficult to write code running with the same
semantics or at all on both three.

For example:

(let ((a 1) (b 2) (c -1))
  (do ((x 0 (+ 1 x)))
      ((> x 10))
   (print (+ c (* b (+ x (* a x)))))))

will do about the same thing in emacs lisp and Common Lisp. For
scheme, you will have to (define (print x) (newline) (display x)), but
scheme will return #t, while Common Lisp returns NIL (and emacs lisp
nil, since in emacs lisp the symbols are in lowcase by default
contrarily to Common Lisp).

Once you know well one of them, including their macro system, you will
be able to write "portability"  function like the above print
function.  In emacs lisp, there is the cl library (require 'cl) which
exports some functions and macros found in Common Lisp and not in
emacs lisp. 

Also, there are implementations of one in the other. For example:
emacs-cl implements Common Lisp over emacs lisp.
Pseudo   implements scheme r4rs over Common Lisp.

( Someone could have good fun trying to make Pseudo run over emacs-cl
over emacs lisp, to have a scheme in emacs ;-) )

But the main thing, with respect to emacs lisp is that if you want to
learn it for emacs editing, then you will have to learn all the emacs
"library" functions. Things about buffers, markers, files, windows,
characters, inserting, deleting, replacing, regular expressions, etc,
not mentionning all the emacs lisp libraries and applications.  This
is an amount of knowledge orders of magnitude superior to the mere
knowledge of the programming language.  (Don't be afraid, happily you
don't have to learn it all at once, you can learn it piece by piece
when you need it).

You could learn emacs lisp from the emacs-lisp-intro tutorial, and
translate the sicp examples in emacs lisp. It's already been done for
Common Lisp, but not for emacs lisp.

Finally, I should mention that you could skip emacs lisp altogether,
learn Common Lisp, and use an emacs implemented in Common Lisp, such
as Hemlock, or the more recent Climacs (but they don't benefit (yet)
the same amount of contributions as emacs).

> As a first observation, it seems to me that Scheme's define seems to
> correspond to both defun and setq in elisp --- is that a fair
> interpretation (or a stupid one)?

As a first approximation, you're right.

For more information see:

__Pascal Bourguignon__           
Until real software engineering is developed, the next best practice
is to develop with a dynamic system that has extreme late binding in
all aspects. The first system to really do this in an important way
is Lisp. -- Alan Kay

reply via email to

[Prev in Thread] Current Thread [Next in Thread]