This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Ruby has a short cut to specify an array of words: %w(apple bee carrot) → ["apple", "bee", "carrot"] | |
;; This can't be implemented in Ruby itself, and requires the language designers to implement this (in C). | |
;; Clojure, being a Lisp, allows anyone to add such a feature directly using a macro: | |
(defmacro %w [& args] `(map str '~args)) | |
(%w apple bee carrot) | |
;; → ("apple" "bee" "carrot") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; English is the defacto standard when it comes to programming languages. | |
;; It is used to derive the names of special forms (e.g. if, def, etc) and core functions (find, map, etc). | |
;; | |
;; What about when you can't or just don't want to write in English? | |
;; For example: http://en.wikipedia.org/wiki/Language_policy_in_France | |
;; | |
;; How hard would it be to write code using another language? | |
;; Preprocessing source files using substitution before compiling/running won't allow us to run the code from a REPL. | |
;; Let's see what we can do in Clojure. | |
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Generating static HTML using Clojure macros | |
;; It is possible to write a DSL in Clojure that generates HTML markup without the need to write a separate parser and compiler (e.g. HAML). | |
;; Our aim here would be to write code that converts the following Clojure code into the HTML below it | |
;; (html | |
;; (head) | |
;; (body | |
;; (h1 "An example") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Keybase proof | |
I hereby claim: | |
* I am bayan on github. | |
* I am bkhalili (https://keybase.io/bkhalili) on keybase. | |
* I have a public key ASA6Uza5arh0TkVrTwC5AYii5ThWrtDUEyjrXtwlLNAD8wo | |
To claim this, I am signing this object: |