In this post I want to discuss about how to install and start coding with Lisp. Before start coding we must need to install the lisp in your system, for that open your terminal in your system and type
sudo apt-get install clisp
with in few minutes clisp (Common Lisp) is installed in your system. you must check to verify that lisp is correctly installed or not in your system, for that just type clisp in terminal, if it is correctly installed then it will display on the window like this
Now lisp was successfully installed in your system. Now you can start coding. Like python, we can run the lisp code in two ways. Interpreted mode and batch mode. in interpreted mode, programmer write the code line by line in the terminal, clisp interpreter process and return result. In batch mode, programmer can write code as a file, after that execute it.
Now I show you an example in two different method.
Example : Program to print "Hello world"
In Interpreted method just type the (print "Hello world") in terminal.
> (print "Hello world")
In batch method open any editor and type (print "Hello world ") after that save the file with .lsp extension. Run the program by just type clisp pgmname.lsp
anoop@anoop-laptop:~$ clisp hello.lsp
I will discuss more complex examples in the next post's. Now i want to discuss some important features of lisp.
Significant Language Features
- Atoms & Lists - Lisp uses two different types of data structures, atoms and lists.
- Atoms are similar to identifiers, but can also be numeric constants
- Lists can be lists of atoms, lists, or any combination of the two
- Functional Programming Style - all computation is performed by applying functions to arguments. Variable declarations are rarely used.
- Uniform Representation of Data and Code - example: the list
(A B C D)
- a list of four elements (interpreted as data)
- is the application of the function named
Ato the three parameters
D(interpreted as code)
- Reliance on Recursion - a strong reliance on recursion has allowed Lisp to be successful in many areas, including Artificial Intelligence.
- Garbage Collection - Lisp has built-in garbage collection, so programmers do not need to explicitly free dynamically allocated memory.
Areas of Application
Below is a short list of the areas where Lisp has been used:
- Artificial Intelligence
- Air Defense Systems
- Implementation of Real-Time, embedded Knowledge-Based Systems
- List Handling and Processing
- Tree Traversal (Breath/Depth First Search)
- Educational Purposes (Functional Style Programming)