clojure

New to Clojure? Try the #beginners channel. Official docs: https://clojure.org/ Searchable message archives: https://clojurians-log.clojureverse.org/
João Galrito 2020-09-23T00:22:22.000400Z

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

João Galrito 2020-09-23T00:22:47.000700Z

#off-topic ?

seancorfield 2020-09-23T00:58:15.002Z

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

João Galrito 2020-09-23T01:51:07.002300Z

Alright

João Galrito 2020-09-23T01:52:39.003500Z

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 Galrito 2020-09-23T01:53:04.004100Z

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

João Galrito 2020-09-23T11:30:48.021200Z

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

João Galrito 2020-09-23T01:54:13.005200Z

and reading and writing to an async/chan

João Galrito 2020-09-23T01:55:59.005500Z

with a buffer

the2bears 2020-09-23T03:37:56.006100Z

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

emccue 2020-09-23T04:34:54.006500Z

That description isn't specific enough for me to say. If you want to partially process a sequence, it would matter for recommendations what the logical predicate is to stop and whether you want that processing to return a value or perform a side effect

emccue 2020-09-23T04:35:55.006700Z

you can always split a sequence by index with the combo of take and drop

chetchan 2020-09-23T06:40:10.008800Z

(->> 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))))

2020-09-23T06:44:52.009300Z

Switch to ->, use doto

➕ 2
nick 2020-09-23T07:14:39.011700Z

(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?

nick 2020-09-23T07:14:51.011800Z

found via https://twitter.com/VincentCantin/status/1308611926310576128

seancorfield 2020-09-23T07:22:49.012300Z

->> 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=> 

👍 1
Isaiah Jones 2020-09-23T08:06:15.013600Z

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 Jones 2020-09-23T08:06:23.014Z

the function code i have right now is this:

Isaiah Jones 2020-09-23T08:07:32.014900Z

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

Isaiah Jones 2020-09-23T08:08:14.015800Z

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 Jones 2020-09-23T08:10:05.016400Z

Anyone know how to fix this issue?

2020-09-23T08:18:33.016700Z

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 Jones 2020-09-23T08:37:23.017100Z

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

2020-09-23T08:53:49.017400Z

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

2020-09-23T08:54:08.017600Z

based on example given in one of your messages

Erkan 2020-09-23T09:47:15.020100Z

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-himik 2020-09-23T10:22:51.020400Z

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.

Erkan 2020-09-23T11:00:46.021Z

excellent, now I got it! thanks @p-himik

bastilla 2020-09-23T13:11:00.026600Z

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!!!

Michał 2020-09-23T13:22:19.031500Z

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.

Pradeep B 2020-09-23T13:27:47.031600Z

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

bastilla 2020-09-23T13:43:04.031800Z

it's uberwar.

bastilla 2020-09-23T13:51:15.032200Z

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

bastilla 2020-09-23T14:01:32.032400Z

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

jsn 2020-09-23T14:13:22.032600Z

https://github.com/ptaoussanis/tempura maybe?

Michał 2020-09-23T14:17:51.033100Z

Thanks, looks like what I'm looking for!

tugh 2020-09-23T14:18:41.034400Z

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

tugh 2020-09-23T14:19:20.035300Z

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

2020-09-23T14:55:46.037200Z

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

dpsutton 2020-09-23T15:00:50.037700Z

because debug is not in your aliases map

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

2020-09-23T15:01:21.038200Z

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

dpsutton 2020-09-23T15:02:02.038700Z

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

robert-stuttaford 2020-09-23T15:06:36.038900Z

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

2020-09-23T15:13:40.039Z

Thank you!

flowthing 2020-09-23T15:46:25.039200Z

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

robert-stuttaford 2020-09-23T15:47:45.039400Z

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

flowthing 2020-09-23T15:49:25.039600Z

Interesting, thanks!

flowthing 2020-09-23T15:50:02.039800Z

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

robert-stuttaford 2020-09-23T15:51:53.040Z

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

flowthing 2020-09-23T15:52:07.040300Z

Sure, same here.

robert-stuttaford 2020-09-23T15:54:12.040700Z

https://github.com/clojure/tools.deps.alpha/wiki/Tools got me excited briefly

borkdude 2020-09-23T16:12:57.041100Z

is a license usually included in the .jar?

borkdude 2020-09-23T16:13:26.041300Z

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

seancorfield 2020-09-23T17:03:40.044700Z

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

seancorfield 2020-09-23T17:04:20.044900Z

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

seancorfield 2020-09-23T17:04:55.045100Z

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

bastilla 2020-09-23T17:22:20.045500Z

@seancorfield 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.

Clypto 2020-09-23T17:34:46.045700Z

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

Clypto 2020-09-23T17:35:23.045900Z

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

seancorfield 2020-09-23T17:37:49.046100Z

@bastilla 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).

