Fork me on GitHub
#beginners
<
2019-08-28
>
Mario C.00:08:48

found the error

noisesmith00:08:23

what was it?

Mario C.00:08:20

The error was because the :plugins key value was incorrect. Just a single vector instead of each of plugin being its own vector

Mario C.00:08:35

pure luck I even caught this

noisesmith00:08:49

wow, the dark side of pure data driven DSL

Mario C.00:08:21

lol this was a hard stuck for me

johnjelinek00:08:02

#beginners might not be the right place for this question ... but, I'm pulling in AsciidoctorJ (java bindings to a ruby gem called asciidoctor) through tools.deps and there's a gem that provides additional functionality ... is there a way to have tools.deps use JRuby to pull in the gem so it can be used?

noisesmith00:08:19

@johnjelinek it looks like jruby is on maven, so you can pull it in as a dep, the next question is how to invoke it to make it pull in and run a gem https://mvnrepository.com/artifact/org.jruby/jruby-complete

noisesmith00:08:45

that might be more of a jruby question - I assume they have a java api, and if that exists clojure can use it via interop

noisesmith00:08:00

for comparison, with clojure, you could depend on the lib via maven and it would in turn depend on clojure, allowing you to invoke clojure and run the lib

noisesmith00:08:19

one would hope jruby allows something similar

johnjelinek00:08:15

So, it looks like AsciidoctorJ comes with an internal JRuby that can resolve gems, but those gems still have to get in there somewhere. I guess maybe there's a way to call the bundle install of JRuby from within the Clojure process?

noisesmith00:08:48

hopefully JRuby provides a way to invoke that via interop, if so you can do it from Clojure

noisesmith01:08:23

a brief google search makes it look like the jruby bundler isn't tied to maven at all, so tools.deps wouldn't do anything with it, but you could definitely script a bundler call into a build process that uses tools.deps to find clojure / maven depenencies

noisesmith01:08:52

tools.deps intentionally isn't a building or packaging tool, it's just for finding jvm deps

noisesmith01:08:17

