This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-09-27
Channels
- # beginners (54)
- # bitcoin (2)
- # boot (1)
- # calva (10)
- # cider (30)
- # cljs-dev (25)
- # cljsrn (17)
- # clojure (27)
- # clojure-dev (16)
- # clojure-estonia (3)
- # clojure-hk (1)
- # clojure-italy (8)
- # clojure-losangeles (1)
- # clojure-nl (17)
- # clojure-russia (1)
- # clojure-spec (15)
- # clojure-uk (45)
- # clojurebridge (1)
- # clojurescript (95)
- # clojurescript-ios (1)
- # core-async (5)
- # cursive (10)
- # datomic (8)
- # emacs (2)
- # figwheel-main (31)
- # fulcro (99)
- # hyperfiddle (3)
- # immutant (1)
- # jobs (13)
- # jobs-discuss (82)
- # keechma (6)
- # leiningen (3)
- # lumo (1)
- # nrepl (1)
- # off-topic (37)
- # onyx (1)
- # pedestal (6)
- # re-frame (7)
- # reitit (2)
- # remote-jobs (1)
- # ring-swagger (3)
- # rum (6)
- # shadow-cljs (14)
- # specter (4)
- # tools-deps (27)
- # yada (12)
Hello good people. We have web app that uses sente for real-time communication. We are planning on making android app that does the same job is it possible to include and use sente as java jar or in android app without clojure overhead? is there a android implementation of sente protocol that can be used out of the box in android development?
The answer is probably: Sente is Clojure, so running it without loading Clojure wouldn’t work. Maybe in the future #graalvm might have an answer to this, but as far as I know, it can’t cross-compile to Android yet. I’m not aware of any straight up Java libraries that can act as a Sente client. But that doesn’t mean it would be impossible to build one. Sente seems to use Transit for its on-wire protocol, and there is a Transit Java library: https://github.com/cognitect/transit-java
@U06B8J0AJ your answer is greatly appreciated! cause of time restriction if writing sente client for android takes too much time we will manage something if not - we will make one and share it with community!
So far today I've managed to learn how to update component on atom change, which finally allows me to actually pull in data from remote source and display it. I'm quite excited about this. Next up: sending data back / updating data.
If anyone is using Visual Studio Code + Calva extension, I have a question, little unsure why I'm not getting the result I expect. I have a stupid little hello world program that with the repl gives me the result I expect, but in VS + Calva, I'm getting "nil". Perhaps I'm not evaluating it correctly. I wonder if someone can help?
(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
(defn foobar
[x]
(+ x 3))
(foo (foobar 20))
On the repl, I get "23 Hello, World!", but with VSC and "ctrl+alt+v, e" I get "nil"
@dharrigan print
and println
always evaluate to nil
. The "23 Hello, World!" you saw was the side effect and not the evaluation result.
VS + Calva doesn't seem to show you the side effects and only show you the evaluation result, which is nil
This is my repl:
user=> (println "ggwp")
ggwp
nil
user=>
The nil
is the evaluation result, and the "ggwp" is the side effect
Thank you! Is the repl being too "generous" in showing a side effect? I seem to recall having side-effects is a "bad thing(tm)" with functional languages?
A program with no side-effects has only one side effect. It makes the computer hot. Does nothing interesting, or useful. The statically typed FP langs tend to dance around side-effects, by wrapping them in monads allowing you to keep your functions pure. Clojure on the other hand, embraces side effects.
Having side effects sprinkled all over your program drastically increases complexity though (especially in testing it).
@dharrigan I'm a bit surprised Calva doesn't also show the stdout (printed stuff) somewhere. Maybe pop into #calva-dev and ask them about it? I only tried Calva/VSC very briefly and don't remember that issue.
@dharrigan I'm a beginner myself so what I said above might not be the clojure philosophy. I'd highly encourage you to watch Rich Hickey's conversation with Brian Beckman, especially if you're unfamiliar with lisps.
@jaihindh.reddy I believe the Clojure philosophy is definitely to allow and support side effects, but to encourage moving that to the "edges" of systems/code bases as much as you can, with as many pure functions for implementing the majority of your logic as you can. Nothing in the language enforces that -- it is strong system design advice, and Clojure makes it easy to write pure functions with immutable data by default.
Yeah, clojure does make it really easy to keep most code pure but doesn't restrict one from doing so. I did feel embraces side effects was a bit too strong.
@seancorfield Pez has replied in the #calva-dev, the output can be seen in "Calva says" console. To quote Pez
The inline evaluation shows the result of the evaluation, which is `nil` in this case.
@dharrigan Great! Thanks for reporting back on the Calva! I'll try remember that next time I play with VSC.
get takes an optional arg (also keywords and maps do as well, working the same way)
that's if not found, not if nil though
no, because that replaces a nil map
(or (...) default-val)
[ ({} :k :default) (:k {} :default) (get {} :k :default)]
all of these return :default
right - but none of them explicitly replace a nil - only replace a not-found
(depends what they really need - replacing nil or replacing a value that wasn't found)
right
user=> ({:foo nil} :foo :not-found)
nil
- I was taking "replace nil" literally - maybe more literal than needed((fnil identity :default) (:a m))
? - not sure I like it
you could give (fnil identity %)
a nice name
maybe there should be a function like or
but explicitly for nil
does anyone know if a function exists like cond, but all of the parameters are functions? I see patterns like the following pretty frequently, and have wondered if anyone has a good solution to it.
The pattern:
(cond
(f1 x) (b1 x)
(f2 x) (b2 x)
...
(fn x) (bn x))
(if (f x)
(b x)
(else x))
(when (f x)
(b x))
I'm imagining something like:
(f x f1 b1 f2 b2 ... fn bn)
(f x f b else) ;; an odd number of cases would treat the last arg as the default function
(f x f b) ;; returns nil if no case matches
I've defined a function myself that accomplishes this, but wondering it it already exists elsewhere - or maybe if there'd be interest in putting it in some utility library
@trailcapital condp
can be used (assuming x
is logical true)
(condp #(when (%1 %2) %2) x
f1 :>> b1
f2 :>> b2
...
fn :>> bn)