This is Words and Buttons Online — a collection of interactive #tutorials, #demos, and #quizzes about #mathematics, #algorithms and #programming.

Learn you a Lisp in 0 minutes

But why?

Learning a language, you are not going to write in professionally, is like visiting a country you are not going to move in to. It may be tiring, but it’s fun, educational and it makes you appreciate other cultures. And Lisp is particularly fascinating to learn because of its influence on modern programming. You might see traces of Lisp in the most unexpected technologies like WebAssembly or GCC internal representation.

The only reason not to learn Lisp, or any other language, is the amount of effort it usually takes. But! If you only want to know the very basics of Lisp, you wouldn’t have to spend any effort at all.

But how?

Since you are reading this article, you probably know English. And this also means that you know a bit of French as well. Words like “concept”, “culture”, “action”, “instinct”, “machine”, “science”, and many more are actually shared between the two languages. Words like these are called “cognates”, and the word “cognate” is almost a cognate itself.

This happens because of long-lasting French influence on the English language. And the same goes for Lisp too. Its ideas and concepts are so widespread among modern languages that if you have any substantial experience in programming at all — you automatically know some Lisp.

So?

I've prepared several exercises so you could prove to yourself that you do know a little Lisp. As many languages and dialects belong to the Lisp family, I should specify that this quiz is based on WeScheme.

The exercises start with very simple things and gradually progress into obscurity. It’s ok not to get all the answers right, some of them would only work for programmers with a functional programming background.

Amuse-toi!

1 What number would this evaluate to?

(+ 2 2)
	
Please enter your answer:

2 Does this return true or false?

(= (+ 2 2) (* 2 2))
	

3 Is it a, b or c?

(first (list 'a 'b 'c))
	

4 Would it print “Apples” or “Oranges”?

(define apples 5)
(define oranges 6)
(if (< apples oranges)
    (printf "Apples")
    (printf "Oranges"))
	

5 What number would it be?

(define (dbl x)
    (* 2 x))

(dbl 2)
	
Please enter your answer:

6 What number will this result to?

(define (fact x)
    (if (<= x 1)
        1
        (* x (fact (- x 1)))))

(fact 3)
	
Please enter your answer:

7 What would this function do to the list?

(define (qs xs)
    (if (empty? xs)
        (list )
        (let ((middle (first xs))
              (others (rest xs)))
            (let ((left (filter (lambda (x) (<= x middle)) others)
                  (right (filter (lambda (x) (> x middle)) others)))
                (append (qs left) (cons middle (qs right)))))))

(qs (list 4 5 1 2 3))
	
Your answer please:

Now it's time to see how well do you know Lisp.

To see your final score, please press the button below.