Fork me on GitHub
#clojure
<
2020-09-23
>
João Galrito00:09:22

is there a channel for non-clojure programming related questions?

seancorfield00:09:15

That sounds like a good place to start if there isn't a language-specific or topic-specific channel for your question.

João Galrito01:09:39

Imagining I have a (potentially infinite) lazy seq, how would I go about outputting this seq into a buffer, and when I receive a signal, start processing from the buffer

João Galrito01:09:04

I imagine I'll have two threads, one where I put stuff into the buffer, and another that locks while waiting for the signal then starts processing

the2bears03:09:56

How about a control channel? That could be used for start, stop, or whatever kind of signal.

João Galrito11:09:48

I kind of have that to signal the 2nd thread to start processing

João Galrito01:09:13

and reading and writing to an async/chan

chetchan06:09:10

(->> bq ; (.jobs) ; (#(.get % project-id job-id)) ; (.execute) ; (.getStatus))) How can I call a method called setLocation which takes a string param on the object returned by line (#(.get % project-id job-id)) In non-threaded form I can achieve it by

(let [jobsobj (.jobs bq)
      getobj (.get jobsobj project-id job-id)
      _ (.setLocation getobj "australia-southeast1")
   (.getStatus (.execute getobj))))

hiredman06:09:52

Switch to ->, use doto

6
nick07:09:39

(let [some-values [-1 2 -3 4]]
  (->> some-values
       (filter pos?)
       (let [some-values [-5 6 -7 8]])))
;; => (6 8)
That was a bit surprising but it might be pretty handy in certain use cases. Reminds me a bit of hoisting in Javascript. Is there a way to know more about why it works the way it works?

seancorfield07:09:49

->> is a pure syntactic transform (a macro) so you can always use macroexpand or clojure.walk/macroexpand-all to see what's going on...

user=> (clojure.walk/macroexpand-all '(let [some-values [-1 2 -3 4]]
  (->> some-values
       (filter pos?)
       (let [some-values [-5 6 -7 8]]))))
(let* [some-values [-1 2 -3 4]] (let* [some-values [-5 6 -7 8]] (filter pos? some-values)))
user=> 

👍 3
Isaiah Jones08:09:15

Hello everyone, I am trying to write a function that is able to call the 'use' function on two parameters but I can't seem to figure out how

Isaiah Jones08:09:23

the function code i have right now is this:

Isaiah Jones08:09:32

(defn foo [a b]
(use a :refer [b]))

delaguardo08:09:33

use expect a vector if you want to use :refer

(defn foo [a b]
  (use [a :refer [b]]))
but this is a bit strange looking usage of use ) have a look at https://clojuredocs.org/clojure.core/requiring-resolve

Isaiah Jones08:09:23

So then how would I be able to use b inside of that function in this case

delaguardo08:09:49

(requiring-resolve (symbol (name a) (name b)))

delaguardo08:09:08

based on example given in one of your messages

Isaiah Jones08:09:14

so that when I call (foo 'project.core 'bar), I am able to refer to the atom named 'bar' located in the project.core namespace inside of this function

Isaiah Jones08:09:05

Anyone know how to fix this issue?

Erkan09:09:15

How do I stop a process started with ProcessBuilder? trying to call destroy on it but I end up with

No matching field found: destroy for class java.lang.ProcessBuilder
and when doing
(clojure.pprint/pprint
    (clojure.reflect/reflect
      process))
it seems to not have any destroy function.

p-himik10:09:51

ProcessBuilder is a builder of processes, it's not the process itself. You will have to get a reference to the started process and call .destroy on it.

Erkan11:09:46

excellent, now I got it! thanks @U2FRKM4TW

bastilla13:09:00

