Fork me on GitHub
#clojurescript
<
2015-11-22
>
dnolen00:11:25

a detailed explanation of how Om Next remotes work - demonstrates where core.async is actually useful

dnolen00:11:44

and shows how components can be incredibly declarative, no control logic gunk simple_smile

danmidwood03:11:24

Is there something that someone can point me to that gives me a concise explanation of the difference between om and om.next? (in my case..: I'm fairly fluent in react, and I've basic usage of om, but I'm completely out of date on the current developments)

noonian03:11:11

There is an #C06DT2YSY channel just fyi. Om next is more of a framework than Om now. It incorporates ideas from Netflix’s Falcor and Facebook’s Relay libraries and tries to provide a complete solution for managing syncing data between the client and the server.

danmidwood03:11:03

Ah, I didn't realise it had its own channel. I think you've given me enough of a base to not-so-blindly start looking into it myself, thanks

noonian03:11:18

have you seen some of David’s talks?

danmidwood03:11:41

Not since the first releases

danmidwood03:11:37

If there's an Om next talk that you'd recommend then link me and I'll watch it

danmidwood03:11:49

Otherwise, I can alway google simple_smile

noonian03:11:52

His recent talk from the conj is probably a great place to start to get an idea of where he’s coming from. The docs are sparse and things are moving fast right now.

danmidwood03:11:41

Awesome, thank you very much 😄

wildermuthn08:11:07

I’m excited about a macro I’ve experimented with tonight, and want to share how it is helping me to understand FP. It’s very similar to letfn, but focuses on syntactic sugar rather than mutual recursion, relying upon function literals #():

wildermuthn08:11:05

(let# [life (+ 4 %)
       universe (* % 10)
       everything (-> % inc inc)]
  (-> 0 life universe everything))

wildermuthn08:11:11

It’s just a wrapper of a macro, but I’ve found that let puts me in an imperative mindset, and let# puts me in a functional mindset. As I refactored three or four functions with the macro, I found patters in my usage of let. Then I found patterns within those patterns. Eventually, my functions became small and discrete, resembling those lego-block pieces I’ve always thought FP would lead me to, but could never quite get to!

thheller08:11:57

(let [life #(+ 4 %)
       universe #(* % 10)
       everything #(-> % inc inc)]
  (-> 0 life universe everything))

thheller08:11:26

@wildermuthn: if you write it like this you are not restricted to using functions 😛

wildermuthn08:11:55

Ah! But that’s what I found so helpful. I was forced to write functions, and it was easier to do so too.

borkdude09:11:57

@wildermuthn: there's also letfn:

(letfn [(life [x] (* 4 x))
        (universe [x] (* 10 x))] 
  (-> 5 life universe)) ;; 200

wildermuthn17:11:48

@borkdude, thanks! I did start out using letfn, but found the extra parens and required params to too much overhead. I tried @thheller’s model next, but I found the code too messy and the typing of # onerous. A little bit of syntactic sugar helps me to focus on the purity of composing functions. But that’s me! simple_smile

borkdude18:11:18

@wildermuthn: take note that the first rule of macro club is: don't write macros

wildermuthn18:11:17

@borkdude, have to disagree with the conventional wisdom there. If that was true, we’d wouldn’t have let, if-let, when-let, letfn, etc. I’m on board with reader macros being toxic to the ecosystem, but I think it’s good to experiment. For me, that’s one of the best parts about lisp. I think conventional thinking is better left to conventional languages.

dnolen18:11:58

letfn isn’t a macro, special form

borkdude18:11:05

@wildermuthn: sure, as a mind-expanding exercise, it's cool 😉

dnolen18:11:13

and @borkdude advice holds simple_smile

borkdude18:11:16

I usually don't even use letfn, because I have to look up the syntax. let usually does the job just fine

wildermuthn18:11:05

I come from a common lisp background, so I might be biased! simple_smile

dnolen18:11:35

you see macro overuse in nearly every lisp

dnolen18:11:46

Common Lisp, Clojure & Scheme are not exceptions to the rule

borkdude18:11:36

@wildermuthn: I think in Clojure there is a shift from macros towards data. For example, some routing libraries use macros to define routes, but as time went on people understood that expression those routes using just data was a better idea.

borkdude18:11:56

so: functions + data > macros

borkdude18:11:27

One of the problems with macros is that they don't compose (can't take the value of a macro)

