Introduction to Common Lisp

Introduction to Common Lisp




Common Lisp is a powerful and expressive programming language that has been around for decades. It is one of the oldest and most influential members of the Lisp family of languages, which are known for their elegant syntax, dynamic features, and support for multiple paradigms. In this article, we will give you a brief overview of Common Lisp and show you how to get started with writing and running simple programs.


What is Common Lisp?


Common Lisp is a general-purpose, multi-paradigm programming language that supports functional, imperative, object-oriented, and meta-programming styles. It is also a dialect of Lisp, which stands for LISt Processing. Lisp was invented in the late 1950s by John McCarthy as a mathematical notation for computer programs. Lisp is based on the idea of manipulating symbolic expressions, which are represented as lists of atoms or other lists. For example, (+ 1 2) is a list that represents the expression 1 + 2.


One of the distinctive features of Lisp is that it is a homoiconic language, which means that its code and data have the same structure and can be manipulated by the same functions. This allows Lisp programmers to write programs that generate and modify other programs, a technique known as metaprogramming. Metaprogramming enables powerful abstractions and domain-specific languages that can simplify complex tasks.


Another feature of Lisp is that it is a dynamically typed language, which means that variables do not have fixed types and can hold values of any type at runtime. This gives Lisp programmers more flexibility and expressiveness, but also requires more care and discipline to avoid errors. Lisp also provides mechanisms for error handling and debugging, such as conditions and restarts.


Common Lisp is not a single language, but a standard that defines a core set of features and a large library of functions and macros. There are many implementations of Common Lisp, such as SBCL, CCL, ECL, CLISP, and ABCL. Each implementation may have its own extensions and optimizations, but they all conform to the Common Lisp standard. The standard was first published in 1984 as ANSI X3.226-1984 (also known as CLtL1), and was revised in 1994 as ANSI X3.226-1994 (also known as CLtL2 or ANSI Common Lisp).


How to get started with Common Lisp?


To start writing and running Common Lisp programs, you need two things: a Common Lisp implementation and an editor or IDE (Integrated Development Environment). A Common Lisp implementation is a program that can execute Common Lisp code, either by compiling it to native code or by interpreting it on the fly. An editor or IDE is a tool that helps you write and edit code, as well as interact with the implementation.


There are many options for choosing a Common Lisp implementation and an editor or IDE, depending on your preferences and needs. Some popular choices are:


- SBCL (Steel Bank Common Lisp): A high-performance compiler that produces native code for various platforms. It also has an interactive REPL (Read-Eval-Print Loop) that allows you to evaluate expressions and run commands.

- Emacs + SLIME (Superior Lisp Interaction Mode for Emacs): A combination of the Emacs editor and the SLIME extension that provides a powerful environment for developing Common Lisp applications. It allows you to edit code in Emacs buffers, compile and load it into SBCL (or other implementations), debug it with breakpoints and inspectors, browse documentation and source code, and more.

- Portacle: A portable and self-contained distribution of Emacs + SLIME + SBCL + Quicklisp (a library manager for Common Lisp) that works on Windows, Linux, and macOS. It is easy to install and use, and provides everything you need to start coding in Common Lisp.

- Lumen: A web-based IDE that runs in your browser and connects to a remote Common Lisp server. It offers syntax highlighting, code completion, documentation lookup, REPL interaction, debugging tools, and more.


To illustrate how to use one of these options, we will use Portacle as an example. To install Portacle, you just need to download the appropriate archive file from https://portacle.github.io/ , extract it to a folder of your choice, and run the portacle executable. This will launch Emacs with SLIME already configured.


To create a new file in Emacs, you can use the command C-x C-f (Control-x Control-f), which will prompt you for a file name. You can enter any name you like, but it is customary to use the .lisp extension for Common Lisp files. For example, you can enter hello.lisp to create a file named hello.lisp in your current directory.



Post a Comment

Previous Post Next Post