Fork me on GitHub
#clojurescript
<
2016-02-21
>
tianshu13:02:42

Finally, find home:heart:

lsenta16:02:50

Hi guys, I need a hand, I renamed my root package in cljs and the compiler tells me:

clojure.lang.ExceptionInfo: failed compiling file:src-cljs/frontend/handlers.cljs
...
Caused by: java.lang.Exception: No namespace: frontend.utils found

lsenta16:02:23

I (:require-macros [frontend.utils :refer [x y]]) in the handler.cljs

mfikes16:02:46

@lsenta: If nothing else, do a clean

lsenta16:02:23

@mfikes, thanks I tried that already, went nuclear with lein clean then rm every possible compiled file

mfikes16:02:41

@lsenta: Are you missing a : as in :require-macros?

lsenta16:02:41

I may have a problem with macros

lsenta16:02:55

Woops, nope, I written too fast

lsenta16:02:45

So how does it works with macro, I'm using clojurescript 1.7.145

mfikes16:02:01

@lsenta: Well, the classpath is used to find code

lsenta16:02:02

Do I need to name my files containing macros cljs or clj ?

lsenta16:02:42

OK, I got that wrong already, long time without clojur'ing, I forgot these tiny details

lsenta16:02:58

My next issue is, the utils contains macros around the async library

lsenta16:02:34

utils.clj require is:

(ns frontend.utils
  (:require-macros
    [cljs.core.async.macros :refer [go]])
  (:require
    [cljs.core.async :refer [<!]]))

mfikes16:02:07

@lsenta: If that is a .clj file, you can’t do :require-macros in it.

lsenta16:02:30

Yea, so I merged everything in :require, but now I get:

Caused by: java.io.FileNotFoundException: Could not locate cljs/core/async__init.class or cljs/core/async.clj on classpath.
 

lsenta16:02:01

Do I import the clojure async lib to write a macro for cljs?

mfikes16:02:44

@lsenta: You are going down a path (using core.async from within macros that I have no experience with). Perhaps you simply need to ensure that the Clojure version of core.async is also on your classpath

lsenta16:02:31

@mfikes, my project.clj contains the dep [org.clojure/core.async "0.2.371"]

mfikes16:02:25

@lsenta: It is interesting that it is mixing cljs and clj in those paths.

lsenta16:02:36

Yea I'm kinda lost

lsenta16:02:51

To summarize: I want to write a clojurescript macro that uses core async

mfikes16:02:04

You are referring to the cljs package in your clj require

lsenta16:02:26

Hence my question, shall I use the clojure macro? That sounds weird

mfikes16:02:29

It is clojure.core.async from Clojure. simple_smile

lsenta16:02:12

Caused by: java.io.FileNotFoundException: Could not locate clojure/core/async/macros__init.class or clojure/core/async/macros.clj on classpath.
😞

mfikes16:02:47

@lsenta: You might be OK, so long as the result of the macro expansion yields stuff that ends up being useful from ClojureScript. That’s the interesting twist.

lsenta16:02:20

Yea that's what is bothering me, I doubt the expansion of cljs.async is the same than the clojure.async

mfikes16:02:54

@lsenta: What does your require look like? It is telling you the truth. There is no such namespace as clojure.core.async.macros. Maybe that’s it

mfikes16:02:22

In other words, in the Clojure version of core.async the macros are right in the clojure.core.async namespace.

mfikes16:02:35

@lsenta: Depending on what you are really trying to do, I think I’d consider macros that themselves don’t directly refer to Clojure core.async, but expand to forms that refer to ClojureScript core.async, which are then further expanded, etc., if that makes sense.

lsenta16:02:55

So you mean having my macros generate fully qualified names instead of importing?

lsenta16:02:24

Something like

(defmacro yolo [x] `(cljs.core.async.macros/go (println x))

nberger17:02:52

@lsenta Yes, that's what happening. I think the way to go is to use fully qualified named but with quote-unquote, like in ~'cljs.core.async.macros/go

nberger17:02:59

And then, you should do the :require-macros of clj.core.async... macros in the namespaces where you use the macro (instead of in frontend.utils)

lsenta17:02:29

@mfikes @nberger It works, thanks a lot for the help guys, I owe you a load of debugging hours!

jasonjckn17:02:56

is there a way for emacs eval of clojurescript to actually show me exceptions in a buffer, like how it does with clojure

jasonjckn17:02:15

when I write bad code, and do C-x C-e, the error shows up in the repl buffer

jasonjckn17:02:23

as oppose to creating a new emacs buffer popup

jamesmintram18:02:40

I am running a ClojureScript REPL using Cursive + Figwheel. I have Def’d some data in a module, and when I print it - it appears as expected, but prefixed is the following warning:

WARNING: Use of undeclared Var hello-app.core/test-data at line 1 <cljs repl>
What is the reason for this? Is it something I should worry about?

jrheard18:02:52

could you paste your code in a pastebin/gist/whatever?

jrheard18:02:09

usually indicates that you've got a line of code that refers to a variable called test-data that is not actually defined

jrheard18:02:22

what's your figwheel repl prompt look like?

jrheard18:02:55

does it say hello-app.core? or does it say cljs.user?

jrheard18:02:24

if the latter, try tools -> repl -> switch repl NS to current file

jrheard18:02:32

i have this bound to cmd-shift-n but there isn't a binding for it by default

jamesmintram18:02:11

This is my REPL

jamesmintram18:02:15

hello-app.core=> test-data
WARNING: Use of undeclared Var hello-app.core/test-data at line 1 <cljs repl>
{:list/items [{:ID 1, :userDescription "A test item"}]}
hello-app.core=> 

jrheard18:02:00

hrm dang - sorry, gotta run 😞 glgl

mfikes19:02:00

@jamesmintram: that can occur if your REPL isn't aware of the var, but it has actually been initialized in your JavaScript engine

mfikes19:02:09

@jamesmintram: :analyze-path deals with one use case surrounding this. I've written a post with some exposition on it: http://blog.fikesfarm.com/posts/2015-06-10-analyze-path-ftw.html

jamesmintram19:02:28

Hi @mfikes that looks exactly like the problem I had! (In the end I did a clean and rebooted the Repl)

jamesmintram19:02:34

@mfikes Would you know how to use this with figwheel? My current repl.cljs file looks like this.

(use 'figwheel-sidecar.repl-api)
(start-figwheel!) ;; <-- fetches configuration 
(cljs-repl)

mfikes19:02:21

@jamesmintram: No. All I can say is :analyze-path is a standard REPL option: https://github.com/clojure/clojurescript/wiki/REPL-Options

jamesmintram19:02:45

OK - thanks for your help. I will go and take a look simple_smile

kingoftheknoll21:02:43

I'm formatting url templates retrieved from a python flask server formatted like "/path/<arg1>/<arg2>/etc" and I'm replacing <args> supplied from a vector. My old js implementation splits, loops, replaces and shifts vector until empty and then joins. Is there a more idiomatic Clojure approach?

jrheard22:02:40

am i doing something wrong here? trying to do (:require [goog.events.KeyCodes :as key-codes]) in my ns form, but key-codes ends up being undefined in my program

maria23:02:29

@jrheard: You need to use :import instead. Here is a really good explanation of when to use which http://clojurescriptmadeeasy.com/blog/when-do-i-use-require-vs-import.html

jrheard23:02:35

thanks so much!

jrheard23:02:40

hm, weird - had to refresh my browser tab before my figwheel REPL picked up the imported KeyCodes symbol, but now i can access eg KeyCodes.DOWN. great!