Fork me on GitHub
#clojuredesign-podcast
<
2019-12-18
>
mmeix12:12:03

Why is there a difference in using require in a file and in the REPL?

mmeix12:12:48

(ns my.ns (:require [clojure.string :as str]))

mmeix12:12:55

and in the REPL:

mmeix12:12:29

(require '[clojure.string :as str])

mmeix12:12:57

(maybe a dumb question…)

lodin13:12:43

@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).

mmeix14:12:15

ah - ok! (didn’t know about the macro here) - thanks!

mmeix15:12:38

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.”

lodin09:12:49

Yeah. I've assumed that's because (symbol (name x)) gives the same result for :foo as 'foo.