Fork me on GitHub
#clojure-spec
<
2019-05-24
>
Jakub Holý (HolyJak)06:05:04

Does anybody have any idea why might I be getting the error > Syntax error macroexpanding clojure.core/defn at (alpha.clj:78:1). > #object[clojure.spec.alpha$and_spec_impl$reify__2183 0x1698fc68 "clojure.spec.alpha$and_spec_impl$reify__2183@1698fc68"] is not a fn, expected predicate fn when trying to start a REPL in the spec.alpha project and loading the code? I did this:

$ git clone  # sha 5228bb75fa10
$ cd spec.alpha
$ clj
Clojure 1.10.0
user=> user=> (load-file "src/main/clojure/clojure/spec/alpha.clj")
Syntax error macroexpanding clojure.core/defn at (alpha.clj:78:1).
#object[clojure.spec.alpha$and_spec_impl$reify__2183 0x1698fc68 "clojure.spec.alpha$and_spec_impl$reify__2183@1698fc68"] is not a fn, expected predicate fn
$ java -version
java version "1.8.0_192" # running on OSX

4
Alex Miller (Clojure team)07:05:02

spec is aot compiled, might be a conflict since you are forcing a load of the clj, which recompiles the protocol (yet all the old instances are from the prior protocol). should probably use load instead?

Jakub Holý (HolyJak)07:05:08

Ah, OK, thank you, that helped! I am used to load-file and do not really know how it works, I guess I should learn 🙂

seancorfield17:05:27

@U0522TWDA I'm curious how you got into the habit of using load-file in the first place? It seems like require would be the "obvious" thing to learn first...

Jakub Holý (HolyJak)17:05:00

Perhaps a bad habit from Node.js where require is idempotent and does not actually reload the code from the disk. Also, I see that Cursive's "load file in repl" used to reload the code actually calls load-file, at least when running REPL via main (instead of via lein)

Jakub Holý (HolyJak)17:05:50

Ah, no, Clojure require does not reload the code either > Loads libs, skipping any that are already loaded. So what are you saying? That the 1st time I should use require but after I change the code, to get the changes in, then I should use what?

Jakub Holý (HolyJak)17:05:09

(I guess I will get the answer after I finish Eric's REPL course)

seancorfield17:05:09

(require ... :reload) or (require ... :reload-all)

👍 4
Jakub Holý (HolyJak)17:05:28

Also, require requires that the code is on the classpath while load-file does not care about that. But I guess that is not a problem if I only use lein repl in lein project and clj in deps.edn projects as those have the correct paths autom.

seancorfield17:05:59

I think editors are likely to use load-file since they have a filesystem path, rather than a namespace -- but I view load-file as a tooling/system-level hook. Always interesting to hear how other folks developed their Clojure habits...

👍 4