This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-03
Channels
@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.
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
While searching for "Java gui animations" I bumped into https://github.com/kirill-grouchnikov/radiance, which is what prompted my question here
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
(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)
The defold game UI is built in Clojure with JavaFx and there are some talks about it
And REBL of course :)
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?
This weekend's folly is, trying to write code for a microcontroller in CLJS via the johnny-five JS library
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], ...}
IIRC That translates to
(def five (js/require "johnny-five"))
(def board (new (.-Board five)))
hmm, those keywords are really strings, aren't they: (aget j5 "Board")
=> #object[Board]
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
.
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)
there are soooo many places this could be going wrong 🙂 --- is this a correct translation?
I would probably do something like this:
(defn led [x]
(let [Led (.-Led j5)]
(Led. x)))
(def my-led (led 13))
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)))
.
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
if you call them as just a normal function, things can go awry and you might not know why
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 🙂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.
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.
reduce
takes a function and a collection, and it calls the function you give it for each item in the collection
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.
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)
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 🙂
hard to say which is more performant since in practice they are used for such different things
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
could be. sometimes you can use them the same if the function you’re using (like +
) is variadic (takes any number of args)
while traversing a sequence in some fn
how can I refer to an element next to current %
?
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.
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)))
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.
something like this would be awesome: https://marketplace.visualstudio.com/items?itemName=serayuzgur.crates
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?
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.
"RELEASE" sounds like it will fit perfectly for just messing around with various tutorials and such. thank you!
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"
So you have lein-ancient
, boot-deps
, or clj depot
, but I’m always looking for a repo with CHANGELOG.md
anyway 🙂
@sy_borg this can be dangerous as the build depends on the point in time when it happened.
I mean, in the future “LATEST” can resolve to a different, incompatible revision.