This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-18
Channels
- # aws-lambda (3)
- # beginners (57)
- # boot (3)
- # bristol-clojurians (1)
- # cider (38)
- # cljs-dev (23)
- # clojure (35)
- # clojure-italy (32)
- # clojure-nl (6)
- # clojure-spec (35)
- # clojure-uk (132)
- # clojurescript (34)
- # cursive (22)
- # data-science (1)
- # datomic (54)
- # devcards (1)
- # duct (5)
- # editors (7)
- # euroclojure (4)
- # fulcro (40)
- # graphql (1)
- # hoplon (6)
- # immutant (5)
- # jobs (1)
- # off-topic (22)
- # om (1)
- # planck (17)
- # portkey (1)
- # protorepl (12)
- # re-frame (97)
- # reagent (67)
- # reitit (16)
- # ring-swagger (1)
- # shadow-cljs (98)
- # spacemacs (8)
- # sql (20)
- # tools-deps (60)
Whats the best way to search for stuff in clojure (ideas, concepts, libs)? I currenty go to https://crossclj.info/ns/statecharts/0.2.2/project.clj.html#outdated. it seems better then google
@drewverlee I don't use CrossClj much -- I've used Bing for all my technical searches for several years and I find everything I need that way. I've seen several people say Bing seems better than Google these days for technical searches.
I think CrossClj is great when you have a library -- or a few choices of library -- and want to see which is more widely used and how it is used.
Hi all, I am attempting to iterate through the chars of a string, and so far I have this: (doseq [i (count "letters")] (.charAt "letters" i))
this is giving me this error: Don't know how to create ISeq from: java.lang.Integ
i'm not exactly sure what to change the doseq
to in order to get the behavior that I need? suggestions?
@marlenefdez You鈥檇 want to use range
in that case
(doseq [i (range (count "letters"))] (println (.charAt "letters" i)))
But you could just seq right over the letters:
(doseq [c "letters"] (println c))
I suppose you could also use dotimes
(dotimes [i (count "letters")] (println (.charAt "letters" i)))
but that seems a little odd, FWIW.@marlenefdez doseq requires a sequence and binds the symbol you provide as each member of that sequence in turn. count
will return a number. so mike here is either using the string as the sequence or getting a same-length sequence of numbers.
@marlenefdez you can also map
over a string
I鈥檓 having difficulty using a 3rd party Java library in Clojure.
I can successfully add [com.clarifai.clarifai-api2/core "2.4.0"]]
to my Lein project.clj
and retrieve it (it shows up in lein deps :tree
), but I can鈥檛 seem to import
it in the REPL.
e.g. I want to import the ClarifaiBuilder
class as seen in https://github.com/Clarifai/clarifai-java#getting-started
can鈥檛 always assume that the organization in a dependency atom is in the package path the same way
Hello I got a question about programatic access to java variables. Supposing that I got (def name-of-java-variable "var1")
how can I access the property of obj
programmatically using name-of-java-variable
?
Depending on what kind of thing it is, you can access it with Class/forName
or some sort of reflective access.
ok but what with cljs?
it's much simpler in cljs, you can use js/foo
instead of foo
for anything globally accessible
since js actually has a global scope used for arbitrary values
yup but what if I got an object like var obj = { prop: 'blabla' }
and a string which is 'prop'. How can I programatically access that property using a string. In plain js I would do
var nameOfProperty = 'prop'
obj[nameOfProperty]
oh, in that case you would use goog.object (or you can use aget - there's code that does this but it has problems that are fixed by using the goog.object library instead)
goog comes with cljs
Thank you very much 馃檪
the fact that it actually works
ljs.user=> (let [m #js{:foo :bar}] (println) (println "get:" (get m "foo")) (println "goog:" (.get js/goog.object m "foo")))
get: nil
goog: :bar
nil
get is a function on clojure hash-maps, not js objects generally. There's a hack where aget
accidentally does the right thing but if you look at the code being emitted and why it works it should be clear that goog.object/get is the better choice
oh interesting. seems like it should just emit the right code. maybe it can鈥檛 figure it out.
i think aget
will always work in javascript. i thought the issue is that there was some interesting in doing some runtime type checking
aget works on js objects that aren't arrays because someone realized it worked, it only worked because of an implementation detail, and now that implementation detail can't be changed because it would break so much code
but I don't think that's a good justification for using aget on objects in new code
and yes, the most pragmatic difference is that you can get better error messages in some cases (I forget the particulars at the moment)
actually, did get
work for you? I forgot that the reason it works for me is that i implemented ILookup
on object
I鈥檓 having difficulty accessing a method of a class. I鈥檓 trying to follow this Getting Started example: https://github.com/Clarifai/clarifai-java#example-requests
(def client (.buildSync (ClarifaiBuilder. clarifai-api-key)))
(def general-model (.generalModel (.getDefaultModels client)))
(import clarifai2.dto.input.ClarifaiInput)
(def my-input (ClarifaiInput/forImage ""))
(.predict general-model)
;;=> #object[clarifai2.api.request.model.PredictRequest 0x6cd93f00 "clarifai2.api.request.model.PredictRequest@6cd93f00"]
PredictRequest
has the public withInputs
method, per the Getting Started docs and source code:
https://github.com/Clarifai/clarifai-java/blob/master/core/src/main/java/clarifai2/api/request/model/PredictRequest.java
But that鈥檚 exactly where I鈥檓 running into trouble:
(.withInputs (.predict general-model) my-input)
java.lang.IllegalArgumentException: No matching method found: withInputs for class clarifai2.api.request.model.PredictRequest
Any idea what鈥檚 going wrong? Any pointers?my-input
;;=> #object[clarifai2.dto.input.AutoValue_ClarifaiInput 0x7359950c "ClarifaiInput{id=null, createdAt=null, inputValue=ClarifaiURLImage{crop=Crop{top=0.0, left=0.0, bottom=1.0, right=1.0}, url=}, _metadata={}, concepts=[], geo=null}"]
@chris_ try wrapping that in a vector. According to the source link, that method takes either ClarifaiInput...
which in clojure java interop means you鈥檇 need to supply an array, or Collection<ClarifaiInput>
which is nice of it, because that means you can wrap it in a generic collection