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

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

Re: How to learn elisp ?


From: Pascal J. Bourguignon
Subject: Re: How to learn elisp ?
Date: Wed, 05 Aug 2009 17:34:45 +0200
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.2 (gnu/linux)

"Drew Adams" <drew.adams@oracle.com> writes:

>       I am not a programmer. 
>       I have used emacs for a period of time .
>       I have read `A Introduction to emacs lisp' and Orelly's Learn Gnu Emacs
>   3ed .
>       
>       Now I am reading `Emacs Lisp Reference' , I feel it is harder and my
>   progress is slow.
>       How to learn elisp ? Because I need to write or modify some functions.
>       Do I need to read Emacs Lisp Reference wholely ? 

Yes, but not yet.
        
Since you are not (yet) a programmer, you will need to learn
programming, to become one.  Study these books, one after the other:

    Common Lisp: A Gentle Introduction to Symbolic Computation
    David S. Touretzky
    http://www-cgi.cs.cmu.edu/afs/cs.cmu.edu/user/dst/www/LispBook/index.html
    http://www.cs.cmu.edu/~dst/LispBook/


    Structure and Interpretation of Computer Programs
    Harold Abelson & Gerald Jay Sussman, with Julie Sussman
    http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html
    http://swiss.csail.mit.edu/classes/6.001/abelson-sussman-lectures/


The first gives you an easy introduction to programming.
The seconds gives you good fundamentals to programming.

The only drawback is that they don't use emacs lisp for their
examples.   The first uses Common Lisp, which is quite close to emacs
lisp.  There are significant technical differences, so you will
probably learn some Common Lisp along, but it will also make you
understand better emacs lisp, and teach you how to program in lisp.

For example, to insert X times a line in a buffer in emacs lisp you would write:

      (defun happy (n)
        (dotimes (i n)
           (insert (format "Happy %d%s birthday!\n" 
                            i (case i
                                 (0 "th")
                                 (1 "st")
                                 (2 "nd")
                                 (3 "rd")
                                 (otherwise "th"))))))


In Common Lisp you would write:

      (defun happy (n)
        (dotimes (i n)
           (format t "Happy ~d~:*~[th~;st~;nd~;rd~:;th~] birthday!~%" i)))

or you could write it more like in emacs lisp:

      (defun insert (&rest args) ; there's no buffer, therefore no insert in 
Common Lisp.
         (dolist (arg args) (princ arg))) ; we will just princ the arguments to 
the output.

      (defun happy (n)
        (dotimes (i n)
           (insert (format nil "Happy ~d~a birthday!~%" 
                            i (case i
                                 (0 "th")
                                 (1 "st")
                                 (2 "nd")
                                 (3 "rd")
                                 (otherwise "th"))))))

You will have to be aware of the differences, but there is a big core
of common principles and operators, so you can easily write code that
work the same, or quite similarly, in either lisp.  Learning how to
program with a Common Lisp book will help you to program in emacs
lisp, it's basically the same ability.

If you put (require 'cl) in your ~/.emacs, you will load a set of
functions and macros like thoses found in Common Lisp.

If you install eieio (from cedet.sourceforge.net), and (require
'eieio) in your ~/.emacs, you will even get a clone of CLOS (the
Common Lisp Object System), if you want to do OO programming in emacs
lisp.

    The most notable difference between emacs lisp and Common Lisp
    are that all variable bindings in emacs lisp are dynamic, while
    Common Lisp uses lexical binding by default, and optionnally (eg
    for global variables), uses dynamic binding.  In Scheme, there is
    only lexical bindings.  As a consequence, there is no closure in
    emacs lisp (but (require 'cl) provides a simulated lexical binding
    operator (lexical-let) which allow you to create kind of
    closures).





For SICP, this book uses scheme, another kind of lisp, for its
examples.  But its teaching goes way beyond the specific programming
language, and it is really worth studying if you want to make good
programs.  (Note that these exercises have been translated in several
programming languages, including Common Lisp
http://www.codepoetics.com/wiki/index.php?title=Topics:SICP_in_other_languages
)


> http://www.emacswiki.org/emacs/LearnEmacsLisp 

You can also get help from:

news:gnu.emacs.help
irc://irc.freenode.org/#emacs
    for emacs specific questions,

http://cliki.net/
news:comp.lang.lisp
irc://irc.freenode.org/#lisp
    for Common Lisp specific questions, or general lisp questions (including 
gentle or sicp).

http://www.scheme.org/
news:comp.lang.scheme
irc://irc.freenode.org/#scheme
    for scheme specific questions (including sicp).

-- 
__Pascal Bourguignon__


reply via email to

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