Fork me on GitHub
#beginners
<
2017-06-07
>
Alex Miller (Clojure team)00:06:02

some other options to consider: JavaFX (there are a couple Clojure wrappers), Swing (Seesaw), Vaadin (functional-vaadin)

zlrth05:06:32

I have a list of maps:

({:name "cash", :newamount 12500/3} {:name "cash", :newamount 500} {:name "vanguard", :newamount 500} {:name "house", :newamount 0})
and for each :name that’s the same, i’d like to add the :newamounts together. so the output should be
({:name "cash", :newamount 14000/3} {:name "vanguard", :newamount 500} {:name "house", :newamount 0})
i’ve been futzing around with merge and merge-with and i can’t get it right. i also have a suspicion i should be using reduce. something like ben ashford’s group-by-better: http://benashford.github.io/blog/2014/12/27/group-by-and-transducers/

danlebrero07:06:17

@mfm I think you want to group-by :name and then reduce each group

sb08:06:44

Guys, could you help me how to learn easy .. integrate Java SDK to Clojure? (I don’t have java dev background)

sb08:06:02

Where are great docs for this?

danlebrero08:06:44

@sb what do you mean by integrate?

sb08:06:16

Where is no Clojure SDK or similar.. or too hard to dev.

hansen-pansen08:06:07

@sb Accessing Java from Clojure is really nice. You can find good starting points here https://clojure.org/reference/java_interop and here http://www.braveclojure.com/java/

sb08:06:50

thanks @hansen-pansen I see that will be more time than I thought to understand fully. I will test it.

john13:06:59

@sb, you need to make sure that Clojure can see Java. You should be able to install Java SDK from sun and then it should be available on your PATH. The Clojure should be able to see it (java) when you run Clojure.

noisesmith16:06:57

john: this reply makes no sense to me at all. Clojure is a java library that creates and executes byte code, if clojure is running it has access to java directly.

john16:06:06

When I hear sb say "integrate Java SDK to Clojure," I imagine he or she has downloaded the clojure.jar (or something similar) and has now also downloaded the Java SDK and now he or she doesn't know how to proceed.

john16:06:05

I suppose the last sentence doesn't make sense though lol

john16:06:27

lein needs to be able to find your java/bin folder somewhere

john16:06:43

clojure.jar won't even run if some java isn't on your path

john16:06:26

But in general, I was thinking perhaps sb wasn't even as far along as thinking about interop. Hard to tell though.

sb16:06:16

Sorry Guys I would like to integrate a solution (like Skype Java SDK) to Clojure

sb16:06:46

Means where is not clojure repository or no rest API

sb16:06:31

So I need to download the java things and drop in the project.clj the path and I try to drop to core.clj .. like import (?)

sb16:06:08

That is the main question how to understand the java specification and implement in clojure

sb16:06:46

Where is a great tutorial for beginners in java? Book good too

john16:06:52

You want a solution where you can deploy both your clojure app and it's java dependency to your users?

noisesmith16:06:36

the easier way to do it is to make a Skype SDK project and add clojure.jar as a dep

sb16:06:41

Yes, how to use eg Skype bot java sdk like dependency

noisesmith16:06:44

because clojure works standalone, and it’s an easy lib to use

noisesmith16:06:12

I’d skip lein for this actually, just use clojure.jar as a dep in your java project

noisesmith16:06:40

it’s a lot less headache than using skype from lein would be

sb16:06:58

Ok, in this case I need to learn java if I understand good

sb16:06:28

For use advanced .. clojure

john16:06:34

I've never heard of this. A Java SDK for writing Skype bots?

noisesmith16:06:39

at least a little - it’s easy to put clojure into a java project and do most of the work into clojure code though

sb16:06:05

Phyton, nodejs, java lib for dev bots

sb16:06:22

That is just an example

noisesmith16:06:58

this shows how to use clojure from java, it’s very easy - just use Var to get require, and require to get your code https://clojure.org/reference/java_interop#_calling_clojure_from_java

sb16:06:05

Ok I try to do, learn this @noisesmith

fingertoe16:06:27

So if I want a function to run continuously in another thread until I stop it, is future and future-cancel the proper way to do this, or is there another more proper way?

ghadi16:06:53

@fingertoe if your continuous operation is in the shape of a loop, you should check for a cancellation signal before processing the next item

ghadi16:06:45

@fingertoe future cancellation is not guaranteed... you can't really stop threads in java anymore, you can Thread.interrupt() them tho

noisesmith16:06:06

@vitruvia all the args but the last return functions

ghadi16:06:42

It's best to use a queue and check for a sentinel STOP/POISON item, or read a shared global stop flag / core.async channel

noisesmith16:06:49

@ghadi agreed with the caveat that sleep and IO are both interruptable, so in practice I’ve had good luck stopping threads from the outside as long as they stop for io or call Thread/sleep. This comes up in particular for me when using core.async thread to run something that I might want to consider timed out if the IO takes too long

ghadi16:06:08

but you're not calling Thread.stop() are you?

noisesmith16:06:30

no, I’m cancelling the thread, and counting on it calling a cancellable method

noisesmith16:06:33

(well, future task, not thread etc.)

ghadi16:06:53

👌 future.cancel(mayInterrupt) <- will interrupt a thread in interruptible methods (I/O, sleep etc.)

ghadi16:06:16

but -- it also screws up core.async channel locks

noisesmith16:06:31

oh - even if called on something outside a go block?

ghadi16:06:15

i mean if you interrupt an (async/thread) you might do it at a catastrophic time

ghadi16:06:05

e.g. when it's interacting with a channel handler

vitruvia16:06:12

@noisesmith I'm not sure what you mean. more is supposed to be a list of predicates and other-preds should take these predicates and turn them into functions according to its definiton

noisesmith16:06:50

but your reduce returns either x or nil

noisesmith16:06:04

nil isn’t a function, and I’m not certain x is a function?

noisesmith16:06:58

the reduce function (that is, other-preds)should have another function inside

vitruvia16:06:59

no they arent

noisesmith16:06:03

in order to return a function

vitruvia16:06:00

but I don't want to return a function. I want to return x if the value of pred is true

noisesmith16:06:14

but what your reduce returns is what your function returns

noisesmith16:06:27

all the other branches of the function return functions, but your reduce returns nil or x

noisesmith16:06:32

x may be callable, nil is not

vitruvia16:06:58

I think I get what you mean

vitruvia16:06:09

I'll see what I can do, thanks!

ghadi16:06:25

^ That is a very relevant post for this room

billbarnhill22:06:42

@gonewest818 I have, because of work requirements Electron is out. Not familiar with Reagent. I am hoping to persuade management to use a Web UI, but that won't be for this iteration

billbarnhill22:06:06

@alexmiller Thanks, will check out Vaadin. What I have working so far is straight JavaFX, but would love more of a wrapper.

Alex Miller (Clojure team)22:06:13

fwiw Rich likes Vaadim and the Datomic Console is written with it

mobileink23:06:04

i note in passing that vaadin's website, like datomic's, is quite mobile-unfriendly. :(

gonewest81823:06:36

also Vaadin produces a web application which doesn’t seem to meet the requirement stated earlier… ?