Fork me on GitHub
#beginners
<
2017-09-21
>
mikeb00:09:16

@genec Atom tooling is much more polished than the VS Code options. I would recommend using Atom+Parinfer+ProtoREPL. There's a #protorepl channel for assistance.

genec00:09:40

@mikeb Thanks for the advice. That was my impression after trying both this afternoon. I prefer VS Code over Atom as an editor, but the Clojure support in Atom does seem more mature, but VS Code support is pretty good too. The proto-repl charts are a nice bonus too.

mikeb01:09:11

My favorite part of protorepl is the inline repl results. That said I really love VS Code as well, just not for clojure yet.

noman04:09:38

I've been using IntelliJ with Cursive

noman04:09:48

it's not bad, but it's a little finicky with formatting

noman04:09:05

maybe i'll try the atom route

noman04:09:27

but intelliJ is just so much smarter and more IDE-like than Atom

amit588105:09:27

i was wandering how to configure postgresql with my SPA. I'm using IntelliJ with Cursive on windows

Simon06:09:10

how can I filter a map. I want to keep all that have a certain field value and don't want to turn the result into a list

rauh06:09:59

@hotbelgo Just change odd? in the above example with your predicate.

Simon06:09:39

thanks - are you human or bot?

Simon06:09:40

what does comp achieve here?

rauh06:09:41

@Simon I'm human 🙂 . (comp odd? val) is the same as (fn [map-entry] (odd? (val map-entry)))

Simon06:09:16

ah, I see, because val is a function composed with odd?

schmee06:09:06

another variation is (into {} (for [[k v] {:a 0, :b 1} :when (odd? v)] [k v]))

Simon06:09:38

what I thought I oculd best understand from this is (into {} (filter (fn [_ {:strs [bdType]}] (= bdType tp))) bindings))

Simon06:09:57

but i seem to have made a mistake as it does not give the same results as @rauh example

Simon06:09:27

(defn bindings-by-type [bindings tp]
    (into {} (filter (fn [_ {:strs [bdType]}] (= bdType tp))) bindings))

rauh06:09:15

@Simon you're not destructing, the filter function is a predicate with exactly one argument. Add brackets to your fn: (fn [[_ {:strs ...}]] ...)

rauh06:09:55

You're doing CLJS? Because this should give you an arity error in CLJ.

Simon06:09:50

aaarrrrrr - only the 11000 time I've made that mistake

Simon06:09:37

Last question I'm using the function above here

