Fork me on GitHub
#beginners
<
2020-09-20
>
Jim Newton07:09:24

when defining a namespace, I can use (:require [some-namespace :refer [name1 name2 ...]) Is there a way to only list the names I DONT want to import instead?

Jim Newton07:09:24

when defining a namespace, I can use (:require [some-namespace :refer [name1 name2 ...]) Is there a way to only list the names I DONT want to import instead?

Jim Newton07:09:14

I guess this is the :exclude option ?

Jim Newton07:09:10

but apparently I must use :refer :all :exclude [...]

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}

             Compiler.java: 6971  clojure.lang.Compiler/checkSpecs
             Compiler.java: 6987  clojure.lang.Compiler/macroexpand1
             Compiler.java: 7074  clojure.lang.Compiler/macroexpand
             Compiler.java: 7160  clojure.lang.Compiler/eval
             Compiler.java: 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
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  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*
               RestFn.java:  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
               RestFn.java:  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
               RestFn.java: 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
                  AFn.java:   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
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  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
                                         :clojure.core.specs.alpha/defn-args],
                                   :in [0]}],
    :clojure.spec.alpha/spec #object[clojure.spec.alpha$regex_spec_impl$reify__2509
                                     "0x1f2ac1cd"
                                     "[email protected]"],
    :clojure.spec.alpha/value (clojure-rte.api-test/-main
                               []
                               (clojure.test/run-tests
                                (quote clojure-rte.api-test))),
    :clojure.spec.alpha/args (clojure-rte.api-test/-main
                              []
                              (clojure.test/run-tests
                               (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?

sogaiu07:09:57

i don't know the answer to that question 🙂

sogaiu07:09:06

my guess after looking at: * https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java#L305 * https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java#L408 * https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/LispReader.java#L416-L464 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")
hi/there
user=> (find-ns 'hi)
nil
so symbols can be created that are not associated with a namespace. or if that demo was not so good:
user=> (symbol "there")
there
user=> (type (symbol "there"))
clojure.lang.Symbol
user=> there
Syntax error compiling at (REPL:0:0).
Unable to resolve symbol: there in this context

sogaiu07:09:53

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.

amirali18:09:39

Hi folks. what can cause this? :

Exception in thread "async-dispatch-1" clojure.lang.ArityException: Wrong number of args (3) passed to: clojure.core.async.impl.ioc-macros/put!
besides the fact that I dont have any put! <! >! with 3 arity!

amirali18:09:39

Hi folks. what can cause this? :

Exception in thread "async-dispatch-1" clojure.lang.ArityException: Wrong number of args (3) passed to: clojure.core.async.impl.ioc-macros/put!
besides the fact that I dont have any put! <! >! with 3 arity!

phronmophobic18:09:00

you can use clojure.walk/macroexpand-all to see what code might be producing that problem

amirali19:09:44

Thank you! but well its a huge project, How should i use it? @U7RJTCH6J

phronmophobic19:09:49

where did all this code come from?

phronmophobic19:09:46

i was thinking you would have some narrowed down portion of the code that you could macroexpand, and examine all the put! calls

alexmiller19:09:09

is this clojure or clojurescript?

alexmiller19:09:22

and which version of core.async?

amirali11:09:36

I checked every async command in the code and no problem than i can find.

amirali11:09:55

Found out! The guy used <! instead of >! this caused the error

xceno21:09:11

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