Fork me on GitHub
#clojure
<
2017-05-15
>
qqq04:05:31

;;    import static jcuda.jcublas.JCublas2.cublasCreate;
;;    import static jcuda.jcublas.JCublas2.cublasDestroy;
;;    import static jcuda.jcublas.JCublas2.cublasSgemv;
Is there a way to import this in clojure so I can refer to cublasCreate, cublasDestroy, cublasSgemv, or is the bedst I can do merely
`
(:import [jcuda.jcublas JCublas2])
and then refer to the functions as JCublas2/cublasCreate, JCublas2/cublasDestroy, etc .... ?

tstirrat04:05:21

@noisesmith the use case in this case was to translate individual characters of the string a la DNA/RNA transcription. Are there better ways to do that?

noisesmith05:05:32

tstirrat: if you are treating it as a sequence and using sequence logic (eg. analyzing repeated sequences or doing statistical measure etc.) then it makes sense to convert to a sequence. I was more intending to warn against using eg map where clojure.string/replace with a regex argument would suffice

tstirrat15:05:02

makes sense. thanks!

matan05:05:27

A word of perspective about the language, after some busy weeks with clojure: I wonder why it isn't called/touted a functional-OO language. Much of the stuff cannot be done without using objects such as with defrecord, defprotocol and related lean object parts of the developer programming interface. I now treat it as object functional hybrid. It's not your grandfather's OO object orientation, but much of the programming interface is about object facades, objects carrying data with some semi-specialized ways of treating the data they have. The pure functional stuff is only 70% I would say.

matan05:05:51

Maybe not object oriented, but being a language providing object and protocol abstractions, those are a critical parts of the usage as I see it.

john06:05:47

Depends how you use it. I rarely ever use protocols/defrecords/deftypes

john06:05:12

But I rarely need to focus on performance

john06:05:50

I believe they're mostly a necessity to leverage good performance on host platforms built on object systems.

john06:05:18

One could imagine a host platform optimized for plain clojure data structures though

john06:05:33

well, I suppose you're right about the facade thing...

john06:05:33

Sometimes you want to make a derefable thing and method overrides are usually seen as object oriented kind of thing, right?

noisesmith06:05:41

but we don't do concrete inheritence so much, it's more about parametric polymorphism rather than method overrides

john06:05:07

Multimethods were around first, which are strictly more powerful than objects. But the defrecord/type/protocol stuff sits right on the host's object system, for performance

john06:05:25

I mean, more powerful than type dispatch

iku00088806:05:42

Has anyone ever tried uploading a downloaded pdf elsewhere programmatically in the browser? I am experiencing the uploaded pdf being corrupted (page layout there, but content gone) but not sure why.

iku00088806:05:00

I am currently storing the pdf data into a blob and then handing the blob to a formData object which then I am POSTing with cljs-ajax

noisesmith06:05:26

my first guess is some step using a data reading function meant for strings

iku00088806:05:43

Could you give me some places to poke around?

noisesmith06:05:18

eg. - if someone calls slurp on the bytes coming in

noisesmith06:05:45

what does the back end handler for the data look like?

iku00088806:05:58

the one that fetches the pdf?

john06:05:08

Is this in CLJS?

noisesmith06:05:40

@iku000888 you mention POSTing the pdf, what is the code that handles that POST request?

iku00088806:05:10

(POST url
          {:body form-data
           :headers {"X-Requested-With" "XMLHttpRequest"}
           :handler handler
           :error-handler #(js/alert "file upload failed") })

iku00088806:05:18

Will be several parts...

noisesmith06:05:59

I meant on the other end, the one that consumes it on the server

iku00088806:05:34

server is out of reach for this project

john06:05:41

my money is on formData

iku00088806:05:46

@john Yes it is cljs

iku00088806:05:07

(doto (js/FormData.)
                    (.append "__REQUEST_TOKEN__" (get-request-token))
                    (.append "file" blob-obj file-name))

iku00088806:05:16

formData looks like this

iku00088806:05:46

get-request-token returns a string, file-name is a string

john06:05:21

I don't know 😕

iku00088806:05:36

the blob-obj is constructed with (js/Blob. #js [<response from the get request>] #js {:type "application/pdf"})

john06:05:01

I suppose you can't just send the pure byte stream, because you have to use the post methods available on the server?

john06:05:38

I'd try to avoid converting the data at all

iku00088806:05:12

I think looking for potential data conversions happening is a good start though

john06:05:41

I just brought up formData because I remember seeing something about XML and formData in the past

iku00088806:05:50

So back tracking, there is a html form that when click redirects me to the pdf in question

iku00088806:05:00

that pdf is good

iku00088806:05:46

When I try to hit the same endpoint with cljs-ajax and do something with the stream things get weird

iku00088806:05:36

Spitting out the problem gave me few ideas, so thanks for now

iku00088806:05:46

Good to know there is always somebody here 🙂

john06:05:37

how do you know the form is blank when it gets to the server? Have you tried dumping the pdf to disk from the browser? Using a save dialogue or something?

john06:05:57

Are you sure there isn't a redirect sitting behind that click?

john06:05:16

some pdf sites will try to use tricks to prevent downloads

john06:05:07

I'm taking a break from an impossible bug right now too 🙂

iku00088806:05:21

Good idea 🙂

iku00088806:05:30

Thanks though.

iku00088806:05:45

(And darn I thought I was writing to the cljs channel. Sorry...)

chrisetheridge06:05:01

do multimethods have any delay when they are being registered? we have a strange problem in our web app, where an implementation of a multimethod is taking long to be registered

noisesmith06:05:09

it should only take as long as it takes to modify a var... because that's all it does

noisesmith06:05:34

are you sure the namespace defining the method is getting required at startup?

noisesmith06:05:28

one thing to watch out for is that defmulti is implicitly defonce - if you edit the definition you need to blow the original away, just reloading the code won't change it

noisesmith06:05:42

anyway, it's late here, I'm turning in 👋

lincpa07:05:17

@matan Clojure is an object-based functional programming language, such as VB is an object-based procedural programming language. They all take advantage of the simple and practical part of the Object-Oriented, discarding the complex and bad parts. You need to try to change the programming methodology, I wrote a pure Clojure personal project(40+k lines). My code base has nearly 100k lines of Clojure, Clojurescript, clojureclr. Never used 'defrecord', 'defprotocol', 'deftype', 'proxy', 'reify'. The two kinds of data structures are mainly used in Hash-map and vector. I constructed the system, is the use of dataflow and logicflow separation method, simply said, is as much as possible to use the threading macro, the more the better. 90% functions in my project is made up of the threading macro block.

mobileink19:05:00

lincpa: whoa nelly! in no way is clojure "object-based"! datum != (OO) object.

lincpa00:05:18

@mobileink I agree that Clojure is data-oriented, but Clojure is based on the JVM, and the JVM is object-oriented, and objects are ubiquitous, so that Clojure is Object-based.

lincpa00:05:33

@mobileink Clojure is Object-based. So clojure can make full use of the existing achievements and facilities of OO

mobileink01:05:42

Clojure is not “based on” the JVM.

tbaldridge02:05:03

And if someone attempts to do OOP in Clojure they're gonna have a bad time

lincpa07:05:15

@U07TDTQNL I agree with your point of view.

lincpa07:05:26

I've never used OOP technology on Clojure, just using object on the JVM and the Java library.

lincpa07:05:26

@mobileink Don't you use any object in Clojure? It's impossible.

tbaldridge13:05:49

I have to disagree as well with the bit about -> that's just a tool to help readability. It's not something I would base my entire programming structure around. Infact for very short bits of code, I find -> does more harm than good.

mobileink13:05:22

No, I don’t use objects, and neither does anybody else. The JVM is a host environment, whether it is OO is not relevant. Of course you are free to call Clojure data “objects”, but that just confuses things. And it would be very misleading to tell newcomers that Clojure is Object-Oriented or “object-based”.

lincpa07:05:39

Maybe because I never wrote Java 🙂

qqq07:05:55

If I'm translating Java code to Clojure, does Java classes become clojure defrecords ?

lincpa07:05:31

hash-map + function

lincpa07:05:51

Let a lot of functions revolve around a data structure. Write functions as data changes.

lincpa07:05:35

First define the data change process, then write a threading macro

lincpa07:05:10

translating Java code to Clojure, Don't maintain the original system construction method, which is unreasonable.

lincpa08:05:37

Clojure is an Object-based + State-Oriented FP (Lisp)

iku00088808:05:04

@john @noisesmith Just wanted to drop a thanks. It ended up being I had to specify a response format to write the response as a byte array when downloading, and everything is good now 🙂

matan09:05:09

@lincpa I would LOVE seeing that code base, if it is in the open domain. It might provide the other half to my question.

qqq11:05:45

I look at https://github.com/mikera/core.matrix and I see clojure vectors.

qqq11:05:57

How can this possibly be fast if it's using clojure vectors instead of native java vectors?

mccraigmccraig11:05:36

is it not copying over to LAPACK anyway @qqq- a linear copy op probably doesn't figure much in the overall complexity

lincpa11:05:57

@matan My code base is private, but my project can be downloaded on the homepage. The current release version is based on Clojureclr+pgsql+sqlce, and the current developing version is based on Clojure+luminus+R+pgsql. My homepage: https://github.com/linpengcheng/fa

chrisblom11:05:30

what clojure book would you recommend for beginners?

mikahanninen11:05:46

Web development with Clojure by Sotnikov seems to be a good book

lincpa12:05:08

《Clojure Programming》is a good book.

val_waeselynck12:05:11

@chrisblom my favourite was "Programming Clojure", followed by "Web Development for Clojure"

michaellindon12:05:43

I liked clojure for the brave :)

michaellindon12:05:54

The clojure koans are good too

michaellindon12:05:10

Does anybody know of any branch and bound software available to clojure or java?

michaellindon12:05:20

I have an optimization problem I need it for

chrisblom13:05:31

cool, thanks for the suggestions

Alex Miller (Clojure team)14:05:53

@val_waeselynck @chrisblom “Programming Clojure” 3rd edition, updated for Clojure 1.9, will be available in beta form in the next month or so (I’m working on this)

john18:05:13

alexmiller: This book taught me lisp. Still the best introduction to Clojure IMO

borkdude14:05:27

Has anyone used direct linking (https://github.com/clojure/clojure/blob/master/changes.md#11-direct-linking) and really noticed any performance gains?

borkdude14:05:14

Also are there any catches when you turn this on in production, e.g. code that explicitly uses var to get a function, will still work?

borkdude14:05:08

@alexmiller That’s great news 🙂

borkdude14:05:14

That was the first book about Clojure I read, in the Christmas holiday of 2009

jcromartie15:05:41

I'm having a lot of trouble using a JDBC url with username and password embedded in them

jcromartie15:05:50

this is a PAAS type of environment where DATABASE_URL is provided

jcromartie15:05:17

not really a Clojure thing, I know... but I wonder if anybody has had any luck with that

hiredman16:05:00

I forget exactly how this shakes out, but an issue I have seen in the past is passwords tend to have characters that need url encoding, and in the past I have had some trouble with whatever was generating the urls not url encoding the passwords, or jdbc not properly url decoding (I forget which)

adamvh16:05:21

question: how do i tell lein run to execute a whole file, rather than a function?

adamvh16:05:11

at the moment, i'm trying to get an example project working, and that project has :main name-of.namespace in its project.clj

adamvh16:05:32

and lein run dies with an error message saying it couldn't find anything to run

adamvh16:05:39

i guess lein exec is what's supposed to solve this problem

devn16:05:51

Do you have a -main defined?

adamvh16:05:14

no, the file in question doesn't have a function named main

adamvh16:05:28

or -main, so i would assume that's why it chokes

devn16:05:55

So you're trying to run it like a script?

adamvh16:05:19

i'm trying to run this project:

adamvh16:05:05

and this project's project.clj contains :main cljs-react-material-ui-example.dev-server, which is a namespace and not a function, so lein run fails

adamvh16:05:35

if i navigate to that file, it looks like something that ought to be run as a script, so the workaround i suppose would be to wrap the contents of that file in a function and change project.clj so that the main key references that function?

adamvh16:05:02

and then perhaps to submit a pull request to that effect as well

adamvh17:05:23

i didn't see it but that's what i came up with, too

adamvh17:05:52

(except i also left a def form out of the -main function but that's neither here nor there)

adamvh17:05:40

however good to see the pull request legwork's already done. thanks, @wiseman !

macrobartfast18:05:28

If I have the following thing: ("foobar") ...

macrobartfast18:05:44

is it fair to call it a list containing one item (a string in this case)?

macrobartfast18:05:04

I am getting the typical dreaded 'java.lang.String cannot be cast to clojure.lang.IFn' when I pass it into another function, but, as this is the result of another function, I'm not sure how to make it a literal with the '

macrobartfast18:05:35

or, how do I get the string out of that form without clojure attempting to evaluate it?

dpsutton18:05:12

super fair to call it that, as that's what it is. can you show an example of your usage?

dpsutton18:05:41

but to make it a literal with ', just prepend the sexp with quote '("won't be evaluated") => (quote ("won't be evaluated"))

macrobartfast18:05:19

well, it's buried in a bunch of code... it's being produced by an Enlive selector... which creates that in a returned map as opposed to just a string...

macrobartfast18:05:56

let me try the quote function ( I think that's what I was looking for ) and if that doesn't work I'll work on getting something more complete up here.

dpsutton18:05:17

what do you mean try the quote function if this is coming from another function?

macrobartfast18:05:37

well, Enlive function is returning something like ({:tag :a, :attrs {:href "/bizbaf", :content ("foobar")} and I have another function looking at the content, I was getting 'java.lang.String cannot be cast to clojure.lang.IFn', but if I pass the content into (quote... it'll not evaluate it...

hiredman18:05:51

I imagine your other function is assuming the contents of the value for the :content key are maps, and trying to invoking the maps as functions

macrobartfast18:05:02

hmm... well, actually, it seems to want just a string...

macrobartfast18:05:23

and so I really just am trying to get the string out of that list...

macrobartfast18:05:30

which has been stumping me.

macrobartfast18:05:16

using quote isn't technically right because it's adding in the opening and closing parens as part of the string

macrobartfast18:05:16

which works for my other function (which is just hunting for strings within that string), but I think getting the string out of the form is probably better, but that's stumped me.

dpsutton18:05:33

you want the first element of a list?

adamvh18:05:50

do you want to return the original data structure but with a plain string in place of ("foobar")?

macrobartfast18:05:40

that would be great, actually.

adamvh18:05:05

you probably want to use update-in then

macrobartfast18:05:37

can you give an example for ({:tag :a, :attrs {:href "/bizbaf", :content ("foobar")} ?

macrobartfast18:05:58

hmmm.... never mind that first paren...

adamvh18:05:03

one together 🙂

macrobartfast18:05:11

{:tag :a, :attrs {:href "/bizbaf", :content ("foobar")}

adamvh18:05:45

putting one together i mean

dpsutton18:05:50

fizzbuzz.core> (update-in {:a 1 :b '("string")} [:b] first )
{:a 1, :b "string"}

adamvh19:05:10

ah he's got it

macrobartfast19:05:26

oh man, this is really helpful, from a learning perspective (as well as getting past this frustrating point!)...

adamvh19:05:21

so update-in is getting :b out of your data structure, and then replacing it with a new data structure where :b will return (first b)

adamvh19:05:04

and also if your maps are nested it will follow a sequence of keys

adamvh19:05:09

that is in the brackets there

adamvh19:05:22

`> (update-in {:a {:b {:c '("string")}}} [:a 😛 :c] first) {:a {:b {:c "string"}}}

adamvh19:05:12

so update-in is kind of your swiss-army knife for turning a big map into the same big map with one little part changed

macrobartfast19:05:17

I had forgotten to use the code button to paste in code... and some of the code turned into emoticons, and then the wi-fi here failed...

macrobartfast19:05:35

a perfect storm.

macrobartfast19:05:41

anyway, sorry for all that.

macrobartfast19:05:53

this all seems right, to clean up my data before passing it into the rest of the functions (and not try to handle in them).

macrobartfast19:05:22

so, the crux of my issue seems to be that my data structure is

macrobartfast19:05:56

where the value for ':b' is not quoted

macrobartfast19:05:42

clojure: code is emoticons, emoticons is code

adamvh19:05:46

that should only be a problem if you are typing in the data structure at a repl

adamvh19:05:01

or like if this datastructure is coming from a macro and then clojure is trying to compile it

adamvh19:05:49

if you are, yourself, writing this data structure in your code you will have to quote ("string")

adamvh19:05:24

if something else is giving you this data structure, clojure shouldn't try to compile it unless in a macro

macrobartfast19:05:32

well, I'm getting a sequence of maps in a vector that is the result of an Enlive function, and the value for the :content key looks like ("foobar"), and then it's throwing that error

adamvh19:05:59

which enlive function is returning this

macrobartfast19:05:50

probably I should take a look at that, to see why I'm getting a value (a webpage element in this case) as a list containing a single string.

macrobartfast19:05:57

that's the root of the problem.

adamvh19:05:29

that seems fine to me, i think the root of the problem is that clojure is trying to evaluate that value

macrobartfast19:05:03

totally. and I'm learning a lot about the 'data is code, code is data' thing right now from you all.

adamvh19:05:07

the value you have seems to me like clojure should not be trying to evaluate it, so that a single-element list should be fine

adamvh19:05:27

however i'm not sure in what context you're getting this value. the big reason clojure would do this is if you are in a macro.

genmeblog19:05:33

question about resources, using lein in project.clj I have :resource-path "resources/" and some xml file inside. (xml/parse (io/file (io/resource "file.xml"))) works perfectly when run from the project

genmeblog19:05:30

but when I pack files into the jar and deploy on clojars with lein deploy clojars, my xml files are in the jar in the top folder

genmeblog19:05:49

calling io/resource causes an exception

b-ryan19:05:17

Are you sure it's io/resource causing the exception and not io/file?

genmeblog19:05:51

io/file, sorry

macrobartfast19:05:55

@adamvh well, I think I need to look at the overall code, and/or come up with a version I can post here for you

b-ryan19:05:26

When you run locally with lein, the "resources" directory is a file on your system (ie. you can do ls resources). But when you pack into a jar, you are no longer dealing with files on the system, the resources are within the jar. So io/file doesn't have an actual file to work with.

adamvh19:05:47

what's, like, one form up from the enlive function call?

b-ryan19:05:41

If the xml/parse function can take a string, you could replace io/file with slurp

genmeblog19:05:18

ok, checking

noisesmith17:05:23

tsulej: b-ryan: most things that can take an instance of File (as io/file returns) can take io/resource directly. If not, (io/input-stream (io/resource …)) will almost always do the trick.

genmeblog17:05:23

thx, will check

nrako19:05:36

I have a small project on clojure 1.9.0-alpha16. Firing up the REPL works fine. I want to dive into clojure.spec a bit, so when I add spec to the ns (i.e. [clojure.spec.alpha :as s]) and reload the REPL, I get an error - CompilerException java.lang.ClassCastException: clojure.spec.alpha$regex_spec_impl$reify__1340 cannot be cast to clojure.lang.IFn. What am I missing here? Would definitely appreciate any help...

hiredman20:05:35

nrako: that looks like an issue that is fixed in newer builds of spec

nrako20:05:23

@hiredman Thanks. alpha16 is not the best build to use?

hiredman20:05:16

as of the latest alphas, spec and clojure are different artifacts and versioned separately

genmeblog20:05:22

@b-ryan unfortunately xml/parse doesn't accept string... but (xml/parse (java.io.ByteArrayInputStream. (.getBytes (slurp (io/resource "file.xml"))))) works

nrako20:05:25

@hiredman Looks like it is working. The last note on the Google groups thread was key. Thank you again...

b-ryan20:05:57

@tsulej If you're using https://github.com/clojure/data.xml it looks like there is also a parse-str function. Or you might be able to use (io/input-stream (io/resource "file.xml")). But good to see you got something working.

etemtezcan20:05:15

@pyroclast-bot Send to CgcyNDM2NjMzEgZnaXRodWI, 591a0573-2ed1-40c1-93dc-2e9f895be2db, topic-c6e4d140-1a91-4323-b288-e0ddd3a62aca

genmeblog20:05:39

@b-ryan I'll take a look, thank you.

qqq22:05:02

(defn draw-text [font s x y]
  (let [bi (BufferedImage. 32 32 BufferedImage/TYPE_BYTE_GRAY)
        g  (.createGraphics bi)
        f2 (.deriveFont font (float 20.0))]
    (.setColor g Color/white)
    (.fillRect g 0 0 32 32)
    (.setColor g Color/black)
  
    
    (.setFont g f2)
    (.drawString g s x y) 
    bi))

(let [f (first (filter #(.canDisplay % \a) all-fonts))
      ans (draw-text f " world" 4 22)]
  (ImageIO/write ans "png" ( "output/test.png"))) 

This should be BLACK text on WHITE background right? For some reason, I get WHITE text on BLACK background.

devn22:05:51

Anyone here using datadog JMX monitoring with a Clojure application?