connected-in-bindings (->> (bindings-by-type bindings "QBSelect")
                                   vals
                                   (remove #(empty? (:in %))))
makes me think I should reverse the order of the parameters - are there any rules of thumb for that?

madstap06:09:17

@hotbelgo Rule of thumb: If you're doing stuff with a sequence then the sequence should come last (`filter`, map, reduce, replace). If you're operating on one data-structure, it should come first (`conj`, update, assoc, dissoc, (most of?) the fns in clojure.string).

Aron10:09:07

i would like to have java completions in lein repl, but i don't know how to look for it. any suggestions?

hmaurer11:09:11

@matt.a.renfro let supports any number of forms in body. n the first case it’s treating each of assoc, m, k, etc as a body form

hmaurer11:09:27

(it won’t behave as if assoc was wrapped in parentheses btw)

hmaurer11:09:44

in the second case your assoc is within a if block, which only supports two forms

antique11:09:09

interesting I wouldn't expect that you could put anything not in parens

hmaurer11:09:19

@matt.a.renfro what do you mean? you definitely can. For example, in (+ 1 2) the individual arguments 1 and 2 are not in parens

hmaurer11:09:02

The way let works is it takes a bindings form and any number of body forms, and returns the result of the last body form

hmaurer11:09:45

If your assoc on line 8 was wrapped in parens it would count as one body form, and the let block would return its result, e.g.

hmaurer11:09:20

If you do not wrap it in parens, it counts as 4 forms. Neither of them have side-effects so they get executed unnoticed (the first one, assoc, will resolve to the funtion, the second one to an empty map, etc), and at the end it returns the last form, 42

hmaurer11:09:00

You would have the same behaviour with a do block

antique11:09:16

Thanks, I just started learning the language yesterday so it was a bit unexpected. I'll keep that in mind.

genec14:09:59

Does anyone have a suggestion as to a good Clojure GUI library? I just want to throw together some UI's at work for prototypes and get some quick feedback from users.

genec14:09:06

From what I can tell, it seems like seesaw / swing is the only thing that's fully baked.

noisesmith14:09:29

there's also javafx

genec14:09:51

Thanks, have you tried it?

noisesmith14:09:40

no, but in my experience projects from that author are very good

jaymartin14:09:17

I’m trying to execute a Clojure expression from the command-line without success. Here’s what I’ve tried:

java -cp clojure-1.8.0.jar clojure.main "(+ 2 3)" 
and
java -cp clojure-1.8.0.jar clojure.main  < "(+ 2 3)" 

noisesmith14:09:35

@jaymartin check out java -jar clojure...jar --help

noisesmith14:09:39

you want -e for a string, or << to make the shell hand it a string as stdin, or << to give it contents of a file (if you are using a normal shell at least). -i works instead of < for a file as well

jaymartin14:09:12

@noisesmith Thank you pointing me to the docs for future reference. That did the trick.

jaymartin14:09:36

With the Clojure 1.8.0 jar in my present working directory, the complete command line for future readers is:

java -cp clojure-1.8.0.jar clojure.main -e "(+ 2 3)"

Mike C16:09:24

Newbie question: I’m reading an XML file with (-> file name io/file io/input-stream io/reader xml/parse). The file has some invalid entities in it, which cause xml/parse to choke. I’d like to do a transformation on the string as it passes through. Is there a nice Clojure way to do that lazily on the way through, or should I just read in the full string, transform it, and then parse-str it?

Mike C16:09:54

s/file name/filename/

noisesmith16:09:44

you could slurp the string, edit, and then make a StringReader and pass that to xml/parse

noisesmith16:09:17

or you could use a tagsoup parser that just keeps chugging when it hits invalid stuff and lets you pick up the pieces

Mike C16:09:21

OK, thanks — so there’s no way of doing, in effect, a Regexp substitution on the string as it’s read, and have the system buffer enough characters to know whether there’s a possible match?

noisesmith16:09:29

not that I know of...

noisesmith16:09:19

you could likely use PushBackReader or StringReader to implement something that behaved like an InputStream or Reader but had that behavior, but I don't know of something that does that out of the box

noisesmith16:09:29

it might exist though?

bfabry16:09:07

no built in way that I know of. I'd be wrapping the reader in a proxy

Mike C16:09:32

Great, thanks — just wanted to make sure I wasn’t re-inventing something that was already available

noisesmith16:09:37

there's libs for java that do this sort of thing, I can't vouch for quality though https://github.com/rwitzel/streamflyer

noisesmith16:09:58

in clojure you can usually find a functionality for what you want by searching for java instead, interop is relatively easy

hmaurer16:09:26

probably one of the best part about clojure actually

hmaurer16:09:38

access to the rich java ecosystem of librairies without having to write java

Mike C16:09:31

Oooh. That looks like it might be just the ticket. Thanks!

Mike C18:09:44

So I’ve been playing around with streamflyer, and almost got it working. To run the transformation I need, I have to use proxy to make an object that implements a specific interface (`MatchProcessor`). The function of interest in that interface accepts a java StringBuilder, which (in the java example) it modifies in place.

noisesmith18:09:47

sounds good so far - even clojure.core/str uses a mutable StringBuilder internally

Mike C18:09:42

I can run methods on the StringBuilder in my code, but the results are lost — do I need to do something to ensure that the updated StringBuilder is ‘seen’ by the calling java?

noisesmith18:09:12

so it passes you a StringBuilder, and you are putting things in it, and they disappear?

noisesmith18:09:28

it's a mutable thing, you shouldn't have to do anything special to make it work

noisesmith18:09:59

other than the obvious eg calling the append method etc.

Mike C19:09:01

so I shouldn’t have to do anything special

Mike C19:09:09

Time to write some minimal test cases then, thanks

noisesmith19:09:54

since you are here in #beginners I'll mention this one: make sure that you aren't calling the append method inside for or map

noisesmith19:09:35

because for, map, and friends are lazy, and if nobody is using the sequence they generate, they do nothing. If you need to iterate for side effects use run! or doseq

Mike C19:09:47

Worth noting, thanks

Mike C19:09:24

I’ve fixed it though — it wasn’t mutability issue in the end (that was just my first concern). I was mis-counting where I wanted the scanner to restart, so it was missing some matches

Mike C19:09:29

thanks again

genec19:09:30

I'm playing around with SeeSaw. Everytime I close the window (frame) my repl crashes and I have to close it and restart it. I'm using Atom / Proto-Repl. Any ideas on how I can create, show, close windows without restarting the repl?

seancorfield20:09:54

@genec When you say "crashes", what do you mean? Have you tried this from a REPL started from the command line outside of Atom?

schmee20:09:47

@genec do you have :on-close :exit set on your frame?

vuuvi20:09:09

does anyone advice for learning how to write REGEXs?

noisesmith20:09:21

if you need to use regexes, this site is a great resource https://www.regular-expressions.info/reference.html

hmaurer20:09:35

@alexkeyes try things in https://regex101.com/ until it works 😄