Fork me on GitHub
#beginners
<
2019-02-03
>
reaysawa00:02:31

@seancorfield that was what was linked to me before. I'm interested in achieving a "modern app feel" with screen transitions, toasts, that kind of stuff.

reaysawa00:02:44

I have only done Swing programming in high school for small CRUD apps so I'm totally lost on what's up with Java GUI

reaysawa00:02:53

While searching for "Java gui animations" I bumped into https://github.com/kirill-grouchnikov/radiance, which is what prompted my question here

reaysawa00:02:43

Was wondering if anyone had done a mature/modern GUI application in Clojure

seancorfield00:02:54

I think you'll want to search for javafx clojure and see what you get. Based on searches for javafx and swing, it seems that JavaFX is the modern replacement for Swing @joao.paulo.silvasouza

👍 5
seancorfield00:02:50

(and I don't know that anyone is building GUIs like that with Clojure -- I know Colin Fleming, creator of Cursive, built on IntelliJ, ended up using Kotlin to deal with all the Java interop, instead of Clojure)

Alex Miller (Clojure team)01:02:02

The defold game UI is built in Clojure with JavaFx and there are some talks about it

😃 10
reaysawa05:02:12

thank you very much for the answers : )

Karol Wójcik12:02:02

What is a difference between quoting with vs quoting with '`. As far as I can tell the former allows to use ~ whereas the latter does not. Is there something more I am missing?

dpsutton12:02:57

