help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Learning LISP; Scheme vs elisp.


From: Joel J. Adamson
Subject: Re: Learning LISP; Scheme vs elisp.
Date: Fri, 01 Aug 2008 15:16:46 -0400

>>>>> "Adam" == Adam Funk <a24061@ducksburg.com> writes:

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

    Good idea: the best computer science book ever written --- and the only
    one I've ever used :-P

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

    Uh, what?  Can you explain this?  Can you explain why on Earth you
    would do it?

    Adam> Any tips on transferring knowledge between Scheme and elisp?

    There are some general qualities to Lisp that all Lisp dialects
    share, Scheme and Emacs Lisp among them.  Both are descendants of
    MacLisp (though Scheme is way different from MacLisp, and Emacs Lisp
    is quite similar).

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

    Scheme has a single namespace for variables and functions, whereas
    other Lisps have one for functions, one for special variables, on
    and on.  That's why there's defun, defvar, defmacro, defkitten; this
    is how you can pass a function as a variable without specially
    tagging it in Scheme:

    Scheme:

,----
| Gambit v4.2.8
| 
| > (define lis '(1 2 3 4))
|   (apply + lis)
| > 10
`----

    Emacs:
    
,----
| ELISP> (apply + '(1 2 3 4))
| *** Eval error ***  Symbol's value as variable is void: +
| ELISP> (apply '+ '(1 2 3 4))
| 10  
`----

    Common Lisp:
    
,----
| [5]>     (defvar lis '(1 2 3 4))
| LIS
| [6]> lis
| (1 2 3 4)
| [7]> (apply #'+ lis)
| 10
| [8]> (apply + lis)
| 
| *** - APPLY: (APPLY #'+ LIS) is not a function name; try using a symbol 
instead
| The following restarts are available:
| USE-VALUE      :R1      You may input a value to be used instead.
| ABORT          :R2      ABORT
| Break 1 [9]> 
`----

Read those errors carefully and they'll make sense given what I said
above about namespaces.

The real correspondent of setq in Scheme is set! --- destructive
procedures end in exclamation points.   It's up to a particular
implementor of Scheme as to whether set! on an undefined
variable is an error (correct me if I'm wrong about the standard, but
I've had some implementations where you can set! an un'define'd
variable, and others where you can't).

I suggest you use Emacs for Scheme hacking, and that way you will learn
the ins and outs of both.  If you'd like to see an application that I
developed in Emacs using Scheme (and that I'd like to add an Emacs mode
for interacting), check out http://www.unc.edu/~adamsonj/software.html
and scroll down to Intelligent WTF.  The source code is also there for
browsing.

Joel




-- 
Joel J. Adamson
(303) 880-3109
Public key: http://pgp.mit.edu
http://www.unc.edu/~adamsonj
http://trashbird1240.blogspot.com




reply via email to

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