From f2c2f2c764a4bf08d4ef950dfff8434fa4665385 Mon Sep 17 00:00:00 2001 From: Dmitry Barskov Date: Thu, 27 Oct 2022 23:40:28 +0200 Subject: [PATCH 1/2] Lisp --- _posts/2022-10-13-lisp.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 _posts/2022-10-13-lisp.md diff --git a/_posts/2022-10-13-lisp.md b/_posts/2022-10-13-lisp.md new file mode 100644 index 0000000..60f491c --- /dev/null +++ b/_posts/2022-10-13-lisp.md @@ -0,0 +1,31 @@ +--- +layout: post +title: Lisp +date: 2022-10-13 16:28:00+0200 +categories: programming-language +--- + +# Lisp + +Lisp is a family of programming languages with many dialects in it. + +## Syntax + +You can write numbers and strings as you usually do in other programming +languages. + +### Atoms + +Atom is either a literal (numeric or string) of or a symbol. +You can think of a symbol as of name. + +### S-expressions + +Symbolic expression is an atom or list of other s-exrpressions in braces. + +```lisp +(list 3 4 5 (* 3 2) 7) ; s-expression +; list and * are symbols +; 2 3 4 5 7 - numbers +; (* 3 2) - s-expression +``` From ce61ec0cae95608330ce665c4c0cee34b77cf70d Mon Sep 17 00:00:00 2001 From: Dmitry Barskov Date: Fri, 28 Oct 2022 00:51:11 +0200 Subject: [PATCH 2/2] Lisp lisp lisp --- _posts/2022-10-13-lisp.md | 44 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/_posts/2022-10-13-lisp.md b/_posts/2022-10-13-lisp.md index 60f491c..f2a13cf 100644 --- a/_posts/2022-10-13-lisp.md +++ b/_posts/2022-10-13-lisp.md @@ -1,6 +1,6 @@ --- layout: post -title: Lisp +title: Lisp (Clojure) date: 2022-10-13 16:28:00+0200 categories: programming-language --- @@ -9,21 +9,61 @@ categories: programming-language 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. -```lisp +```clojure (list 3 4 5 (* 3 2) 7) ; s-expression ; list and * are symbols ; 2 3 4 5 7 - numbers