Fork me on GitHub

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:


@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!

👍 4
Digital Baboon12:09:09

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.


can someone give me a minimal working example how i can stream data to a local port?


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."
  (println x "Hello, World!"))

(defn foobar
  (+ 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")


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.

👍 4

Thanks everyone for your kind replies and patience in helping 🙂


@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.


I'll get on it 🙂 Thank's too Sean, I've asked the question in #calva-dev


@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.

✔️ 4

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.


Mystery solved 🙂


Thanks again everyone! 🙂


@dharrigan Great! Thanks for reporting back on the Calva! I'll try remember that next time I play with VSC.

Denis G21:09:50

how to get value from map with default value if nil?


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

Denis G21:09:58

(fnil get default-val) ?


no, because that replaces a nil map


I’d so something like

user=> (get {:a 1} :not-there :not-found)


(or (...) default-val)

Denis G21:09:42

i see, thanks 😅


[ ({} :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


ah i see 🙂


(depends what they really need - replacing nil or replacing a value that wasn't found)


oh you mean distinguishing between a found-nil and a not-there-at-all


may I never write code that needs to do that 🙂


user=> ({:foo nil} :foo :not-found)
- I was taking "replace nil" literally - maybe more literal than needed


Is there a more succinct way to write this?

(if-some [x (:a {:a false})]


((fnil identity :default) (:a m)) ? - not sure I like it


you could give (fnil identity %) a nice name


Ahh nice pattern…


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: 
  (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)