wildermuthn18:11:32

@dnolen, @borkdude, no disagreement here, on either overuse or with using data when possible. But I’m happy to use small simple macros that make my life easier. I get into trouble when I make big complex macros that only seem to do so.

dnolen18:11:53

right the tradeoff is just whether it’s important that other people can read the code

dnolen18:11:03

this may or may not matter depending on what you are doing

dnolen18:11:23

but it’s the reason I don’t bother with little sugar-y macros anymore

dnolen18:11:29

only boilerplate removal or “serious” macros

wildermuthn18:11:48

I can see going down a rabbit-hole with sugar-y macros.

dnolen18:11:59

and by boilerplate I mean “serious automated code generation"

borkdude18:11:59

In my experience, macros mostly come from libraries (clojure.core, core.async -> go, etc), but as a consumer of those libraries I don't have many occasions when I really need to roll my own.

darwin18:11:22

is there some cljs.core helper to convert a seq into an JS array? clj->js is not a good fit, because I don’t want a deep conversion

darwin18:11:25

need to do that dynamically, writing some other macros which depend on .apply 😉

borkdude18:11:43

@darwin: what about (apply array [{:foo "bar"} {:bar "baz"}])?

darwin18:11:29

@borkdude: won’t work, array is a macro

borkdude18:11:50

I just tested it here and it worked. http://clojurescript.net/

darwin18:11:55

@borkdude: you are right, interesting, I will try it, thanks

darwin18:11:53

I looked in the cljs.core sources and I saw "core/defmacro array …”, am I missing some other version which is a function? or why this works?

borkdude18:11:21

@darwin: I see that there is also an into-array function

darwin18:11:05

@borkdude: that’s the one I was looking for

borkdude18:11:34

@darwin: and also to-array simple_smile

darwin18:11:22

@borkdude: now it makes more sense I got puzzled because intellij started showing me clojure sources, not clojurescripts’s while I was writing macros, that’s why I wasn’t able to find anything familiar

darwin18:11:32

I knew there was something

borkdude18:11:03

I love the docstring of to-array: "Naive impl of to-array as a start."

borkdude18:11:27

@darwin: what is a nice feature from the cljs repl, try (apropos "array")

dnolen18:11:56

@darwin macros live in a different namespace

dnolen18:11:21

most people are confused and don’t realize ClojureScript has a unique macro system that is very different from Clojure's

dnolen18:11:34

macros and vars live in different namespaces

dnolen18:11:44

this means you can have a macro array and a function array

dnolen18:11:49

this is impossible in Clojure

dnolen18:11:41

this is how we do inlining for many operations, arithmetic, array construction etc.

darwin18:11:06

@dnolen: thanks for explanation, so when I have both macro and function with the same name, how compiler knows which one to use? it tries macro first? in case of apply macro cannot be used, so it uses function instead?

dnolen18:11:40

macros only work if they are the first element of the form

dnolen18:11:48

(apply array …)

dnolen18:11:54

clearly won’t match

darwin18:11:51

aha, so apply works with macros, they just cannot be passed as parameters, makes sense, now. I thought macros and apply does not work at all

borkdude18:11:09

so, (source array) could have returned the source for the array macro as well

borkdude18:11:42

@darwin: in the case of apply, I think the first argument always has to be a function

darwin19:11:45

ok, have to go, will think about it more

dnolen19:11:30

no apply doesn’t work with macros simple_smile

dnolen19:11:50

(apply array …) invokes the array function at runtime.

dnolen19:11:24

the array function and array macro shall never meet.

nasser19:11:51

hi all! just pushed out my node/npm clojurescript package https://www.npmjs.com/package/clojurescript

nasser19:11:37

i am really excited to use clojurescript in node-only environments, like Electron or embedded platforms, and this is a first step in that direction

nasser19:11:55

open to feedback, bug reports, and pull requests! have at it!

wildermuthn20:11:10

@nasser: Nice!! Trying it out

richiardiandrea20:11:13

replumb candidate 😄

wildermuthn20:11:23

@nasser, this is really exciting for getting ClojureScript apps distributed via npm!