Fork me on GitHub

hi I am new to clojure, and I got a question I have not being able to find a definitive answer on google I work with a big java desktop application, where I have managed to embedd jython to provide a scripting framework it works well, but I hate java scientific libraries, jython cannot use numpy and Co. I got interested in Inchanter instead. Now I am wondering if I can also embedd clojure into the java app in the same way as I did for jython. What I do with jython, is on java, I create an interpreter, set paths to different modules I need dynamically then I put a 2D matrix (a list of lists) into the interpreter and then I load the script I want and execute a function that will always be in every script by convention, and which takes that 2D matrix I put into the interpreter the function returns another 2D matrix, which then I can recover from java side and cast to java types and then some other small things like redirecting jython stdout and stderr to java so that I can print nicely on the java app, etc Would it be possible with clojure? Somehow I got the feeling it is not designed for this purpose.


Hi @sidrero you should be able to use core.matrix for most of what you need. It supports conversions to / from various different matrix representations


core.matrix is roughly equivalent to numpy in terms of scope, most of the same functionality is there too

Nicolas Boskovic20:10:17

I have a small question regarding clj-http. How can I emulate a curl post that does this? curl -X POST '' -d 'request_body={ ... }'


@nnbosko: this should do it

(require '[cheshire.core :as json])
(require '[clj-http.client :as http])
(http/post "" {:body (json/encode {...})})
there are a lot of excellent examples in the readme on github

Nicolas Boskovic20:10:40

Sorry, I should have been more specific. The issue isn't that per se, I know more or less how to deal with clj-http, the issue is specifically sending 'request_body = { ... }' as data

Nicolas Boskovic20:10:45

Not request body as a json parameter itself, but request_body={ "api_key" : "xxxxxx", "name" : "xxxxx" etc }

Nicolas Boskovic20:10:21

hence -d 'request_body={...}'


so the body is "request_body={...}"?

Nicolas Boskovic20:10:51

I wouldn't say that, because doing (http/post "website" {:body "request_body={...}"}) fails


then i'm afraid the finer points of what curl is doing there is lost on me!


@nnbosko: "I wouldn't say that, because doing (http/post "website" {:body "request_body={...}"}) fails" fails how?

Nicolas Boskovic20:10:58

It says request_body is empty

Nicolas Boskovic20:10:54

More specifically this is the body of the request I'm getting from the server

Nicolas Boskovic20:10:13

:body "{\"status\":\"ERROR\",\"status_code\":\"BP-DPAR-1\",\"status_message\":\"request_body is empty\"}"


I think it's something on your server side. I tried here and (client/post "" {:body "request_body={...}"}) works fine, the server gets the string "request_body={...}"


what’s the content-type header on the POST?


typically you need to set application/x-www-form-urlencoded to get standard parsing behaviors to work, this is often automatic


yeah, if it works with curl but doesn't work with clj-http, it's probably a matter of the default content-type being different for each one, which causes the server to misunderstand the body