Day 1 - Lisp Learning

Saturday, February 3, 2024 | Permalink

In my free time (which I have very less), I'm learning Lisp programming language. After doing some search, I decided to go with Common Lisp and installed sbcl.

Unless you're using Emacs, do not write multiple lines of code in REPL (in Terminal). Most of the terminals don't support paren auto-closing and highlight. Due to this, you might frustrate.

I'm using GNU/Linux machine. Following command help me to install the sbcl on my computer.

sudo apt install sbcl

After installation, check for the version and you can confirm the installation.

sbcl --version

Write only sbcl and it'll open the true REPL for you. In order quit or exit the REPL you need to write (quit).

You can directly write 10 or "hello, world" (use double quotes) as these are the literal values.

* 10
10
* "hello, world"
"hello, world"


If you try to write 10 as (10) or "hello, world" as ("hello, world") you'll get errors. Because, in simple terms, after open paren, Lisp expect to have something that can execute. For example, (+ 3 4) works as + will execute on 3 and 4 values.

Here is the hello, world in Common Lisp.

* (format t "hello, world")

Here, format print on terminal (actually it is standard output) "hello, world" string. You can write code within file that can have .lisp extension. Then you can run it as,

sbcl --script hello.lisp

or Open sbcl REPL and load the file.

sbcl
* (load "hello.lisp")
 

Labels: