When do i need to include an apostrophe in clojure?

What's the difference between:

(require '[some-package.sub as some]) (require 'example.core) 

and

 (require [some-package.sub as some]) (require example.core) 

When should I use one over the other? Only one with an apostrophe works in the REPL environment.

+5
source share
1 answer

require is a function (check with (source require) in the REPL). Thus, his parameters are evaluated before his own assessment.

At the time you call, the some-package.sub character is required to allow (points) nothing, so you get "Cannot resolve the character: the-symbol-that-points-to-nothing in this context ..."

However, if you specify the specified character, we can get the actual estimate of require . Thus, require , since it is a function, requires quoted forms.

Now ns is a macro (check with (source ns) in REPL). Thus, it does not evaluate its parameters before extension. Technically, it can accept free characters or quotes, but it was decided to use raw free characters. (ns lalala (:require [some-package.sub :as some]))

No-ooo-ow, when you call require (function) with a , you really need a character that is stored by var, which allows.

Example:

 (def a 'B) (require a) FileNotFoundException Could not locate B__init.c;ass or B.clj on the classpath[...] 

... because require is a function.

Hope this helps.

+8
source

All Articles