Why is there a difference in using require
in a file and in the REPL?
(ns my.ns
(:require [clojure.string :as str]))
and in the REPL:
(require '[clojure.string :as str])
?
(maybe a dumb question…)
@mmeix ns is a macro, and converts the above code to a call to require. The quote is needed to stop Clojure from evaluating the vector and resolving the symbols. In ns you don't need it because macros get unevaluated forms as arguments (that's the point of macros).
ah - ok! (didn’t know about the macro here) - thanks!
Yeah. I've assumed that's because (symbol (name x))
gives the same result for :foo
as 'foo
.
found some clarifying things here: https://stuartsierra.com/2016/clojure-how-to-ns.html )
Interesting: “Use keywords, not symbols, for `:refer-clojure`, `:require`, and `:import`. Symbols happen to work in most versions of Clojure, but were never correct syntax.”