Skip to content

Instantly share code, notes, and snippets.

Bayan Khalili bayan

Block or report user

Report or block bayan

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bayan
bayan / gist:3382884
Created Aug 17, 2012
Clojure DSL to generate static HTML
View gist:3382884
;; 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")
@bayan
bayan / i18n.clj
Created Aug 15, 2012
Transliterajure - Clojure macros to internationalize source code
View i18n.clj
;; 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.
;;
@bayan
bayan / gist:3331552
Created Aug 12, 2012
Ruby's array of words and symbols shortcuts in Clojure - an example of how macros can be used to implement language level features that are present in other languages
View gist:3331552
;; 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")
You can’t perform that action at this time.