Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Clojure by
(ns foo
  (:require [clojure.java.io :as io]))

(defn f [] ::io/key)

Clojure 1.10.0-alpha4
user=> (require 'foo)
user=> (source foo/f)
RuntimeException Invalid token: ::io/key  clojure.lang.Util.runtimeException (Util.java:221)

*Problem analysis*
{{source}} calls {{read}}, without any underlying binding or notion of {{Compiler.currentNS()}}, which causes aliased keywords to fail to resolve.

*Possible solution*
Bind \*reader-resolver\* to the following before reading:

(reify LispReader$Resolver
  (currentNS [_] 'ignored)
  (resolveClass [_ sym] 'ignored)
  (resolveAlias [_ sym] 'ignored)
  (resolveVar [_ sym] 'ignored))

Aside, the logic inside {{source-fn}} can be simplified with {{read+string}}, modulo CLJ-2358

1 Answer

0 votes
Reference: https://clojure.atlassian.net/browse/CLJ-2359 (reported by gshayban)