Top of Page Current: "emacs lisp 1"    Up: Hobbies    Next: latexing

I hope you know a little about emacs lisp. In case you don't, do take a look at this post in my blog where I give an overview of the lisp programming language. In case you still do not understand or you want to know more have a look at the manual online.

Everything in lisp is a function. In lisp, you perform all tasks via functions. All the functions do is take in a list of one or more symbols and return a single symbol as output. It is good to view the whole process as symbol manipulation and you do not have to bother much with respect to the types of arguments. However, there are a few very basic types such as strings, numbers, lists that has to be adhered to.

Thus a symbol may be a string, a number, a list or a variable. Unlike other languages, the whole type thing in lisp is intuitive and hence we can proceed directly into the programming aspect. Here are some commonly used functions in emacs lisp. To learn how to execute a function in emacs lisp in emacs click here.

N.B.:- The input arguments in square brackets are optional. That is, they may be omitted while writing the function forms in programs. But, the other arguments are compulsory.

Change the table design : 1 2 3 4 5 6

Function Name Syntax Input form Output form
quote or '
(' is a short form of quote)
(quote arg1) or 'arg1 arg1 is any symbol return the symbol arg1
without modification
+ (+ [a1] [a2] ... [an]) 'n' numbers a1,a2 ... an the sum of a1,a2, ... ,an
=> (a1 + a2 + ... +an)
* (* [a1] [a2] ... [an]) 'n' numbers a1,a2 ... an product of a1 a2 a3 ...an
=> (a1 * a2 * ... *an)
- (- [a1] [a2] ... [an]) 'n' numbers a1,a2 ... an subtract from a1,the sum
of a2,a3,... an
=>(a1 - (a2 + a3 + ... an))
/ (/ a1 a2 [a3]... [an]) 'n' numbers a1,a2 ... an Divide a1 by the product,
of a2,a3 ... an
=>(((a1/a2)/a3).../an) or
=>(a1/(a2*a3*...an))
% (% a1 a2) 2 numbers a1,a2 Return the remainder when a1 is divided by a2
=>(a1 % a2)

Now, onto some example codes. Each line contains a program that can be copied into emacs and "evaluated".

Code :
  1. (quote 5)
  2. `5
    ;shorthand for (quote 5)
  3. (quote (+ 1 2))
  4. (+ 1 2)
  5. (+ 1 (+ 2 3))
  6. (- 100 (+ 20 5))

Suppose you evaluated (quote 5) You would get 5 in the echo area.
Similarly,

Well, the s-expression (-), that is the function "-" with no arguments evaluates to 0.
Similarly, (*) =>1 and (+) => 0.
So, what would be the result of evaluating (+ (+) (-) (*))? Well? Do try it out yourself and see.Another thing to be noted is that the arguments to the functions could themselves be functions.

Right! So that was a starter. Do try writing some programs on your own and get used to thinking in the lisp paradigm. I would suggest that you think of a particular arithmetic expression and consider how you would translate it so that it will be understood and evaluated appropriately by the emacs lisp compiler.

We now proceed to the next set of functions. These functions as described here are specific to emacs lisp in the sense that they will work fine in emacs but may not work in other dialects of lisp.

Change table design

Function Name Syntax Input form Output form
concat (concat [str1] [str2] ... [strn]) Any number of string arguments
str1, str2, ... strn
A single string which is the result of
concatenating str1, str2, ... strn
message (message arg1 [arg2] ... [argn]) arg1 has to be a string with
zero or more special symbols
The input arg1 is formatted and printed out.
substring (substring arg1 start end) arg1 is a string
start,end are numbers
Return the substring
arg1[start]...arg1[end]


last updated on 7 July 2009
Created on 18 June 2009