Hello World in Lisp
Published on 22 August 2019 (Updated: 02 May 2020)
In this article, we tackle Hello World in Lisp.
How to Implement the Solution
Unfortunately, Lisp has many flavors which means the following implementation of Hello World will likely only be applicable to handful of those flavors:
(format t "Hello, World!")
That said, I’m happy to dig into this implementation of Hello World in Lisp.
First things first, we have the format keyword. In Common Lisp, format is basically the equivalent to printf in C. It basically takes some string and outputs it to some destination.
That brings us to this mysterious letter t. According to gigamonkeys, t is actually the destination of the output. More specifically, t indicates standard output. Another option is NIL which causes the string to be returned.
Finally, we have our Hello World string. This is obviously what gets printed to standard output.
How to Run the Solution
If we want to try it ourselves, we can copy the code above into an online Common Lisp compiler. The one I linked is in CLISP, but it gets the job done.
Alternatively, as mentioned before, we can download a copy of Steel Bank Common Lisp as well as a copy of the solution. Assuming SBCL is in the path, we can run a lisp file like a script as follows:
sbcl --script hello-world.lsp
And, that should produce the “Hello, World!” string on the command line.
Further Reading
- Hello World in Lisp on The Renegade Coder