all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: pjb@informatimago.com (Pascal J. Bourguignon)
To: help-gnu-emacs@gnu.org
Subject: Re: How to learn elisp ?
Date: Wed, 05 Aug 2009 17:34:45 +0200	[thread overview]
Message-ID: <7cocqujmui.fsf@pbourguignon.anevia.com> (raw)
In-Reply-To: mailman.3940.1249477629.2239.help-gnu-emacs@gnu.org

"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__


  parent reply	other threads:[~2009-08-05 15:34 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-05 10:08 How to learn elisp ? waterloo
2009-08-05 11:24 ` Andy Stewart
2009-08-05 13:06 ` Drew Adams
     [not found] ` <mailman.3940.1249477629.2239.help-gnu-emacs@gnu.org>
2009-08-05 15:34   ` Pascal J. Bourguignon [this message]
2009-08-05 15:47     ` Drew Adams
     [not found]   ` <7cocqujmui.fsf@pbourguignon.informatimago.com>
     [not found]     ` <mailman.3950.1249487281.2239.help-gnu-emacs@gnu.org>
2009-08-05 17:21       ` Pascal J. Bourguignon
2009-08-05 17:45         ` Drew Adams
  -- strict thread matches above, loose matches on Subject: below --
2009-08-05 11:26 waterloo
2009-08-05 11:47 ` Tim Visher
2009-08-05 11:59   ` waterloo
2009-08-05 12:54     ` Andy Stewart
     [not found]     ` <mailman.3941.1249477743.2239.help-gnu-emacs@gnu.org>
2009-08-06  9:32       ` Jyrki Tikka
2009-08-06 12:32         ` Elena
2009-08-06 14:59           ` Drew Adams
     [not found]   ` <mailman.3936.1249473586.2239.help-gnu-emacs@gnu.org>
2009-08-05 13:18     ` Anselm Helbig
     [not found] <mailman.3930.1249466928.2239.help-gnu-emacs@gnu.org>
2009-08-05 10:26 ` David Kastrup
2009-08-05 10:40   ` Thierry Volpiatto
2009-08-05 11:44 ` Elena
2009-08-06 23:28 ` despen
     [not found] <mailman.3934.1249471596.2239.help-gnu-emacs@gnu.org>
2009-08-05 12:08 ` Xah Lee
2009-08-05 13:56 waterloo
2009-08-05 14:06 ` Andy Stewart
     [not found] ` <mailman.3945.1249481229.2239.help-gnu-emacs@gnu.org>
2009-08-05 15:49   ` A.Politz
2009-08-05 16:25     ` Richard Riley
2009-08-05 16:28 waterloo
     [not found] <mailman.3943.1249480576.2239.help-gnu-emacs@gnu.org>
2009-08-05 17:31 ` Barry Margolin
2009-08-05 17:53   ` Pascal J. Bourguignon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7cocqujmui.fsf@pbourguignon.anevia.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.