Fork me on GitHub
#clojurescript
<
2021-06-07
>
sansarip01:06:51

Hello, fine people! I get errors when trying to eval a custom macro in cljs, but the macro works just fine otherwise in cljs. And when I say "custom macro", I simply mean one that I've defined.

(ns peanuts.editor
  (:require [cljs.js :refer [empty-state eval-str js-eval]]))

(defn evaluate 
 [s cb]
 (eval-str
   (empty-state)
   (str "(do " s ")")
   nil
   {:eval       js-eval
    :source-map true
    :context    :expr}
   cb))

=> (evaluate "(require-macros '[peanuts.core :refer [defnc]]) (defnc foo [a] a) (foo 1)" println)

{:error #error {:message ERROR, :data {:tag :cljs/analysis-error}, :cause #object[TypeError TypeError: cljs.user.defnc is undefined]}}
nil
I even tried setting the :ns option on eval-str to 'peanuts.core and then trying to evaluate defnc without the require, but that yielded another error:
=> (evaluate "(defnc foo [a] a) (foo 1)" println)
{:error #error {:message ERROR, :data {:tag :cljs/analysis-error}, :cause #object[SyntaxError SyntaxError: expected expression, got '.']}}
nil
Is there a way to eval custom macros in cljs simple_smile ?

Oliver George02:06:31

Hi Guys, quick cross-promotion. I've started a #show-and-tell channel. Share a screenshot and tell us about it. So far we've seen some interesting developer setups and side projects. Today I've shared a facilitaties management solution we developed using, among other things, #re-frame & #cljsrn.

👍 7
Oliver George02:06:36

And if broad-scope facilities management solutions don't inspire you... well, I can't imagine what will.

Jacob Rosenzweig04:06:46

Any idea why I get this error when I attempt to start a shadow-cljs project I generated?

PS C:\Users\Jacob\clojure\my-app> shadow-cljs watch app
shadow-cljs - config: C:\Users\Jacob\clojure\my-app\shadow-cljs.edn
shadow-cljs - starting via "clojure"
clojure : The term 'clojure' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ clojure -m shadow.cljs.devtools.cli --npm watch app
+ ~~~~~~~

thheller06:06:53

looks like the template uses deps.edn to manage dependencies but you do not have tools.deps installed?

thheller07:06:22

(or just use :dependencies and :source-paths in shadow-cljs.edn and remove :deps)

Jacob Rosenzweig04:06:20

I'm using this npm package for context. https://github.com/jgoodhcg/create-expo-cljs-app I think what is happening is that the new :deps option leads to code trying to launch a clojure repl using the keyword "Clojure"

Jacob Rosenzweig04:06:43

Also, could anyone tell me what the :> operator is in hiccup? E.g.

[:> rn/View ]

rossputin16:06:27

hi - can anyone point me to an example integrating Aero into a clojurescript project? Thanks!

sova-soars-the-sora16:06:29

What's aero and what does it do? looks like a lot of different things to give a live coding experience but i'm not sure what it does

p-himik16:06:29

It's probably https://github.com/juxt/aero, just a config library. @UV23GRRR7 What exactly do you expect to get from it in a CLJS app? What do you mean by "integrate" here?

rossputin16:06:15

I was wondering if there is any way my clojurescript app (in a mono repository) can share some config I use in the clojure backend

rossputin16:06:40

not precious about it being Aero - just thought it looked like a pretty good way to do things on the Clojure side

p-himik16:06:07

You can read that config in a CLJ macro and embed as data in a CLJS script.

rossputin16:06:17

thanks for the pointer

sansarip22:06:12

Anyone know if it’s possible to eval-str referred macros in Cljs? I’m having trouble doing so. e.g.

(eval-str
     (empty-state)
     "(require-macros '[some-library :refer [some-macro]]) (some-macro)"
     nil
     {:eval       js-eval
      :source-map true
      :context    :expr}
     println) 

thheller22:06:37

depends on the library and the macro. not all macros are automatically self-host compatible.

👍 2