Hi Clojurians! First post here. Has anyone experience with Luminus? I fail to create a functioning WAR file with lein-uberwar (0.2.1) / Leiningen 2.9.1. WAR gets created but once deployed on a Jetty or Tomcat webapps I get HTTP Status 500: clojure.lang.ArityException: Wrong number of args (1) passed to: mytestapp.handler/app (Notice, I didn't do any coding. It's a fresh luminus templated project with just a WAR option. (new luminus mytestapp +war) I get it perfectly running in dev mode using 'lein run'. Has anyone ecnountered this or has an idea? 1000 Thanks!!!

Pradeep B13:09:47

i used lein uberjar command and was able to run the jar just fine with java -jar <filename.jar>

bastilla13:09:04

it's uberwar.

bastilla13:09:15

Unless I can deploy a JAR on a Webapp server. (Giving it a try right now.... Thanks)

bastilla14:09:32

As expected 'lein uberjar' created an executable. Cannot be deployed as a webapp.

seancorfield17:09:40

I thought Luminus projects were intended to be just run as an uberjar, starting Jetty internally?

seancorfield17:09:20

I wouldn't expect an "arbitrary" web project in Clojure to be buildable/usable as a WAR file without additional code being written.

seancorfield17:09:55

There's a #luminus channel where you might get more detailed answers about that...

bastilla17:09:20

@U04V70XH6 Thanks! I'll try that channel. Luminusweb has a +war profile. Doc says "+war adds support of building WAR archives for deployment to servers such as Apache Tomcat". The template code delivers a home page from the get go (lein run). But maybe you're right and there is some additional boot straping neccessary.

Clypto17:09:46

yes, you want an uberwar, which will look for servlet class and such and make sure that's aligned with web.xml and all that in the war archive

Clypto17:09:23

the uberjar is for running the process standalone, not outside of a container. And that needs it's own main function where the jetty adapter can be started. More like a simple process that starts its own web server

seancorfield17:09:49

@U01BEC6NUSY Ah, good to know. I'm not very familiar with Luminus' various options. And I have never used WAR deployment with Clojure (in a decade of production usage).

Michał13:09:19

Hi! I'm looking for the best solution to keep strings (sentences, used by my bot) in some configuration file. The idea is that non technical person will modify them or later we'll add new languages. Is there any library designed to help with that? I don't want to reinvent the wheel using json files if not needed.

Michał14:09:51

Thanks, looks like what I'm looking for!

tugh14:09:41

you can create an edn file an put it under resources. and then create your own (simple) function

tugh14:09:20

idk if you have more needs but this solution is easy and straightforward IMHO

mac0102114:09:46

Can anyone help me figure out why I can't pick up an alias from my global deps.edn? (transcript attached)

dpsutton15:09:50

because debug is not in your aliases map

{:aliases {:depstar
           {:extra-deps
            {com.healthfinch/depstar {:git/url ""
                                      :sha "4aa7b35189693feebc7d7e4a180b8af0326c9164"}}}
           :disasm
           {:extra-deps
            {nodisassemble {:mvn/version "0.1.3"}}}}
 :debug
 {:extra-deps
  {philoskim/debux {:mvn/version "0.7.6"}}}}

mac0102115:09:21

oh well that's interesting! indentation fail, I guess

dpsutton15:09:02

yeah indentation is critical to me. as soon as i reindented it it was clear

robert-stuttaford15:09:36

Has someone perhaps written a #clojure tools-deps centric tool for auditing all of the OSS licenses in use in the dependency tree?

flowthing15:09:25

I’m actually also interested. A Leiningen-based tool would also do.

robert-stuttaford15:09:45

seems https://www.versioneye.com/ (paid tool) has lein support

flowthing15:09:25

Interesting, thanks!

flowthing15:09:02

Maybe I’m optimistic, but I guess it shouldn’t be too difficult to build something fairly simple on top of tools.deps.

robert-stuttaford15:09:53

super simple, just would rather reuse than spend some time building it

flowthing15:09:07

Sure, same here.

borkdude16:09:57

is a license usually included in the .jar?

borkdude16:09:26

then it seems like a pretty simple program to scan for certain files / words on your classpath?

Clypto17:09:02

anyone have a recommendation on best visualization library out there - either server side clojure or front-end clojurescript? I'm looking for something relatively simple - data coming from the server as a ledger of date/time and some values, and then want to do some line graphs around that

Clypto17:09:10

is Oz too much or are there better options?

manutter5118:09:35

Derp, I was thinking Vega Lite was a simplified version of Oz, but it’s the other way around

jsa-aerial19:09:20

Best to ask about this sort of thing in #data-science on Zulip: https://clojurians.zulipchat.com/#narrow/stream/151924-data-science Oz is not simplified Vega/Vega-Lite - it uses them pretty directly. There is Hanami https://github.com/jsa-aerial/hanami if you want a lib to build something on. It has a means of creating simplified templates for visualizations on top of Vega and Vega-Lite.

manutter5120:09:50

Yeah, it’s Vega Lite that’s (obviously) the simpler version of Vega, and Oz that’s a wrapper around Vega/Vega-Lite. I worded my correction badly.

manutter5118:09:50

We were looking at Oz/Vega/Vega-Lite for our dataviz stuff, but then the business decided to farm out to Tableau instead of doing it in-house. I was liking what I saw in Oz even though we never built anything in it.

dorab18:09:55

@clypto I'm a happy oz user. It's pretty straightforward. Depending on your needs, also see cljfx and cljplot.

vlaaad18:09:23

are you sure about cljfx? it's a UI library, not a data visualization library...

vlaaad18:09:39

although it has charts..

Clypto18:09:14

ah cool, I'll give Oz a try

jsa-aerial19:09:20

Best to ask about this sort of thing in #data-science on Zulip: https://clojurians.zulipchat.com/#narrow/stream/151924-data-science Oz is not simplified Vega/Vega-Lite - it uses them pretty directly. There is Hanami https://github.com/jsa-aerial/hanami if you want a lib to build something on. It has a means of creating simplified templates for visualizations on top of Vega and Vega-Lite.

jsa-aerial19:09:57

Should probably mention there is a 'bare bones' example Hanami application as well: https://github.com/jsa-aerial/bbhanami

vlaaad20:09:47

not many people in #xml, so I'll vent here... I've been experimenting with creating xml from code, and it looks just horrible:

(xml/alias-uri 'pom ""
               'xsi "")

(println
  (xml/indent-str
    (xml/element
      ::pom/project
      {::xsi/schemaLocation " "
       (keyword "xmlns" "") ""
       :xmlns/xsi ""}
      (xml/element ::pom/modelVersion
                    {}
                    "4.0.0"))))
Specifying some ns as default requires using unprintable keywords: (keyword "xmlns" "") waaaat

alexmiller20:09:56

I'm doing exactly this stuff for pom.xml in the tools.deps pom sync code if you want to look at that

vlaaad20:09:35

sexp api looks better in this regard!

vlaaad20:09:15

am I missing something?

alexmiller20:09:57

you can set default ns as an attribute

Istvan Szukacs20:09:40

hi folks, can I do something about project.core$myAwesomeFunction.invokeStatic () it takes up a lot of CPU

alexmiller20:09:34

that's just the invocation of your function

alexmiller20:09:02

so your function is taking a lot of cpu. if you open it up, you should learn more about what is doing that

👍 3
Istvan Szukacs20:09:58

You mean just check line by line what it does?

Istvan Szukacs20:09:36

what tool should I use the further analyze this?

Istvan Szukacs20:09:51

seems like VisualVM does not give me everything

alexmiller22:09:31

those little dropdowns on the right are showing you that the top line, and most of its time is spent in the 2nd line, and if you open, that most of its time is spent in the lines below that etc - if you keep following that trail you can see what's taking most of the time

alexmiller22:09:28

depending whether visualvm is using sampling or tracing (probably the former), you won't necessarily see everything, but in theory you should see the important stuff

vlaaad20:09:36

wouldn't it be nice if instead of pom.xml we had pom.edn that could be manipulated as map... :thinking_face: e.g.

{:modelVersion "4.0.0"
 :groupId 'group
 :artifactId 'artifact
 :version "1.0"
 :name "name"
 :dependencies #{{:groupId 'org.clojure
                  :artifactId 'clojure
                  :version "1.10.1"}}
 :repositories #{{:id "clojars"
                  :url ""}}
 :scm {:url "..."
       :tag "..."}}
