Avoid name clashes in a Clojure DSL

Viewed 497

As a side project I'm creating a Clojure DSL for image synthesis (clisk).

I'm a little unsure on the best approach to function naming where I have functions in the DSL that are analogous to functions in Clojure core, for example the + function or something similar is needed in my DSL to additively compose images / perform vector maths operations.

As far as I can see it there are a few options:

  1. Use the same name (+) in my own namespace. Looks nice in DSL code but will override the clojure.core version, which may cause issues. People could get confused.
  2. Use the same name but require it to be qualified (my-ns/+). Avoids conflicts, but prevents people from useing the namespace for convenience and looks a bit ugly.
  3. Use a different short name e.g. (v+). Can be used easily and avoid clashes, but the name is a bit ugly and might prove hard to remember.
  4. Use a different long name e.g. (vector-add). Verbose but descriptive, no clashes.
  5. Exclude clojure.core/+ and redefine with a multimethod + (as georgek suggests).

Example code might look something like:

 (show  (v+ [0.9 0.6 0.3] 
             (dot [0.2 0.2 0] 
                  (vgradient (vseamless 1.0 plasma) ))))

What is the best/most idiomatic approach?

1 Answers
Related