1

What's the best way to rename Clojure's special forms?

For example, if I preferred defvar over def or defun over defn, what would be the best way to go about it?

Selam S
  • 43
  • 3

2 Answers2

8

Just use def and defn instead. You can define macros that forward to the underlying special forms, but it's in much better taste to just use the same primitives everyone else does.

amalloy
  • 89,153
  • 8
  • 140
  • 205
  • 1
    I already see the benefits of using the existing functions. It would be great if you could give an example of forwarding using macros. Thank you! – Selam S Sep 22 '17 at 08:11
5

While I perfectly agree with amalloy's answer it may be interesting to see the quick and dirty solution. You can forward the macro call by taking all the arguments of the original call and constructing another macro call using the genuine Clojure version.

(defmacro defvar [& xs] `(def ~@xs))
(defmacro defun [& xs] `(defn ~@xs))
bfontaine
  • 18,169
  • 13
  • 73
  • 107
erdos
  • 3,135
  • 2
  • 16
  • 27