LISP: A Blast from the Past
Hi Everyone! This is my first ever article and I wanted to write about the LISP Family of Programming Languages. Now, you might have never heard about a LISP language. That's because it's not a mainstream language.
LISP is an acronym for List Processing. It was one of the earliest languages used for artificial intelligence research. One of the cool features of it is that it allows us to interchange code and data. Now, what do I mean by that? Suppose, you have a function that operates on some data like strings or integers to generate new data by returning some value. Now imagine if that function itself can be used as data and you can use it to further generate another function. Isn't that cool? That is exactly what LISP allows us to do. This concept is called Metaprogramming. So, by using this feature of LISP, we can write programs that generate programs.
I recently started to learn one of its dialects called Racket. It was a new experience for me as this language is so different from something like Python and C++, with parentheses all over the place.
So, without further ado, let me show you how does it look like by using its dialect, Racket.
Adding two numbers:
(+ 1 2)
Fun fact: Writing operators and operands in this way (operator first and then the operands) is called Polish Notation or Prefix Notation.
Assigning value to a variable:
(define myname "Azan")
Comments:
; This is a comment :)
; Comments start with a semi-colon. Hah, take that C++
if-else statements:
(if (> 2 1) ; This is the predicate or the question.
"YES" ; This will execute if the predicate is true.
"NO") ; This will execute if the predicate is false.
As you can see, the number of parentheses increases as we write more and more code.
Now, you might be wondering: "But wait how can I run all this code and try it for myself?". Well, my friend, you don't have to worry about that. Simply install DrRacket and choose the Racket Language from the Language tab.
Go ahead, try out the language and explore what it has to offer.
So, there you have it. Let me know if you want me to write more about it. Dive a little deeper into functions and write some small programs.
Anyway, Azan signing out :)
Subscribe to my newsletter
Read articles from Azan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Azan
Azan
I am a computer science student from Pakistan. I write about things I learn and find interesting, which mostly includes computer science stuff.