Fork me on GitHub
#beginners
<
2018-09-27
>
lepistane11:09:37

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?

henrik11:09:55

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

lepistane11:09:41

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

👍 1
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.

nifflor13:09:59

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

dharrigan19:09:08

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?

dharrigan19:09:28

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))

(defn foobar
  [x]
  (+ x 3))

(foo (foobar 20))

dharrigan19:09:20

On the repl, I get "23 Hello, World!", but with VSC and "ctrl+alt+v, e" I get "nil"

jaihindhreddy19:09:41

@dharrigan print and println always evaluate to nil. The "23 Hello, World!" you saw was the side effect and not the evaluation result.

jaihindhreddy19:09:11

VS + Calva doesn't seem to show you the side effects and only show you the evaluation result, which is nil

jaihindhreddy19:09:42

This is my repl:

user=> (println "ggwp")
ggwp
nil
user=> 

jaihindhreddy19:09:59

The nil is the evaluation result, and the "ggwp" is the side effect

dharrigan19:09:12

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?

jaihindhreddy19:09:42

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.

jaihindhreddy19:09:54

Having side effects sprinkled all over your program drastically increases complexity though (especially in testing it).

seancorfield19:09:13

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

👍 1
dharrigan19:09:32

Thanks everyone for your kind replies and patience in helping 🙂

jaihindhreddy19:09:36

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

dharrigan19:09:31

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

andy.fingerhut19:09:32

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

✔️ 1
jaihindhreddy19:09:05

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.

dharrigan20:09:57

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

dharrigan20:09:13

Mystery solved 🙂

dharrigan20:09:20

Thanks again everyone! 🙂

seancorfield20:09:51

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

noisesmith21:09:28

get takes an optional arg (also keywords and maps do as well, working the same way)

noisesmith21:09:45

that's if not found, not if nil though

Denis G21:09:58

(fnil get default-val) ?

noisesmith21:09:13

no, because that replaces a nil map

justinlee21:09:15

I’d so something like

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

noisesmith21:09:20

(or (...) default-val)

Denis G21:09:42

i see, thanks 😅

dpsutton21:09:57

[ ({} :k :default) (:k {} :default) (get {} :k :default)] all of these return :default

noisesmith21:09:21

right - but none of them explicitly replace a nil - only replace a not-found

dpsutton21:09:37

ah i see 🙂

noisesmith21:09:45

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

justinlee21:09:54

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

justinlee21:09:11

may I never write code that needs to do that 🙂

noisesmith21:09:55

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

mfikes21:09:39

Is there a more succinct way to write this?

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

noisesmith21:09:01

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

noisesmith21:09:26

you could give (fnil identity %) a nice name

mfikes21:09:17

Ahh nice pattern…

noisesmith21:09:41

maybe there should be a function like or but explicitly for nil

enforser23:09:06

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

enforser23:09:21

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

mfikes23:09:05

@trailcapital condp can be used (assuming x is logical true)

(condp #(when (%1 %2) %2) x
  f1 :>> b1
  f2 :>> b2
  ...
  fn :>> bn)