Fork me on GitHub
Jim Newton07:09:53

Is it really not allowed to define a function by giving its fully qualified name?

(defn clojure-rte.api-test/-main []
  (clojure.test/run-tests 'clojure-rte.api-test))
I get the following error
2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling test/clojure_rte/api_test.clj at (31:1)
   {:clojure.error/phase :macro-syntax-check,
    :clojure.error/line 31,
    :clojure.error/column 1,
    :clojure.error/source "/Users/jimka/Repos/clojure-rte/test/clojure_rte/api_test.clj",
    :clojure.error/symbol clojure.core/defn}

    6971  clojure.lang.Compiler/checkSpecs
    6987  clojure.lang.Compiler/macroexpand1
    7074  clojure.lang.Compiler/macroexpand
    7160  clojure.lang.Compiler/eval
    7131  clojure.lang.Compiler/eval
                  core.clj: 3214  clojure.core/eval
                  core.clj: 3210  clojure.core/eval
    interruptible_eval.clj:   82  nrepl.middleware.interruptible-eval/evaluate/fn/fn
          152  clojure.lang.AFn/applyToHelper
          144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
       425  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   82  nrepl.middleware.interruptible-eval/evaluate/fn
                  main.clj:  414  clojure.main/repl/read-eval-print/fn
                  main.clj:  414  clojure.main/repl/read-eval-print
                  main.clj:  435  clojure.main/repl/fn
                  main.clj:  435  clojure.main/repl
                  main.clj:  345  clojure.main/repl
       137  clojure.lang.RestFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj:  660  clojure.core/apply
                regrow.clj:   20  refactor-nrepl.ns.slam.hound.regrow/wrap-clojure-repl/fn
      1523  clojure.lang.RestFn/invoke
    interruptible_eval.clj:   79  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:   56  nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj:  145  nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
           22  clojure.lang.AFn/run
               session.clj:  202  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  201  nrepl.middleware.session/session-exec/main-loop
           22  clojure.lang.AFn/run
       834  java.lang.Thread/run

1. Caused by clojure.lang.ExceptionInfo
   Call to clojure.core/defn did not conform to spec.
   {:clojure.spec.alpha/problems [{:path [:fn-name],
                                   :pred clojure.core/simple-symbol?,
                                   :val clojure-rte.api-test/-main,
                                   :via [:clojure.core.specs.alpha/defn-args
                                   :in [0]}],
    :clojure.spec.alpha/spec #object[clojure.spec.alpha$regex_spec_impl$reify__2509
                                     "[email protected]"],
    :clojure.spec.alpha/value (clojure-rte.api-test/-main
                                (quote clojure-rte.api-test))),
    :clojure.spec.alpha/args (clojure-rte.api-test/-main
                               (quote clojure-rte.api-test)))}
...stuff omitted...

Jim Newton06:09:14

what is a simple symbol actually?

Jim Newton06:09:46

(defn simple-symbol?
  "Return true if x is a symbol without a namespace"
  {:added "1.9"}
  [x] (and (symbol? x) (nil? (namespace x))))

Jim Newton06:09:02

seems to be a symbol whose namespace is nil

Jim Newton07:09:21

I wonder what the reasoning for that is. coming from Common Lisp, this seems really bizarre.

Jim Newton07:09:56

perhaps it is to maintain the invariant that the reader remain side-effect free ?

Jim Newton07:09:29

However, what does the reader do when it encounters

(defn some-ns/fname [] ...)
I.e., the reader parses that and hands it over to spec to verify, then spec calls simple-symbol? on a symbol which is not simple. Did the parser actually create a symbol in the some-ns namespace?


i don't know the answer to that question 🙂


my guess after looking at: * * * is that a symbol (fully-qualified, so with the namespace part) is created, but not in any particular namespace. it appears one can do this kind of thing:

user=> (symbol "hi/there")
user=> (find-ns 'hi)
so symbols can be created that are not associated with a namespace. or if that demo was not so good:
user=> (symbol "there")
user=> (type (symbol "there"))
user=> there
Syntax error compiling at (REPL:0:0).
Unable to resolve symbol: there in this context


i find many things in clojure to be not so easy to determine reasoning for. sometimes there seem to be answers if an appropriate party is consulted.

peter hull08:09:41

I think the intention is to discourage you from creating symbols in another namespace, to keep things modular. If there is a symbol already, you can set it from 'outside' with alter-var-root. Hopefully someone with more knowledge can provide more detail.


Did I get this right about datomic ions: When I deploy a web application, I can still modify the underlying system my main application runs on, because it's just an EC2 instance running linux under the hood? I'm asking because i need libpython-cljto run some python scripts on the backend as well, so I need to have a python environment on wherever my code will run