ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

Follow publication

Member-only story

What Makes LISP Unique?

Erik Engheim
ITNEXT
Published in
9 min readSep 28, 2022

--

Alien LISP mascot by Conrad Barski, M.D.
Alien LISP mascot by Conrad Barski, M.D.

The LISP programming language and its derivatives, such as Scheme and Clojure, have a feature that has long fascinated me, referred to as homoiconicity.

It implies that code is represented as data in LISP, and thus can be manipulated and modified in the same manner as data. To truly appreciate the profound implications of such a simple statement requires reading a book and write your own LISP code. You probably don’t have time for that, so let me instead give you an inkling or intuition through this short article.

Understanding LISP always begins with understanding the core data structure LISP is built around, a linked list. It may seem peculiar that understanding a language relies on understanding a data structure, but bear with me.

The following LISP code defines a linked list containing an integer, a string, a boolean value, a floating-point number and a character. Notice how the LISP expression begins and ends with parenthesis. LISP is infamous for the abundance of parenthesis.

(list 43 "hello" true 2.5 'c')

Please note that to make LISP code examples easier to read, I have taken the liberty of using C-like syntax for booleans and characters. Standard LISP will use different syntax.

A linked list consist of nodes, where each node can point to another node. It also has a cell to store data. But this can also be a pointer to another list. Hence, we can have lists of lists, These lists can also be lists of lists.

(list 34 (list "hello" true) (list 2.5 'c'))

Thus, one can express complex data structures and tree structures this way. If you know a little bit about how a compiler works, you already know that when it parses code, it produces an abstract syntax tree. In a mainstream programming language, you may have an expression such as y = 4*(2 + x). It could be represented as the syntax tree you see below.

Abstract Syntax Tree (AST) of expression y = 4*(2 + x)
Abstract Syntax Tree (AST) of expression y = 4*(2 + x)

--

--

Published in ITNEXT

ITNEXT is a platform for IT developers & software engineers to share knowledge, connect, collaborate, learn and experience next-gen technologies.

Written by Erik Engheim

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.