Fork me on GitHub

ClojureScript beginner, is there an equivalent to calling on a text file in my jar? Where presumably that text file makes it into .... static assets in some other dir? ... or something? Basically I want my ClojureScript functions to be able to get to static data I control, and I'm used to doing this in Clojure through a resources subdirectory that gets baked into my (ΓΌber)jar at build time. What is the preferred idiom for this, and should I be asking in #clojurescript instead? So many questions....

JB Seo01:11:52

if you are using shadow-cljs, you can use shadow.resource/inline for reading a file on compile time.


I am not -- am just using lein-cljsbuild... but I will look at that fn to see if I can grok it. Thanks!


You can write a macro to access static files as well. Here is an example of slurping an SVG file


Interesting, thanks!

JB Seo01:11:41

Hello. I have a question on deftype documentation ( > You can also define overrides for methods of Object. Note that a parameter must be supplied to correspond to the target object ('this' in Java parlance). > Thus methods for interfaces will take one more argument than do the interface declarations. > > Note also that recur calls to the method head should *not* pass the target object, it will be supplied automatically and can not be substituted. The last sentence says that when calling the method recursively, this should not passed. But how can I call the method recursively without passing this ?


It is like a normal recur, you just leave out the first argument (the this parameter)


(xml/alias-uri 'soap12 "")
 (xml/element ::soap12/Envelope
                   {:xmlns/xsi ""
                    :xmlns/xsd ""
                    :xmlns/soap12 ""}
                   (xml/element ::soap12/Body {}
                                (xml/element :GetWorkers {:xmlns ""}
                                (xml/element :dataNumber {} "xxx")
                   (xml/element :bagsBH {} "aaaa"))
hello, i have use generate xml data, and it outputs
<?xml version=\"1.0\" encoding=\"UTF-8\"?><soap12:Envelope xmlns:xsi=\"\" xmlns:xsd=\"\" xmlns:soap12=\"\"><soap12:Body><GetWorkers xmlns:a=\"\"><dataNumber>xxx</dataNumber><bagsBH>aaaa</bagsBH></GetWorkers></soap12:Body></soap12:Envelope>
there is a :a after xmlns in GetWorkers, how can i remove it


You can't remove it unless you remove the xmlns attribute but you can customise it using namespaced xmlns keywords like you have for xsi/xsd/soap12.


does somebody have an idea how to convert a google sheet to clojure data? I coudl download as comma separated values and go from there


If you are still looking for other solutions, reading can be done in a clojure spreadsheet library, fxl. But does require some setup with access keys :)


Google Sheets has an api to get the data directly as well, though I don't recall how easy it was to use.


yea I googled and followed a guide to get the json hackily. Really wierd - but I have what I need πŸ˜„

πŸŽ‰ 1

Hi I have a file coming in from the client multipart params to the server:

{:filename "download.png", :content-type "image/png", :tempfile #object[ 0x52ecc329 "/var/folders/96/df02xppj77g7dx698gtmwmrw0000gn/T/ring-multipart-5763616289942355055.tmp"], :size 15035}
I want to save it to a file on the server. How do I do that?

Wout Neirynck14:11:11

@U01F1TM2FD5 from the looks of it, it's already in a file (the :tempfile property). You can copy it to another location using any available Clojure or Java function (take a look at


I found this a little bit mind-twisting. For example, some considers logical true, but if-some considers not nil and if-let instead considers logical true. Why the inconsistency?

Alex Miller (Clojure team)15:11:37

design is hard and there are a finite number of words

βž• 2
πŸ™‚ 1

I somehow remember there being something about spec.gen and doing for example human readable strings for sample data. Like atm I get really random strings but the use case is sample data for a search completion thingy


Probably not what you're referring to but test.chuck's string-from-regex might do what you want

Dmitrii Pisarenko18:11:12

I want to write a macro my-nil sets a given variable to nil. That is, (my-nil abc) should be expanded to (def abc nil). Is this implementation correct? (It seems to work at the first glance.)

(defmacro my-nil ""
  (list 'def var-name nil)

Alex Miller (Clojure team)19:11:02

(macroexpand β€˜(my-nil foo)) is a good way to test a macro

πŸ‘ 1
Erich Wolodzko22:11:33

Can anyone point to resources explaining how a Clojure library comes to be consumable via ClojureScript and/or how to determine if that is the case for a given library? I'm very new to the ecosystem, and confused by the fact that e.g. explicitly states that it supports both, but the namespaces appear to be different, whereas doesn't say whether it can be used via ClojureScript.


in general, if it says it works in clojurescript, that is how you know


if you want to go beyond just looking at readmes, the presence of .cljs files or .cljc files may be indicators

Erich Wolodzko22:11:15

My confusion is compounded by the fact that my .cljs file is actually using the "Clojure" namespace referenced in the core.match README, so currently looks like this

  (:require [clojure.core.match :refer [match]]))
but seems to work as far as I can tell. The reason for my question is that I was trying to start using algo.generic.functor in my .cljs file as well, so far unsuccessfully. I wasn't sure if I was just fumbling the dependency updates or if I was trying to do something impossible.

Erich Wolodzko22:11:38

So there is no definitive way to tell beyond try it and see?


I don't deal much in clojurescript, but the compiler for cljs has some automatic support for swapping the clojure namespace name for the cljs namespace name


the definitive way is the readme

Alex Miller (Clojure team)22:11:54

but the lib won't work automatically regardless - it has to have either cljs or cljc files (algo.generic does not)


right, it is just the namespace name that might be automatically swapped,

Alex Miller (Clojure team)22:11:27

(perhaps a better suggestion is that you probably shouldn't use algo.generic)

Erich Wolodzko22:11:47

So the answer is something like, if the library is written in cljc then the compiler for cljs can handle it somewhat automagically, but if the library is written in clj than it cannot?


yeah, I've never used algo.generic in anger


it is just some namespace names the cljs compiler will automatically replace with the cljs namespace name

Alex Miller (Clojure team)22:11:47

more that if it has cljc then presumably the author has put thought into making it work with cljs


so when you try to load clojure.core it loads cljs.core or whatever


and the namespace name rewriting is independent of cljc or cljs

Erich Wolodzko22:11:01

So the library writer has to explicitly provide cljs.* namespace versions of their stuff that actually work with CLJS, but if I try to load a namespace in a .cljs file the compiler will say, "Hey, you probably meant I bet."

Erich Wolodzko22:11:29

That last part is a little odd and surprising, but fair enough.


a clojurescript namespace can come from a .cljs file or a .cljc file, and a clojure namespace can come from a .clj or a .cljc file

Erich Wolodzko22:11:00

So if I want to see if a library supports CLJS, the best indicators are README and/or to see if they define a cljs namespace?


so .cljc files are intended as a way to share code between different clojure implementations


the readme is your best bet really