This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2015-12-28
Channels
- # admin-announcements (72)
- # aws (23)
- # beginners (43)
- # boot (140)
- # cider (11)
- # cljs-dev (4)
- # cljsrn (82)
- # clojars (2)
- # clojure (215)
- # clojure-nl (2)
- # clojure-russia (149)
- # clojurecup (4)
- # clojurescript (159)
- # cursive (19)
- # datomic (47)
- # editors (1)
- # emacs (27)
- # hoplon (32)
- # jobs (11)
- # ldnclj (3)
- # mount (33)
- # off-topic (1)
- # om (380)
- # onyx (1)
- # re-frame (2)
- # reagent (54)
- # yada (63)
Hi, I’m trying to require cljs.analyzer.api
to use resolve
but am getting errors, is this not possible?
If you really want to use compiler API in clojurescript, you have to compile it to clojurescript, first.
Bootstrapped clojurescript is not a full substitute for clojurescript compiler on JVM.
@crocket: got it, actually was just hoping to turn a key or string into a function and call it at runtime
@mudphone: Evaluating a string into a function creates security vulnerabilities in practice.
When doing lein figwheel
it seems I get
Caused by: java.io.FileNotFoundException: Could not locate cljs/analyzer__init.c
lass or cljs/analyzer.clj on classpath:
@cjmurphy: this nearly always means you haven’t specified a Clojure 1.7.0 dependency explicitly
@cjmurphy: but you also need to be sure nothing is pulling in the wrong dependency, lein deps :tree
I'll do it manually. Wanting to get kanban demo going - seems the most comprehensive Om/Next demo out there...
The boot problem is a serious one too: https://github.com/Jannis/om-next-kanban-demo/issues/1
I've done all the tutorials. Jannis's code looks easy enough to follow - good to see lots of querys at the root level.
Can anyone explain https://github.com/clojure-emacs/cider/issues/1489#issuecomment-167415309 ?
@crocket: understood… actually, I’m not taking the string from the user, just want to use a keyword, turn into a string, and resolve into an already existing function
@mudphone you can use cljs.analyzer/resolve instead, have a look at https://github.com/ScalaConsultants/replumb/blob/master/src/cljs/replumb/repl.cljs#L83
crocket: in go they use values as errors. Also you can define your own error protocol. Maybe it could be helpful
https://github.com/jamesmacaulay/cljs-promises or there is some promises library over core.async @crocket
Since errors are emitted from the same channels as other values, it is inconvenient. Exceptions can't be used, either.
hmm... what about Failure record? I wrote a blog-post about it, but I'm not very experienced with core.async: https://s-mage.github.io/2015/10/16/better-errors.html
Typed Clojure may be a better alternative. Errors are of different types from other values. Something like Either<Error,HttpResponse> is not bad.
Using the regexp from http://stackoverflow.com/a/8317014/385505 in Clojurescript throws "Invalid regular expression flags". Why is that? EDIT: I see, forward slashes don't need to be escaped in Clojurescript.
hi guys, i have this simple function to catch keyboard shortcut, it doesn't seem to work, does anyone spot something wrong ?
(ns something
(:require [goog.events :as events])
(:import [goog.ui KeyboardShortcutHandler]))
;; ...
(let [handler (doto
(KeyboardShortcutHandler. js/document)
(.registerShortcut 'A' 'a'))
triggered-fn (fn [e]
(js/alert (str "Shortcut triggered" (.identifier e))))]
(events/listen handler
js/goog.ui.KeyboardShortcutHandler.EventType.SHORTCUT_TRIGGERED
triggered-fn)
)
@mudphone: why not keep the functions in a map and resolve it that way? Something like:
(let [functions {:keyword (fn [arg] (println "wheee" arg))}
function (functions :keyword)]
(function "test'))
@crocket: as someone mentioned using Maybe
and Either
from cats - http://funcool.github.io/cats/latest/#maybe - could be a good solution.
@crocket: Use the go-catching
and <?
macros from the glossop libraries. They are slight variations of the go
and <!
macros from core.async that catches exceptions.
Their implementation is actually fairly straight forward: https://github.com/nervous-systems/glossop/blob/master/src/glossop/core.cljc
maybe https://github.com/funcool/cats or https://github.com/funcool/octet can serve as example
If you have small number of tests octet approach is much simplier, but if you are expecting have a bunch of namespaces, cats approach is more appropriate
I can't make macroexpand nor macroexpand-1 work in a macro called from CLJS. Does anyone have this problem?
@phil: or you could take a look at this: https://github.com/magomimmo/modern-cljs/blob/master/doc/second-edition/tutorial-15.md
@vibl: https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure#macros
(defmacro test-macroexpand [] `(quote ~(macroexpand-1 '(-> 1 inc)))) returns (-> 1 inc) instead of (inc 1)
@magomimmo: no problem
@vibl: no. You can only macroexpand it. defmacro is still clojure, not clojurescript
A macro declared from the cljs repl with defmacro seems to work (which surprised me) but with an error message: "WARNING: Wrong number of args (0) passed to cljs.user/bla at line 1 <cljs repl>"
@magomimmo try it, you'll be surprised.
@magomimmo: maybe it's a feature preview
@vibl: people are already abusing defmacro….imagine what could happen if they make it available in cljs as well
it’s a minor issue that it doesn’t just throw an error, someone can submit a patch for that if they like
@dnolen On an unrelated subject: I can't make macroexpand and macroexpand-1 work within a clj macro called from cljs.
@dnolen: in a clj file, there is (defmacro test-macroexpand []
(quote ~(macroexpand-1 '(-> 1 inc))))`
the best documentation maybe is the source code organization of the existing open source applications
@richiardiandrea: Thanks, that gets me closer, I’m still seeing some odd errors, mostly because I probably have to dig into this source. Here’s my first attempt in case you’re interested:
(ana/resolve-var (empty-analyzer-env) (symbol "+") ana/confirm-var-exist-warning)
#object[Error Error: No protocol method IDeref.-deref defined for type null: ]
@jaen: Thanks that would work. I’m using a multimethod now, I think someone here recommended. I was really just trying to see if I could get clever and only have to specify the fn names twice, instead of three times.
But basically you can't select a function by string at runtime in Clojurescript, so you have to get creative.
@jaen, I guess I could pull all the fns from an ns and put them into a map, where I turn the fn names into keys?
You could do either write it out manually or write a macro using the analyser I suppose.
http://pastie.org/10657931 How could I resolve this keyword in cljs? It looks like clojure’s #resolve would work, but that’s not available
HI, should (extend-protocol IDoThing number (do-thing [this] ...))
work in clojurescript?
I get the error: #object[TypeError TypeError: Cannot read property 'do_thing' of undefined]
@heeton: What are you trying to do exactly?
@spelufo: Don’t you want capital N number?
no, that throws another error, and I've seen lowercase number used in the clojurescript and garden's source code.
@christopherbui: trying to create a router. I have a bunch of pages defined and want to be able to transition, the result of my function being a reference, not the value
And stepping through the extend-protocol form in the chrome devtools it skips that type when going through the list.
@jaen I'm not sure about resolve
, one month ago I have tried to something that requires resolve and I found that cljs does not provide it :S
I have asked some questions in the mailing list... but I don't found any solution at this moment
I'm having trouble with goog.string.format
being recognised as a function. Could there be something obvious I'm doing wrong?
@heeton, @niwinz: I'm talking about https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/analyzer/api.clj#L141-L150
@jaen this is the question that I have asked some time ago https://groups.google.com/d/msg/clojure/DTjqWKQx3Sc/xBWX3WBBCAAJ
@spelufo: Are you sure? I tried this out in the cljs repl and it works
cljs.user=> (defprotocol IDoThing (do-thing [this]))
nil
cljs.user=> (extend-protocol IDoThing js/Number (do-thing [this] 1))
#object[Function "function (this$){
var this$__$1 = this;
return 1;
}"]
cljs.user=> (do-thing 23)
1
cljs.user=>
@niwinz: hopefully it will be helpful; I didn't have need to try that out yet, but from what I understand it should work.
I don't think format
is a macro. I just require it like: [goog.string :refer [format]]
, and call it the way you might call any function. But Cursive and then running figwheel/devcards - so both at code writing and code running times - do not think it is a function. I don't believe there is anything special I need to do in the project.clj file.
hello If you have a minute, I've posted a question about following the QuickStart guide in getting a node REPL in the google group: https://groups.google.com/forum/#!topic/clojure/pf2GuFVtiAw Basically when I try to build with the prescribed node.clj, it can't find a dependency
I've stopped on the exeption in the devtoold and the line that is making trouble is my-ns.core.my-ns.core.do_thing[goog.typeOf(3)]
. Don't know how it got to that, but clearly it should be my-ns.core.do_thing[goog.typeOf(3)]
, the problem is that the namespace gets duplicated somehow.
I had a (def sth ...)
in a namespace '(ns sth.core)', and when I changed it to (def sth-else ...)
the duplicate sth.core.sth.core
turned into sth.core
.