user> 'a
a
user> `a
user/a

mathpunk17:02:25

This weekend's folly is, trying to write code for a microcontroller in CLJS via the johnny-five JS library

mathpunk17:02:43

I immediately slammed against not knowing the right syntax for this contructor:

mathpunk17:02:56

var five = require("johnny-five");
var board = new five.Board();

mathpunk17:02:45

I can see it in there....

#js {:Accelerometer #object[Accelerometer], :Animation #object[Animation], :Altimeter #object[Altimeter], :Barometer #object[Barometer], :Board #object[Board], :Button #object[Button], ...}

mathpunk17:02:28

(get j5 :Board)
nil
cljs.dev> (aget j5 :Board)
nil
:thinking_face:

madstap17:02:30

IIRC That translates to

(def five (js/require "johnny-five"))
(def board (new (.-Board five)))

mathpunk17:02:14

hmm, those keywords are really strings, aren't they: (aget j5 "Board") => #object[Board]

madstap17:02:38

get is for using with cljs maps {}, not objects #js {}

mathpunk17:02:41

reeeeally fuzzy on the method/property distinction --- what's a . and what's a .-

mathpunk17:02:12

hey, there's a board

mathpunk17:02:54

so new is a function we got lying around. It needs to get called on an object. The object is found by getting the Board property from five.

madstap17:02:54

. is for calling a method, .- is for getting a property

madstap17:02:17

cljs.user=> (def foo #js {:bar (fn [x] (inc x))
       #_=>               :baz "some prop"})
#'cljs.user/foo
cljs.user=> (.bar foo 41)
42
cljs.user=> (.-bar foo)
#object[Function]
cljs.user=> ((.-bar foo) 41)
42
cljs.user=> (.-baz foo)
"some prop"
cljs.user=> (.baz foo)
TypeError: cljs.user.foo.baz is not a function
	 (NO_SOURCE_FILE <eval>:1:0)
	 (NO_SOURCE_FILE <eval>:1:0)
	 (NO_SOURCE_FILE <eval>:1:0)

mathpunk17:02:04

clear enough --- thank you

mathpunk18:02:53

there are soooo many places this could be going wrong 🙂 --- is this a correct translation?

mathpunk18:02:03

js: var led = new five.Led(13);

mathpunk18:02:17

cljs: (def led (new (.-Led j5 13)))

lilactown18:02:16

yep that looks right

lilactown18:02:35

I would probably do something like this:

(defn led [x]
 (let [Led (.-Led j5)]
  (Led. x)))


(def my-led (led 13))

madstap18:02:25

I don't think that's valid cljs (`(def led (new (.-Led j5 13)))`), you can't pass a parameter to a property. What lilactown wrote works, or you could do (def led (new (.Led j5 13))).

lilactown18:02:03

ah yeah. the 13 needs to be inside the new parens

lilactown18:02:13

(def led (new (.-Led j5) 13))

lilactown18:02:59

it’s important in JS that you call constructors with new sometimes. so you’ll want to use either the (new Constructor) form in CLJs or the Constructor. short-hand

lilactown18:02:37

if you call them as just a normal function, things can go awry and you might not know why

mathpunk19:02:47

helpful! but, evidently not where my problem is.

var type = board.pins.type;
                        ^
TypeError: Cannot read property 'type' of null
    at Function.Pins.normalize (/home/man/projects/developing/short-circuit-basic/node_modules/johnny-five/lib/board.pins.js:91:25)
    at Led.Board.Component (/home/man/projects/developing/short-circuit-basic/node_modules/johnny-five/lib/board.js:868:23)
    at new Led (/home/man/projects/developing/short-circuit-basic/node_modules/johnny-five/lib/led/led.js:143:19)
    at Object.<anonymous> (/home/man/projects/developing/short-circuit-basic/out/hello/core.cljs:5:10)
 
I'll probably just open a ticket on the johnny-five repo to see if anyone with a better understanding of how the js -> arduino chain works wants to help with this precarious chain of events 🙂

Chase18:02:37

What is the difference between apply and reduce? I don't know if it's just coincidence but it seems when checking my answers for various exercises I'm seeing these two being used in the same context.

lilactown18:02:04

apply and reduce are quite different

lilactown18:02:45

(apply + [1 2 3 4]) I think of like a syntax transform; it becomes (+ 1 2 3 4)

lilactown18:02:47

it takes whatever function you give it and calls it with the first item in the collection as the first arg, second in the collection as the second arg, etc.

lilactown18:02:30

reduce takes a function and a collection, and it calls the function you give it for each item in the collection

Chase18:02:52

ok, I think I see what you are saying. Thanks. It was just a coincidence that the simple examples I have been seeing result in reduce and apply evaluating to the same thing.

lilactown18:02:07

reduce also is expected to return an “aggregate” value each time you call it. so for instance, if you were going to sum a list like before: (reduce + [1 2 3 4]) this returns the same thing, but what it actually does is: (+ nil 1) (+ 1 2) (+ 3 3) (+ 6 4)

lilactown18:02:38

yeah, depending on the example you pick (like my addition example) they might end up with the same answer, but they are actually used for very different things 🙂

Chase18:02:12

cool. that 'syntax transform' explanation makes it a lot clearer for me.

Chase18:02:34

is one more performant than the other?

lilactown18:02:05

hard to say which is more performant since in practice they are used for such different things

Chase18:02:12

I guess that's not a good question..

Chase18:02:18

exactly. cool. thanks

lilactown18:02:32

sure thing 😄 glad I could help

Chase18:02:52

i'm thinking a lot of clojurians(?) mix it up in their heads too. 4clojure and such have people using one or the other for the exact same application

lilactown18:02:04

could be. sometimes you can use them the same if the function you’re using (like +) is variadic (takes any number of args)

Sy Borg18:02:54

while traversing a sequence in some fn how can I refer to an element next to current %?

Sy Borg18:02:12

I feel like I need to join #absolutebeginners...

dpsutton18:02:31

what do you mean by an element next to current %?

dpsutton18:02:39

are you familiar with %1 and %2, etc?

Sy Borg18:02:12

yes, sorry for confusion caused by %

Sy Borg18:02:57

I'm trying to find consecutive duplicates in a sequence, using loop/recur (there's for sure some more efficient method for this), my initial binding is (loop [a (first s), b (first (next s))], so I'm trying to figure out what bindings to use in recur - (recur b ???). I'm lost a bit.

dpsutton18:02:15

you could just destructure.

(loop [[x x' :as xs] s]
  (do ...)
  (recur (rest xs)))

Sy Borg18:02:38

ah. sure. thanks, Dan

Sy Borg18:02:57

also still can't get rid of "imperative" thinking, and I'm not even a programmer...

dpsutton18:02:12

another way to consider it is to group the elements up with their successive elements.

(let [xs [:a :b :c :d]]
  (map vector xs (rest xs)))

5
Chase18:02:56

so how do you folks find out the latest version of a dependency you want to add? Like say you want to bring in Cheshire. Right now I just search for the respective github and go hunt it down. Any way to automate this? I'm on emacs.

Chase18:02:00

related question: do you always want the latest dependency anyways? Say I'm looking at an old tutorial. Should I just use whatever old dependency they list or use the most recent one?

Chris19:02:56

It depends very much on the particular library. Being up to date might not matter, or it might if the lib has security issues or incompatibility with other things. You can specify the latest release by using “RELEASE” as the version. Not quite what you want for normal development though - you probably want to lock the version down - but good enough for trying our libs.

Chase19:02:08

"RELEASE" sounds like it will fit perfectly for just messing around with various tutorials and such. thank you!

ordnungswidrig20:02:27

There’s lein-ancient:

$ lein ancient
[com.taoensso/timbre "2.6.2"] is available but we use "2.1.2"
[potemkin "0.3.3"] is available but we use "0.3.0"
[pandect "0.3.0"] is available but we use "0.2.3"

pithyless21:02:34

So you have lein-ancient, boot-deps, or clj depot, but I’m always looking for a repo with CHANGELOG.md anyway 🙂

Sy Borg22:02:51

I specify "LATEST" instead of version in project.clj

ordnungswidrig22:02:57

@sy_borg this can be dangerous as the build depends on the point in time when it happened.

ordnungswidrig22:02:26

I mean, in the future “LATEST” can resolve to a different, incompatible revision.

Sy Borg22:02:12

you're right, but for my current (learning) purposes it serves ok

tim21:02:31

@sy_borg you could also track the previous item in your loop binding i.e. (loop [xs [...] last-x nil] ..... (recur (rest xs) x))