This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-05-15
Channels
- # beginners (34)
- # boot (45)
- # cider (16)
- # cljs-dev (20)
- # cljsjs (1)
- # cljsrn (8)
- # clojure (207)
- # clojure-berlin (3)
- # clojure-dev (18)
- # clojure-greece (1)
- # clojure-ireland (1)
- # clojure-italy (9)
- # clojure-russia (20)
- # clojure-spec (27)
- # clojure-uk (19)
- # clojurescript (110)
- # code-reviews (2)
- # cursive (7)
- # data-science (2)
- # datomic (7)
- # devcards (1)
- # emacs (4)
- # graphql (1)
- # hoplon (2)
- # immutant (15)
- # jobs (5)
- # jobs-rus (1)
- # juxt (1)
- # luminus (7)
- # lumo (26)
- # microservices (3)
- # off-topic (27)
- # om (13)
- # onyx (11)
- # pedestal (7)
- # proton (4)
- # re-frame (24)
- # remote-jobs (1)
- # spacemacs (2)
- # specter (2)
- # unrepl (31)
- # untangled (7)
- # vim (14)
;; 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 .... ?@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?
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
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.
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.
I believe they're mostly a necessity to leverage good performance on host platforms built on object systems.
Sometimes you want to make a derefable thing and method overrides are usually seen as object oriented kind of thing, right?
but we don't do concrete inheritence so much, it's more about parametric polymorphism rather than method overrides
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
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.
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
my first guess is some step using a data reading function meant for strings
eg. - if someone calls slurp on the bytes coming in
what does the back end handler for the data look like?
@iku000888 you mention POSTing the pdf, what is the code that handles that POST request?
(POST url
{:body form-data
:headers {"X-Requested-With" "XMLHttpRequest"}
:handler handler
:error-handler #(js/alert "file upload failed") })
I meant on the other end, the one that consumes it on the server
(doto (js/FormData.)
(.append "__REQUEST_TOKEN__" (get-request-token))
(.append "file" blob-obj file-name))
the blob-obj is constructed with (js/Blob. #js [<response from the get request>] #js {:type "application/pdf"})
I suppose you can't just send the pure byte stream, because you have to use the post methods available on the server?
I just brought up formData because I remember seeing something about XML and formData in the past
So back tracking, there is a html form that when click redirects me to the pdf in question
When I try to hit the same endpoint with cljs-ajax and do something with the stream things get weird
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?
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
it should only take as long as it takes to modify a var... because that's all it does
are you sure the namespace defining the method is getting required at startup?
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
anyway, it's late here, I'm turning in 👋
@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.
@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.
@mobileink Clojure is Object-based. So clojure can make full use of the existing achievements and facilities of OO
And if someone attempts to do OOP in Clojure they're gonna have a bad time
@U07TDTQNL I agree with your point of view.
I've never used OOP technology on Clojure, just using object on the JVM and the Java library.
@mobileink Don't you use any object in Clojure? It's impossible.
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.
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”.
Let a lot of functions revolve around a data structure. Write functions as data changes.
translating Java code to Clojure, Don't maintain the original system construction method, which is unreasonable.
@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 🙂
@lincpa I would LOVE seeing that code base, if it is in the open domain. It might provide the other half to my question.
I look at https://github.com/mikera/core.matrix and I see clojure vectors.
How can this possibly be fast if it's using clojure vectors instead of native java vectors?
is it not copying over to LAPACK anyway @qqq- a linear copy op probably doesn't figure much in the overall complexity
@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
http://www.braveclojure.com/ would not be a bad start
Web development with Clojure by Sotnikov seems to be a good book
Also Carin Meier’s Living Clojure, https://www.amazon.com/dp/1491909048/ref=cm_sw_su_dp
@chrisblom my favourite was "Programming Clojure", followed by "Web Development for Clojure"
I liked clojure for the brave :)
The clojure koans are good too
Does anybody know of any branch and bound software available to clojure or java?
I have an optimization problem I need it for
@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)
https://pragprog.com/book/shcloj3/programming-clojure is the future home for it
Has anyone used direct linking (https://github.com/clojure/clojure/blob/master/changes.md#11-direct-linking) and really noticed any performance gains?
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?
@alexmiller That’s great news 🙂
I'm having a lot of trouble using a JDBC url with username and password embedded in them
this is a PAAS type of environment where DATABASE_URL is provided
not really a Clojure thing, I know... but I wonder if anybody has had any luck with that
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)
at the moment, i'm trying to get an example project working, and that project has :main name-of.namespace
in its project.clj
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
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?
@adamvh did you see https://github.com/madvas/cljs-react-material-ui-example/issues/1 ?
(except i also left a def
form out of the -main
function but that's neither here nor there)
If I have the following thing: ("foobar") ...
is it fair to call it a list containing one item (a string in this case)?
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 '
or, how do I get the string out of that form without clojure attempting to evaluate it?
super fair to call it that, as that's what it is. can you show an example of your usage?
but to make it a literal with '
, just prepend the sexp with quote '("won't be evaluated")
=> (quote ("won't be evaluated"))
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...
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.
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...
that's all.
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
hmm... well, actually, it seems to want just a string...
and so I really just am trying to get the string out of that list...
which has been stumping me.
using quote isn't technically right because it's adding in the opening and closing parens as part of the string
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.
do you want to return the original data structure but with a plain string in place of ("foobar")?
that would be great, actually.
can you give an example for ({:tag :a, :attrs {:href "/bizbaf", :content ("foobar")} ?
hmmm.... never mind that first paren...
{:tag :a, :attrs {:href "/bizbaf", :content ("foobar")}
oh man, this is really helpful, from a learning perspective (as well as getting past this frustrating point!)...
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)
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
omg, lol...
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...
a perfect storm.
anyway, sorry for all that.
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).
so, the crux of my issue seems to be that my data structure is
where the value for ':b' is not quoted
clojure: code is emoticons, emoticons is code
or like if this datastructure is coming from a macro and then clojure is trying to compile it
if you are, yourself, writing this data structure in your code you will have to quote ("string")
if something else is giving you this data structure, clojure shouldn't try to compile it unless in a macro
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
select
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.
that's the root of the problem.
that seems fine to me, i think the root of the problem is that clojure is trying to evaluate that value
totally. and I'm learning a lot about the 'data is code, code is data' thing right now from you all.
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
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.
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
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
@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
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.
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.
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...
as of the latest alphas, spec and clojure are different artifacts and versioned separately
@b-ryan unfortunately xml/parse
doesn't accept string... but (xml/parse (java.io.ByteArrayInputStream. (.getBytes (slurp (io/resource "file.xml")))))
works
@hiredman Looks like it is working. The last note on the Google groups thread was key. Thank you again...
@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.
@pyroclast-bot Send to CgcyNDM2NjMzEgZnaXRodWI, 591a0573-2ed1-40c1-93dc-2e9f895be2db, topic-c6e4d140-1a91-4323-b288-e0ddd3a62aca
opps sorry
(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.@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.
@mobileink Clojure is Object-based. So clojure can make full use of the existing achievements and facilities of OO