clojuredesign-podcast

Discussions around the Functional Design in Clojure podcast - https://clojuredesign.club/
mmeix 2019-12-18T12:58:03.052100Z

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

mmeix 2019-12-18T12:58:48.052700Z

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

mmeix 2019-12-18T12:58:55.052900Z

and in the REPL:

mmeix 2019-12-18T12:59:29.053300Z

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

mmeix 2019-12-18T12:59:31.053500Z

?

mmeix 2019-12-18T12:59:57.053800Z

(maybe a dumb question…)

lodin 2019-12-18T13:41:43.058200Z

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

mmeix 2019-12-18T14:17:15.059300Z

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

lodin 2019-12-20T09:09:49.007400Z

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

mmeix 2019-12-18T15:44:09.059700Z

found some clarifying things here: https://stuartsierra.com/2016/clojure-how-to-ns.html )

mmeix 2019-12-18T15:47:38.059900Z

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