What is 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 the one with apostrophe works in an REPL environment.
require
is a function (check with (source require)
in a REPL). Thus is evaluates its parameters before its own evaluation.
At the time you call require the symbol some-package.sub
resolves (points)
to nothing, so you get a "Unable to resolve symbol: the-symbol-that-points-to-nothing
in this context..."
However, if you quote the said symbol we can get to the actual evaluation of require
. Thus require
, since it is a function, necessitates quoted forms.
Now ns
is a macro (check with (source ns)
in a REPL). Thus is doesn't evaluate its parameters before expansion. Technically it could take free symbols or quoted forms but it was decided to use raw free symbols. (ns lalala (:require [some-package.sub :as some]))
No-o-o-o-ow, when you call require
(function) with a
, you will actually require the symbol which is held by the var which a resolves to.
(def a 'B)
(require a)
FileNotFoundException Could not locate B__init.c;ass or B.clj on the classpath[...]
...that's because require is a function.
Hope it helped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With