...and pom.xml could be created as a build step and then discarded after deployment...

hiredman20:09:12

pom.edn is serialized data, pom.xml is serialized data

vlaaad20:09:56

1. pom.edn doesn't have to be a file on disk, it can be created by the build tool on the fly from the deps basis 2. updating a map is so much more reliable than updating an xml

vlaaad20:09:33

e.g. setting git revision: 1. for map: (assoc-in pom [:scm :tag] git-hash) 2. for xml: https://github.com/cljfx/cljfx/blob/master/build/version.clj

hiredman20:09:36

that code handles the strictly more general nature of the xml format, if you make the same assumptions you would need to make to reduce it to a map you could get rid of parts of it, and that code includes the reading and writing to disk, which you map example does not

vlaaad20:09:21

> that code handles the strictly more general nature of the xml format Well that's the problem, like For loops that complect What with How, reliance on the xml file on disk as a source of truth that is modified by a tool complects What I want (produce desirable pom for deployment from the deps and version) with How to do it (by surgically updating XML in a fragile way because XML is a tool for marking up documents, not data).

vlaaad21:09:22

reading and writing is 3 lines, everything else is about that xml processing

vlaaad21:09:44

and that processing is not generic, and every other program does it differently

vlaaad21:09:47

e.g. deps-deploy has different non-generic code for extracting version from pom.xml https://github.com/slipset/deps-deploy/blob/master/src/deps_deploy/deps_deploy.clj#L13-L49

