Fork me on GitHub
#beginners
<
2021-11-10
>
eigenhombre01:11:12

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.

eigenhombre01:11:59

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

athomasoriginal01:11:35

You can write a macro to access static files as well. Here is an example of slurping an SVG file https://mattgreer.dev/blog/embedding-svg-into-a-reagent-component/

eigenhombre01:11:19

Interesting, thanks!

JB Seo01:11:41

Hello. I have a question on deftype documentation (https://clojuredocs.org/clojure.core/deftype) > 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 ?

hiredman02:11:11

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

vinurs03:11:01

(xml/alias-uri 'soap12 "")
(xml/emit-str
 (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 clojure.data.xml 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

thom07:11:29

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.

Benjamin10:11:34

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

zackteo02:11:50

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 :) https://github.com/zero-one-group/fxl/blob/develop/src/zero_one/fxl/google_sheets.clj#L65

Mno10:11:43

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

Benjamin10:11:56

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

πŸŽ‰ 1
zendevil.eth12:11:03

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

{:filename "download.png", :content-type "image/png", :tempfile #object[java.io.File 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 https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html#copyFile-java.io.File-java.io.File-).

pinkfrog13:11:25

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
Benjamin17:11:20

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

pavlosmelissinos18:11:07

Probably not what you're referring to but test.chuck's string-from-regex might do what you want https://github.com/gfredericks/test.chuck#string-from-regex

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 ""
  [var-name]
  (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. https://github.com/clojure/core.match explicitly states that it supports both, but the namespaces appear to be different, whereas https://github.com/clojure/algo.generic doesn't say whether it can be used via ClojureScript.

hiredman22:11:20

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

hiredman22:11:49

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

(ns foo.bar
  (: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?

hiredman22:11:13

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

hiredman22:11:36

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)

hiredman22:11:23

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?

hiredman22:11:00

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

hiredman22:11:33

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

hiredman22:11:49

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

hiredman22:11:40

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 clojure.foo namespace in a .cljs file the compiler will say, "Hey, you probably meant cljs.foo I bet."

Erich Wolodzko22:11:29

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

hiredman22:11:46

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?

hiredman22:11:22

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

hiredman22:11:46

the readme is your best bet really