Fork me on GitHub
#beginners
<
2018-06-18
>
drewverlee01:06:16

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

seancorfield02:06:37

@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.

seancorfield02:06:45

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.

marlenefdez13:06:24

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?

mfikes13:06:47

@marlenefdez You’d 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))

🎯 1
mfikes13:06:02

I suppose you could also use dotimes

(dotimes [i (count "letters")] (println (.charAt "letters" i)))
but that seems a little odd, FWIW.

dpsutton13:06:03

@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.

mg14:06:18

@marlenefdez you can also map over a string

chris_18:06:05

I’m 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’t seem to import it in the REPL.

chris_18:06:04

e.g. I want to import the ClarifaiBuilder class as seen in https://github.com/Clarifai/clarifai-java#getting-started

lilactown18:06:04

@chris_ just checking: did you restart your REPL?

chris_18:06:22

Yes @lilactown

chris_18:06:51

Perhaps I’m getting the Java package name wrong?

chris_18:06:38

e.g. (import com.clarifai.clarifai-api2.ClarifaiBuilder) doesn’t work

chris_18:06:50

nor does (import com.clarifai.clarifai-api2.core.ClarifaiBuilder)

chris_18:06:57

this worked: (import clarifai2.api.ClarifaiBuilder)

mg18:06:07

beat me to it 😄

chris_18:06:15

danke mg 🙂

mg18:06:42

can’t always assume that the organization in a dependency atom is in the package path the same way

👍 1
Karol Wójcik18:06:02

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?

noisesmith18:06:06

Depending on what kind of thing it is, you can access it with Class/forName or some sort of reflective access.

Karol Wójcik18:06:30

ok but what with cljs?

noisesmith18:06:04

it's much simpler in cljs, you can use js/foo instead of foo for anything globally accessible

noisesmith18:06:28

since js actually has a global scope used for arbitrary values

Karol Wójcik18:06:09

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]

noisesmith18:06:54

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)

noisesmith18:06:58

goog comes with cljs

Karol Wójcik18:06:45

Thank you very much 🙂

justinlee19:06:42

is there any benefit to doing that instead of just (get jsobj key)

noisesmith19:06:56

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

noisesmith19:06:32

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

justinlee20:06:16

oh interesting. seems like it should just emit the right code. maybe it can’t figure it out.

justinlee20:06:38

i think aget will always work in javascript. i thought the issue is that there was some interesting in doing some runtime type checking

justinlee20:06:36

i do wish the doc string was a bit more specific about get’s acceptable usages

noisesmith20:06:58

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

noisesmith20:06:15

but I don't think that's a good justification for using aget on objects in new code

noisesmith20:06:46

and yes, the most pragmatic difference is that you can get better error messages in some cases (I forget the particulars at the moment)

justinlee20:06:00

actually, did get work for you? I forgot that the reason it works for me is that i implemented ILookup on object

justinlee20:06:06

it really shouldn’t work

justinlee20:06:17

oh no it didn’t work for you. i misread your initial response

chris_19:06:21

I’m having difficulty accessing a method of a class. I’m 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 "[email protected]"]
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’s exactly where I’m 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’s going wrong? Any pointers?

mg19:06:13

@chris_ what’s my-input?

chris_19:06:44

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_19:06:40

A ClarifaiInput object is what PredictRequest’s withInputs method expects.

mg19:06:05

@chris_ try wrapping that in a vector. According to the source link, that method takes either ClarifaiInput... which in clojure java interop means you’d need to supply an array, or Collection<ClarifaiInput> which is nice of it, because that means you can wrap it in a generic collection

❤️ 1
💯 1
💖 1
chris_19:06:29

:heavy_exclamation_mark:

mg19:06:25

the ... is a nice bit of Java syntax that, unfortunately, doesn’t translate as nicely into interop

chris_19:06:49

Okay, yes; I definitely missed what that means in Java

chris_19:06:57

thanks again @michael.gaare

👍 1
ScArcher21:06:28

does anyone know how to build a minified clojurescript app with lein?

ScArcher21:06:42

I can't seem to find the right switches to flip to make it do what I want it to do.