hiredman21:09:16

what do you mean by deployment?

Joe Lane21:09:23

Maybe what you want is a database @vlaaad

vlaaad21:09:10

deployment to clojars

hiredman21:09:40

if you don't deploy to maven repo you don't need a pom

vlaaad21:09:40

I only need pom.xml to deploy to clojars

vlaaad21:09:50

@lanejo01 not sure about that, what do you mean?

Joe Lane21:09:24

It's not a particularly useful answer for you today, but if you step back and think about manipulating this fragile file from multiple programs, potentially concurrently, etc, etc, you could view the output of a query as the pom artifact. That is one valid representation of some facts, but you could have other representations. What if you have questions about the facts, are you going to iterate over the xml file? Iterate over all xml files in all your projects, etc. A database would allow for better affordances than any other existing tools.

hiredman21:09:53

it sounds sort of like what you really object to is the pom file sitting on disk when you don't care about it, so you could just not deploy to maven repos (tools.deps can use git dependencies) or write your own version of deps_deploy with your own version of https://github.com/clojure/tools.deps.alpha/blob/master/src/main/clojure/clojure/tools/deps/alpha/gen/pom.clj that sends the pom over the wire without ever writing it to disk

hiredman21:09:18

inventing a new serialization format for poms doesn't seem like it gets you anything

hiredman21:09:39

maven actually had a project for that kind of thing, https://github.com/takari/polyglot-maven

hiredman21:09:22

my impression was a lot of initial interest, followed by meh when it didn't seem to get you that much

vlaaad21:09:26

I wasn't clear enough, sorry — I don't want a new serialization format for poms. Not pom.edn but pom data structure represented as map in a build/deploy process.

alexmiller21:09:20

part of the work we've been doing to rewrite clj features as functions you invoke is to open up the opportunity to pass it a much greater range of configuration

alexmiller21:09:49

either via :exec-args in deps and/or by overrides on cli

alexmiller21:09:43

you're still going to want the pom.xml as a file though to include it in the jar

vlaaad05:09:53

Of course, but I don't want to have it lying around for more time than built jars are lying around

vlaaad06:09:41

...because for the build tooling, pom.xml is a mutable place that different tools write to or read from