Fork me on GitHub
#clojure
<
2017-11-16
>
rymndhng00:11:22

this will help me sleep better at night 😄 thanks for the explanations!

leontalbot00:11:37

Is there a way to show “simpler” java objects:

leontalbot00:11:01

[#object[edu.stanford.nlp.ling.TaggedWord 0x6a16b1ef "Short/JJ"]] ->

leontalbot00:11:43

[#<TaggedWord Short/JJ>]

phronmophobic00:11:15

are you talking about how java objects are printed?

leontalbot01:11:00

@smith.adriane I tought I could get this construct [#<TaggedWord Short/JJ>] from/instead of this construct [#object[edu.stanford.nlp.ling.TaggedWord 0x6a16b1ef "Short/JJ"]] in the repl.

leontalbot01:11:30

Using prn doesn’t seem to change anything

phronmophobic01:11:59

I think if you can change how it’s printed by overriding the print-method

phronmophobic01:11:16

(defmethod print-method edu.stanford.nlp.ling.TaggedWord [v ^java.io.Writer w]
  (print-method "[#<TaggedWord Short/JJ>]" w))

leontalbot02:11:29

@smith.adriane wow! Thanks! Works like a charm!

leontalbot02:11:10

would need to make dynamic this part: Short/JJ

leontalbot02:11:43

@smith.adriane this does it:

(defmethod clojure.core/print-method edu.stanford.nlp.ling.TaggedWord
  [piece writer]
  (.write writer (str “#<TaggedWord ” (.toString piece) “>”)))

leontalbot02:11:23

Thanks again!

leontalbot03:11:44

Is this a good practice?

leontalbot03:11:50

(def printed-objects [CoreLabel TaggedWord Word])

(defn set-print-methods! [print-objects] 
  (doseq [o print-objects] 
    (defmethod print-method o
      [piece ^java.io.Writer writer]
      (.write 
       writer 
       (str “#<” (.getSimpleName o) ” ” (.toString piece) “>”)))))

(set-print-methods! printed-objects)

leontalbot03:11:16

(-> “Short and sweet.” tokenize pos-tag)

leontalbot03:11:40

;;=> [#<TaggedWord Short/JJ> #<TaggedWord and/CC> #<TaggedWord sweet/JJ> #<TaggedWord ./.>]

henrik07:11:59

I have two channels. One sends frequent, but low-priority messages. Another sends infrequent, but high-priority messages. I want to process messages from these channels sequentially. If a message is available on the high-priority channel, I want to process that message before the low priority channel is considered. In essence, is there some variant of alts! that I can use/build that has a deterministic order in which it takes from channels?

rwilson07:11:28

You can specify :priority true after the channel and handler forms to indicate that the channels should be tried in declared order.

hiredman07:11:35

have you read the docstring for alts!?

andras.liter08:11:07

hi guys. I'm using Cursive to develop & debug our Clojure apps, often experimenting things with the REPL. I wonder if there is an efficient way to create datastructures in the REPL sourced from a Debug breakpoint - e.g. if I have a complex datastructure, which I'd like to work with in the REPL as well (to test functions, debug etc...), how can I have a var referencing it the easiest way in the REPL? Of course I dont want to type the whole thing in the REPL, but would like to get the data from an app under- debugging (say I have a breakpoint and the object is there)?

jumar08:11:02

@andras.liter perhaps def? It should be generally avoided inside functions but I guess it's fine for debugging.

;; let's say I want to get `m`
(defn debug-me [x y]
  (let [z (* x y)
        w (Math/pow z x)
        m {:x x
           :y y
           :wz {:z z :w w}}]
    (def d-m m)
    (keys m)))
(debug-me 4 5)
d-m

cfleming08:11:40

@jumar @andras.liter Yes, def should work for this. When stopped at your breakpoint, use Evaluate Expression to do something like: (def test-data-var (my-expr)) - that should work fine.

cfleming08:11:38

I’m actually planning to try to have the REPL work when stopped at a breakpoint, but there’s some trickiness there when the user changes context (i.e. clicks on a higher stack frame)

qqq09:11:54

{:keys [ .... ]} works with unqualified names. Does it also work with qualified names (from other namespaces)? intuition says no, since there could be more than one match, and there's no obvious way which to pick.

andras.liter09:11:03

thanks for the responses @jumar @cfleming @qqq Indeed, def can be used - was too obviuos for me to find it 🙂

genRaiy12:11:27

hello folks - just wondering if I can dip into the hive mind for five mins
.

genRaiy12:11:54

I want to use a resource and have it clean up 
. like with-open

genRaiy12:11:20

but the resource has a shutdown method rather than a close method

genRaiy12:11:42

do I make my own or is there a more idiomatic alternative?

joost-diepenmaat13:11:23

@raymcdermott we use a custom macro like this:

joost-diepenmaat13:11:56

and then something like (with-cleanup [r (make-resource) .shutdown] ...)

genRaiy13:11:53

For the moment I just copied / pasted with-open

genRaiy13:11:23

but yours is nicer as the method can be varied

joost-diepenmaat13:11:43

in the end you can also just write out a (let [r (make-resource)] (try .... (finally (.shutdown r))

noisesmith17:11:59

@andras.liter if you might also want to use the data in a regression test, I wrote a library that simplifies stashing the clojure data to disk and re-inflating it to use it in test code

josh.freckleton19:11:40

what are some highly-considered db migration libraries (mysql specific?)

juhoteperi19:11:44

Calling Flyway (Java lib) from Clojure is just a few lines of code

josh.freckleton19:11:26

good point, I always forget I can reach for java 🙂

juhoteperi19:11:44

Calling Flyway (Java lib) from Clojure is just a few lines of code

rcolyer21:11:44

anybody know if ideaVim, Cursive, and parinfer play well together?

cfleming21:11:28

@rcolyer Mostly, yes. There’s some doc here about problems: https://github.com/cursive-ide/cursive/wiki/IdeaVim-issues

cfleming21:11:37

Certainly there are Cursive users using it, and most seem to consider it more or less EVIL-level emulation.

cfleming21:11:48

I don’t use it myself so I only have hearsay on that though.

rcolyer21:11:02

@cfleming you get parinfer 3.0 ported over yet?

cfleming21:11:45

I have it mostly done, it’s waiting on a couple of outstanding bugs. Shaun was hopefully going to find time to look at them soon. Once they’re fixed it’ll be good to go.

rcolyer21:11:35

IdeaVim seems to have many issues on its own that are frustrating. I can never get certain leader combinations to work properly

cfleming21:11:54

I’m not sure, sorry - I’m not vim-literate myself.

rcolyer21:11:32

they seem to be known issues....I'm resigned to carpal tunnel syndrome on some of the action with some hideous ctrl-alt-shift-....if I just had one more pinkie" combination

lum21:11:04

Hi, this is beginner stuff, an exercise to re-implement boolean: (defn boolean [x] (if (x == "false") false (if (x == "nil") false true)))

lum21:11:32

user> (boolean "asd") java.lang.ClassCastException: java.lang.String cannot be cast to clojure.lang.IFn

lum21:11:42

can't understand what's wrong

mccraigmccraig21:11:57

@lum assuming you were wanting to output based on string values (cond (= x "false") false (= x "nil") false true)

bostonaholic21:11:02

(x == "false") I think you want (= x "false")

lum21:11:19

ohh, 🙂

bostonaholic21:11:34

depending on what you’re actually testing for

bostonaholic21:11:51

the string false or the value false

bostonaholic21:11:23

but, the root cause, (x == "false") is not doing what you think it’s doing

bostonaholic22:11:11

there is a #beginners channel that may be helpful for you

lum22:11:17

yes, this is for the http://mooc.fi course, I'll see how the tests go, but that one was really noob

lum22:11:27

Thanks, and thanks for the suggestion

andy.fingerhut22:11:52

@rcolyer Years ago I bought one of these and have used one for heavy typing ever since -- not cheap, but way cheaper than wrist surgery. Puts most of those modifier keys under your thumbs, and the keys are programmable, too. https://www.kinesis-ergo.com/shop/advantage2/

rcolyer22:11:12

@andy.fingerhut you use footpedals?

andy.fingerhut22:11:29

I have them, but have only used them on occasions when I was transcribing some audio lectures, where i mapped foot pedals to play/pause on the audio. I do use VI key bindings inside of Emacs, too, just to be weird, although there are still plenty of control keys I use too often for my own good.

andy.fingerhut22:11:55

(Sorry, Clojure denizens, we can take this privately if it gets too much longer)