62

Learn you a Lisp in 0 minutes

 4 years ago
source link: https://www.tuicool.com/articles/ru2ABnm
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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)

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)

6 What number will this result to?

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

(fact 3)

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK