hashp icon indicating copy to clipboard operation
hashp copied to clipboard

Error from CLJS: Attempting to call unbound fn: #'hashp.core/p*

Open harishtella opened this issue 4 years ago • 8 comments

I'm not sure what I'm doing wrong, but I am working on CLI tools based CLJS project.

I have added hashp {:mvn/version "0.2.0"}} to my deps.edn I imported [hashp.core] to my namespace. And I tried adding #p to a form.

I get the following compile time error Attempting to call unbound fn: #'hashp.core/p*.

I looked at the source for hashp/core.cljs and it looks like p* is not defined in there, but I'm likely misunderstanding how hashp works.

harishtella avatar May 28 '20 20:05 harishtella

Can you provide some information about your setup? How are you "importing" [hashp.core]? Are you using require or require-macros/include-macros? Are you using Shadow-CLJS or something else?

weavejester avatar May 29 '20 18:05 weavejester

I usually use figwheel, but in this case I am just compiling my source with cljs.main

All I did was include the hashp dependency. And then I tried both (:require [hashp.core]) and (:require-macros [hashp.core]) in my cljs file.

No luck with either. For the latter, I get these warnings at compile time.

WARNING: Use of undeclared Var hashp.core/prefix at line 23 /Users/harishtella/Repos/probcomp/inferenceql/spreadsheets/src/inferenceql/spreadsheets/panels/table/events.cljs
WARNING: Use of undeclared Var zprint.core/zprint-str at line 23 /Users/harishtella/Repos/probcomp/inferenceql/spreadsheets/src/inferenceql/spreadsheets/panels/table/events.cljs
WARNING: Use of undeclared Var hashp.core/print-opts at line 23 /Users/harishtella/Repos/probcomp/inferenceql/spreadsheets/src/inferenceql/spreadsheets/panels/table/events.cljs
WARNING: Use of undeclared Var zprint.core/zprint-str at line 23 /Users/harishtella/Repos/probcomp/inferenceql/spreadsheets/src/inferenceql/spreadsheets/panels/table/events.cljs
WARNING: Use of undeclared Var hashp.core/print-opts at line 23 /Users/harishtella/Repos/probcomp/inferenceql/spreadsheets/src/inferenceql/spreadsheets/panels/table/events.cljs

And running a function with #p causes this error. Uncaught ReferenceError: hashp is not defined

harishtella avatar Jun 02 '20 17:06 harishtella

You'll need to provide a little more information. I've just tried out the following file:

(ns hello-world.core
  (:require [hashp.core :include-macros true]))

(defn foo []
  #p "Hello World")

With the following deps.edn:

{:deps {org.clojure/clojurescript {:mvn/version "1.10.758"}
        hashp {:mvn/version "0.2.0"}}}

And the following command:

clj --main cljs.main --compile hello-world.core --repl

And it works fine. If it's failing for you, can you give me some way of reproducing what you're seeing?

weavejester avatar Jun 02 '20 18:06 weavejester

Ok, this works perfectly when I add (:require [hashp.core :include-macros true]) to my namespace like you have done.

I guess I didn't realize the alternative is that I have to add both (:require-macros [hashp.core]) and (:require [hashp.core]). It also works when I do this.

It would be great if I could use #p without requiring it everywhere. It seems that I have to require it in the namespace where I am using it, or it has to be required in one of the namespaces that this namespace requires. Putting the require in some unrelated namespace (even though it is required somewhere else) doesn't seem to do it.

Is this just a current limitation?

harishtella avatar Jun 02 '20 22:06 harishtella

If you use ShadowCLJS and follow the instructions on the README, it's injected automatically. I don't know if Figwheel has the same, but I'm pretty sure that the basic CLJS compiler from tools.deps doesn't.

weavejester avatar Jun 02 '20 22:06 weavejester

Got it. Figwheel does have a preloads option. But sticking in [hashp.core] doesn't seem to do it. I imagine it might work differently than ShadowCLJS.

Anyways thank you for the help. And thank you for creating this. :)

harishtella avatar Jun 03 '20 15:06 harishtella

Made a few attempts at getting preloads working in non-shadow-cljs builds, no luck so far. Making a separate preloads file that does :include-macros didn't help, which is weird as it seems shadow-cljs preloads are similar to plain cljs compiler. Or am I wrong?

I'm interested in finding a solution for this, as having a global "invisible" require makes hashp a much more attractive option.

ingesolvoll avatar Jun 17 '20 12:06 ingesolvoll

@harishtella @ingesolvoll I appear to mostly have this working with Figwheel.main if you add :preloads [hashp.core] to the top level of the map in dev.cljs.edn.

Here is relevant part of my dev profile in project.clj:

  :profiles {:dev {:dependencies [[hashp "0.2.1"]
                                  [com.bhauman/figwheel-main "0.2.14"]
                                  [com.bhauman/rebel-readline-cljs "0.1.4"]]
                   :source-paths ["src_server" "env/dev"]}}

if you add a #p before starting figwheel it won't compile, but if you add one after initial compilation it will recompile and work as expected.

ccann avatar Nov 17 '21 20:11 ccann