on the other hand, lein does intend to be a packaging and building tool, and does have a plugin for jruby (I can't vouch for the quality) https://github.com/jkutner/lein-jruby

SoV402:08:47

I'm making a japanese learning application, right now I'm working on drills

SoV402:08:55

So that I can test people for things in an automated way

SoV402:08:03

Repeat it until you get >80% or whatever

SoV402:08:09

{:は "Mr. Tanaka", :から "Japan", :verb "is."}

SoV402:08:12

I have some example maps of potential sentences. The pairs of word+particle, represented in the map as matched :k "v" pairs can be in any order, as long as the verb's at the end.

SoV402:08:29

Not all the maps have the same keys...

SoV402:08:32

(particles)

SoV402:08:04

should I be striving to name all the keys in the map the same?

SoV402:08:13

like :word1 :particle-for-word1

SoV402:08:17

:word2 :particle-for-word2

SoV402:08:50

or can I name them :particle1 word1 ... :particle2 :word2 ... not every map has every potential key i'd be using, just a small subset

johnjelinek02:08:36

@noisesmith: ya, I'm trying to not use lein as much as possible ... and I've been using tools.deps as my task runner with :aliases

johnjelinek02:08:53

@alexmiller: hey hey, I'm workin' through Clojure Applied. Page 53, I've run into an error:

user=> (take 5 (sort (map (:name planets))))
Execution error (IllegalArgumentException) at user/eval6461 (REPL:1).
Don't know how to create ISeq from: clojure.core$map$fn__5862

johnjelinek02:08:15

this works though:

user=> (take 5 (sort (map #(get % :name) planets)))                                                                     ("Earth" "Mars" "Venus") 

johnjelinek02:08:28

so does this:

user=> (take 5 (sort-by :name planets))                                                                                 ({:name "Earth"} {:name "Mars"} {:name "Venus"})

seancorfield02:08:36

You have ( ) in the wrong place

seancorfield02:08:50

(map :name planets) not (map (:name planets))

seancorfield02:08:36

(map (:name planets)) tries to select the :name from the collection planets which will produce nil and then (map nil) is the 1-arg form which produces a transducer.

seancorfield02:08:23

Hence the error: trying to create a ISeq (as the argument of sort) from that transducer (which is an anonymous function from inside map)

seancorfield02:08:27

^ @johnjelinek

johnjelinek02:08:55

that's how it's written in the book

seancorfield02:08:20

Then it's wrong in the book.

johnjelinek02:08:42

@alexmiller: ☝️

johnjelinek02:08:30

user=> (take 5 (sort (map :name planets)))                                                                              ("Earth" "Mars" "Venus") 

alexmiller02:08:46

yeah, that's a bug in the book

seancorfield02:08:46

It's listed as a known issue in the errata: https://pragprog.com/titles/vmclojeco/errata

alexmiller02:08:23

that's to check that you're reading closely

Trevor10:08:47

Is there an editor that offers automatically adding imports in clojurescript? especially adding libraries from javascript like material-ui? It's killing me having to type manual requires in when I need to use a button or something.

uosl10:08:20

how are you importing them? do you know of [my.lib :as m], allowing you to refer to them as m/button?

Trevor13:08:06

@UCW9TUDNK yup, what I'm hoping though is to not have to type any of that. I. typescript or kotlin when you use something from another library or package that you haven't written the import for, intellij will just automatically add the import for you. I'm pretty sure cursive can do this for Clojure, but not clojurescript

uosl13:08:33

it would probably be best to ask this in the specific channel for your editor. (I recommend Cursive if you aren't attached to any specific one.) If it doesn't support this, a simple helper could be creating a snippet for the ns declaration that already includes the requires you usually type in.

Trevor10:08:34

or is this what the cljsjs projects are supposed to solve? providing namespaces and function definitions for javascript libraries?

Leon10:08:36

sorry if this is a dumb question, but here we go: i have some values (in a list), where every one is one of a list of possible values (the status of a server, so "starting", "stopped", etc). These options have a specific order, and i need to find the entry in my value-list that comes first in the list of options. in java/kotlin, i would use enums for that, and have an enum entry for every option and then just sort. how do i go about doing this in Clojure? is there some idiomatic way to achieve this?

Meyer11:08:22

@lkowarschick you can do like this on Clojure, there is no enum like java on Clojure. All Clojure data structure (collections or map) is seq-able and you can iterate every element on it.

Leon13:08:20

thanks for your time ;D my solution ended up being really simple:

(def states ["STOPPED" "STARTING" "RUNNING"])

(defn worst-status [stati]
  (first (filter #(.contains stati %) states)))

chepprey13:08:24

After installing clj according to https://clojure.org/guides/getting_started#_installation_on_linux, I cannot get the REPL up. The clj command is unresponsive for a good minute and then spits out a big Java stacktrace, the key part is Caused by: org.eclipse.aether.transfer.ArtifactTransferException: Could not transfer artifact org.clojure:clojure:pom:1.10.1 from/to central (): No route to host (Host unreachable)

chepprey13:08:01

I'm very certain this is due to corporate network proxy. What's the recommended way to tell clj about my proxy settings?

alexmiller13:08:47

you can use maven proxy settings

chepprey13:08:51

that did it, thanks!

johnjelinek16:08:26

does anyone have examples of passing specs to defrecord?

user=> (clojure.repl/doc defrecord)
-------------------------
clojure.core/defrecord
([name [& fields] & opts+specs])
Macro
  (defrecord name [fields*]  options* specs*)

alexmiller16:08:22

Those specs are not spec specs

alexmiller16:08:59

Specs there are referring to protocol/interface implementations

Ashley Smith17:08:54

Hey, so I have a simple question. In Clojure, we use foo/core.clj(s) a lot. However, when it comes to dependencies, what are the best practices? Should foo/core.clj :require things in it's folder, or should it act as a common file intended to be included by others? I'm neatening my file structure today, and was wondering whether db/core.clj should contain common functions, or whether db/core.clj should act as a single thing to require that handles your things for you. Any ideas?

noisesmith17:08:07

arguably the ubiquity of "core.clj" is just circumstantial - it's a default with lein templates because single segment namespaces are problematic and some generic name was needed

noisesmith17:08:18

ideally you can have a namespace with a more meaningful name

noisesmith17:08:33

that said, if present, people expect the "core" ns to be top level, I think

Ashley Smith17:08:12

I'm glad I chose right then 🙂 Thank you again!

noisesmith17:08:38

the canonical example would be clojure.core (the top level clojure ns of clojure code, implicitly used if you use the ns macro to create a namespace)

Paulius Macernis18:08:37

Hi. Sorry if the question is dumb enough, I do try to learn here.. 🙂 I have a timestamp value which I got in the way like that let [timestamp (java.time.LocalDateTime/now). How do I format the value to something like yyyy-MM-dd'T'HH:mm:ss afterwards ?

hiredman18:08:34

java.time times usually use that kind of format as their default if you just call str or .toString on them

dpsutton19:08:52

if you want to be explicit (.format (java.time.format.DateTimeFormatter/ISO_LOCAL_DATE_TIME) (java.time.LocalDateTime/now)) (I'm not familiar with java time yet but this seems to be a straight forward way. maybe someone more java interop-y than me can comment on how they'd do it

noisesmith19:08:33

the parens around the ISO_LOCAL_DATE_TIME are optional btw, it's a field, not a method

noisesmith19:08:45

I mean, (Math/PI) is valid too, but it's weird

dpsutton19:08:43

ah thanks. i'm still bad at reading javadocsa

Paulius Macernis19:08:26

Thanks to all of you! However, I am still on figuring out how to "connect" the answer to my own needs (the test which is currently failing). At the moment I went to read some more info on the data/time in Java and Clojure. Hope to improve on the topic soon 🙂

noisesmith19:08:09

none of this is Clojure specific (beyond interop syntax which applies to everything we get from Java)

johnjelinek23:08:55

which do you prefer: PersistentQueue or a channel?

hiredman23:08:29

the usage is very different

hiredman23:08:55

a pqueue is a value and a channel is not

hiredman23:08:37

so you can safely use a pqueue as a key for a map, or as part of the succession model

hiredman23:08:26

there are single threaded functional algorithms where you need a queue, and that is where you use a pqueue