Basic LISP commands and their syntax.
So, you ever considered trying some functional programming languages, and can’t decide which? Ever wondered if LISP (LISt Processing) really is short for Lots of Irritating, Silly Parantheses or not? Well, let me give you a helping hand in some of the basics. This little guide is using the module CLISP with Common Lisp, but others will most likely do the same.
How to define a global variable.
(defparameter variablename value)
Pretty simple, huh? The usual convention is to incapsulate the variable in *, to specify that it’s a global variable. So it could look like this when actually used.
Example: (defparameter *thirtyfour* ‘34)
How to add two numbers
(+ number1 number2)
What? The plus is first? How strange! Well, in lisp, when you start a paranthesis, the next list element will often be a function. And than the next list elements will be the parameters of the function. The function plus (+) actually takes any number of parameters, but we will just use two.
Example: (+ 2 4) => 6.
How to define a function
(defun function-name (parameterlist)
(what you want to do))
Let’s try defining a function that adds two numbers.
(defun add-two-words (number1 number2)
(+ number1 number2))
If we would call this function, it would look like this:
Example: (add-two-words 2 4). This would return 6.
More to come.
Why did you suddenly start writing in english?
And why are you writing a LISP-tutorial, when there already exists a lot of them? Probably better than yours too. Stick to what you do best. Dry humour.
(format t “My ~A cents” (+ 1 1))
I want to write a simple introduction to the language, focusing on getting started. Later on I will hopefully include some more advanced features, and propably someone will enjoy this. So stop beeing so damn negative! There enought webspace for all of us.
And about the english: I plan to write the more educational posts in english, so everyone can enjoy them.
Be more consistant, you fool!
Tar til etterretning. Forvent blog om temaet i nær framtid! (I morgen)
Gleder meg som en unge.
[...] wrote in both english AND norwegian. This might seem stressful, and I got some feedback in some of the comments that I need to be more consistent, and stick to one [...]