Welcome back to another installment of the Hello World in Every Language series. At this point, we've covered 12 of the more popular languages like Python and Ruby. Today, we're going to drift away from the industry languages a bit. In fact, we're going to start playing with functional programming languages. Up first is Hello World in Lisp!\n\n\n\nIf you're interested in learning more about Lisp beyond what you'll find in this article, I recommend heading over to my Lisp Programming Language article. In it, you'll learn more about the underlying structure of Lisp including the design of the interpreter. If you're into that sort of thing, check it out! \n\n\n\n\n\nLisp Background\n\n\n\nAt this point, it's probably no surprise that I took to Wikipedia to learn some more about Lisp. \n\n\n\nAccording to Wikipedia, Lisp is actually a family of languages. In other words, Lisp has many dialects. For the purposes of this exercise, we'll be using Common Lisp.\n\n\n\nThat said, let's talk about Lisp in general. As it turns out, Lisp, a language developed in 1958, is the second oldest high-level programming language. The only older language is Fortran. Since its inception, the language has split into several dialects. Perhaps some of the most notable dialects are Scheme, Common Lisp, and Clojure.\n\n\n\nExpressions\n\n\n\nIn terms of features, Lisp differs wildly from the languages we've already covered. For example, all data in Lisp is represented with expressions - in particular, symbolic expressions. These expressions are written in prefix notation:\n\n\n\n(+ 3 6 11)\n\n\n\nIn infix notation, the above expression reads:\n\n\n\n(3 + 6 + 11)\n\n\n\nSo, the expected result is 20.\n\n\n\nLists\n\n\n\nIn addition, Lisp is heavily list based. In fact, Lisp is short for List Processor, so it should be no surprise that lists play an important role in the language.\n\n\n\nImplementing a list in Lisp is rather simple:\n\n\n\n(list 1 5 2 1)\n\n\n\nHere. we've generated a list of four elements: 1, 5, 2, and 1. In fact, we can even nest lists using the prefix notation:\n\n\n\n(list 1 (list 5 2) 1)\n\n\n\n\nThe resulting list would look like the following:\n\n\n\n(1 (5 2) 1)\n\n\n\nKeep this syntax in mind when we get to functions.\n\n\n\nLambda Expressions\n\n\n\nHave you ever played with lambda expressions in other languages like Java or Python? Well, Lisp has them too:\n\n\n\n(lambda (arg) (* arg 2))\n\n\n\nIn this lambda expression, we simply multiply an argument by 2. If we wanted to use the expression, we would have to pass a value to it:\n\n\n\n((lambda (arg) (* arg 2)) 10)\n\n\n\nIf this is confusing, remember that everything is in prefix notation, so this code might look something like the following in a language like Python:\n\n\n\nfoo = lambda n: n * 2\n\nfoo(10)\n\n\n\nNotice, however, that we have a named function in the Python example and an anonymous function in the Lisp example. Don't worry though. Lisp has named functions as well.\n\n\n\nFunctions\n\n\n\nIn Lisp, a named function is essentially a lambda expression that is stored in a symbol:\n\n\n\n(defun foo (arg) (* arg 2))\n\n\n\nIn this example, we've created the exact same lambda expression, but we've stored it in a function called foo. We can then call foo from anywhere in our program:\n\n\n\n(foo 10)\n\n\n\nHow cool is that? I think I'm starting to like Lisp. Of course, we haven't even gotten to implement Hello World in Lisp, so we should probably get to that.\n\n\n\nFor the purposes of this exercise, we'll be using the latest Steel Bank version of Common Lisp.\n\n\n\nHello World in Lisp\n\n\n\nUnfortunately, Lisp has many flavors which means the following implementation of Hello World will likely only be applicable to handful of those flavors:\n\n\n\n(format t "Hello, World!")\n\n\n\nThat said, I'm happy to dig into this implementation of Hello World in Lisp.\n\n\n\nFirst 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.\n\n\n\nThat 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.\n\n\n\nFinally, we have our Hello World string. This is obviously what gets printed to standard output.\n\n\n\nHow to Run the Solution\n\n\n\nIf 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.\n\n\n\nAlternatively, 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:\n\n\n\nsbcl --script hello-world.lsp\n\n\n\nAnd, that should produce the "Hello, World!" string on the command line.\n\n\n\nSample Programs in Every Language\n\n\n\nLooks like that's the end of another chapter of the Hello World in Every Language series. Once again, I got a little caught up in language features. Though, I figure that's probably the point of this whole series after all. I've learned quite a lot already, and there's plenty to still cover.\n\n\n\nAs I mentioned last time, I think I'm going to stick with functional languages for a few days. Up next, I'd like to take a look at Scheme. Then, maybe I'll start playing with some of the newer functional languages. Stay tuned!\n\n\n\nAs always, if there's a language you want to see, drop it below in the comments. If you're still looking for ways to support my journey, make sure to share this article on social media. Every little bit helps!