Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the weird ' usage for ns/use with Clojure?

Tags:

clojure

I define namespace inside a clojure lib without ',

(ns myproject.hello) 

But, I use ' for using it.

(use 'myproject.hello)

Why is this? Is there any logic behind this? In gosh (dialect of scheme), I use without ' i.e. (use myproject) Why is this irregularity?

like image 807
prosseek Avatar asked Aug 19 '10 19:08

prosseek


2 Answers

Short answer: ns is a macro, so its arguments are not evaluated. use is a function, so its arguments must be quoted to prevent the compiler from evaluating them.

The use/require functions were not part of the original design of Clojure, they got added by contributors. They are in need of an overhaul.

like image 105
Stuart Sierra Avatar answered Sep 19 '22 15:09

Stuart Sierra


The idiomatic way is:

(ns myproject.hello

(:use myproject.world))

like image 41
Nicolas Oury Avatar answered Sep 20 '22 15:09

Nicolas Oury