Clypto 2020-09-23T17:57:02.047600Z

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

Clypto 2020-09-23T17:57:10.047900Z

is Oz too much or are there better options?

2020-09-23T18:16:35.049100Z

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

2020-09-23T18:17:50.050300Z

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.

dorab 2020-09-23T18:24:55.051600Z

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

vlaaad 2020-09-23T18:26:23.052200Z

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

vlaaad 2020-09-23T18:26:39.052500Z

although it has charts..

Clypto 2020-09-23T18:39:14.052700Z

ah cool, I'll give Oz a try

practicalli-john 2020-09-24T18:45:33.062700Z

I enjoyed using Oz, really nice to use. I did the following with Oz https://practicalli.github.io/blog/posts/visualising-uk-covid19-data-with-oz/ https://practicalli.github.io/blog/posts/a-deeper-understanding-of-oz-data-visualization/

🦜 1
jsa-aerial 2020-09-23T19:59:57.056100Z

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

vlaaad 2020-09-23T20:00:47.056900Z

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 "<http://maven.apache.org/POM/4.0.0>"
               'xsi "<http://www.w3.org/2001/XMLSchema-instance>")

(println
  (xml/indent-str
    (xml/element
      ::pom/project
      {::xsi/schemaLocation "<http://maven.apache.org/POM/4.0.0> <http://maven.apache.org/xsd/maven-4.0.0.xsd>"
       (keyword "xmlns" "") "<http://maven.apache.org/POM/4.0.0>"
       :xmlns/xsi "<http://www.w3.org/2001/XMLSchema-instance>"}
      (xml/element ::pom/modelVersion
                    {}
                    "4.0.0"))))
Specifying some ns as default requires using unprintable keywords: (keyword "xmlns" "") waaaat

vlaaad 2020-09-23T20:01:15.057100Z

am I missing something?

2020-09-23T20:02:50.057700Z

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.

alexmiller 2020-09-23T20:02:57.057900Z

you can set default ns as an attribute

Istvan Szukacs 2020-09-23T20:03:40.059100Z

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

alexmiller 2020-09-23T20:03:56.059300Z

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

Istvan Szukacs 2020-09-23T20:04:22.059500Z

alexmiller 2020-09-23T20:05:34.060400Z

that's just the invocation of your function

alexmiller 2020-09-23T20:06:02.061Z

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

👍 1
vlaaad 2020-09-23T20:10:13.061100Z

thanks!

vlaaad 2020-09-23T20:10:35.061300Z

sexp api looks better in this regard!

vlaaad 2020-09-23T20:13:36.063300Z

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 "<https://repo.clojars.org>"}}
 :scm {:url "..."
       :tag "..."}}
...and pom.xml could be created as a build step and then discarded after deployment...

2020-09-23T20:28:12.063800Z

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

Istvan Szukacs 2020-09-23T20:30:58.064Z

You mean just check line by line what it does?

Istvan Szukacs 2020-09-23T20:31:36.064200Z

what tool should I use the further analyze this?

Istvan Szukacs 2020-09-23T20:31:51.064400Z

seems like VisualVM does not give me everything

vlaaad 2020-09-23T20:35:56.065800Z

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

vlaaad 2020-09-23T20:38:33.067Z

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

2020-09-23T20:48:36.069400Z

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

vlaaad 2020-09-23T20:59:21.075300Z

> 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).

vlaaad 2020-09-23T21:00:22.075800Z

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

vlaaad 2020-09-23T21:00:44.076300Z

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

vlaaad 2020-09-23T21:01:47.076900Z

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

2020-09-23T21:04:16.077800Z

what do you mean by deployment?

Joe Lane 2020-09-23T21:04:23.078Z

Maybe what you want is a database @vlaaad

vlaaad 2020-09-23T21:05:10.078600Z

deployment to clojars

2020-09-23T21:05:40.079700Z

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

vlaaad 2020-09-23T21:05:40.079800Z

I only need pom.xml to deploy to clojars

vlaaad 2020-09-23T21:09:50.081300Z

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

2020-09-23T21:12:53.083200Z

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

Joe Lane 2020-09-23T21:13:24.083400Z

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.

2020-09-23T21:14:18.084200Z

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

2020-09-23T21:15:39.084800Z

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

2020-09-23T21:16:22.085600Z

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

vlaaad 2020-09-23T21:20:26.087300Z

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.

alexmiller 2020-09-23T21:57:20.089Z

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

alexmiller 2020-09-23T21:57:49.089400Z

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

alexmiller 2020-09-23T21:58:43.089800Z

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

alexmiller 2020-09-23T22:03:31.090300Z

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

alexmiller 2020-09-23T22:04:28.090500Z

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