Skip to content
Draft

Lisp #10

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions _posts/2022-10-13-lisp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
layout: post
title: Lisp (Clojure)
date: 2022-10-13 16:28:00+0200
categories: programming-language
---

# Lisp

Lisp is a family of programming languages with many dialects in it.

Most popular are Clojure, Common Lisp, Racket.

## Syntax

There are a few special symbols: ` ()'"[]`.

You can write numbers and strings as you usually do in other programming
languages.


```clojure
100500 ; comment about integer
-1.5 ; flating point number
22/7 ; ratio
"ruby" ; string
\e ; character
#"\d" ; regex
```

## Symbols

```clojure
def ; symbol
+ ; symbol
java.lang.Math/PI ; namespaced symbol
:with ; keyword
:with/regex ; keyword with namespace
```

## Literal collections

```clojure
'(1 2 3) ; list
[1 2 3] ; vector
#{1 2 3} ; set
{:a 1, :b 2} ; map
```

### Atoms

Atom is either a literal (numeric or string) of or a symbol.
You can think of a symbol as of name.

```clojure
(defn factorial [n]
(if (< n 2)
1
(* n (factorial (- n 1)))))
```

### S-expressions

Symbolic expression is an atom or list of other s-exrpressions in braces.

```clojure
(list 3 4 5 (* 3 2) 7) ; s-expression
; list and * are symbols
; 2 3 4 5 7 - numbers
; (* 3 2) - s-expression
```