clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Luan 2021-01-19T02:45:20.072Z

Hello, have anyone here used iframe with two apps? I was trying to make this communication with postMessage, I tried to use https://github.com/jogrms/messenger but with no success I followed the docs and received this message: <tg://search_hashtag?hashtag=object|#object>[cljs.core.async.impl.channels.ManyToManyChannel] when I ran the command to send message but got no response on browser. Is there anything I can do to debug this problem? Or another way to solve this?

tomrbowden 2021-01-19T06:13:07.076200Z

I am confused about the differences between Special Forms in Clojure and ClojureScript. While the ClojureScript docs at <https://clojurescript.org/about/differences><https://clojurescript.org/about/differences%60|> state that:

The following ClojureScript special forms are identical to their Clojure cousins: if, do, let, letfn, quote, loop, recur, throw, and try.
… I have found via (doc let) in a ClojureScript REPL, that let is a Macro:
cljs.user=&gt; (doc let)
-------------------------
cljs.core/let
([bindings &amp; body])
Macro
 binding =&gt; binding-form init-expr

 Evaluates the exprs in a lexical context in which the symbols in
 the binding-forms are bound to their respective init-exprs or parts
 therein.
nil
The same seems to apply to letfn and loop as well. Can anyone here shed some light on this, please?

seancorfield 2021-01-19T06:18:43.076900Z

That should probably be considered an implementation detail. If you look at the source of let in Clojure it is also a macro:

dev=&gt; (source let)
(defmacro let
  "binding =&gt; binding-form init-expr

  Evaluates the exprs in a lexical context in which the symbols in
  the binding-forms are bound to their respective init-exprs or parts
  therein."
  {:added "1.0", :special-form true, :forms '[(let [bindings*] exprs*)]}
  [bindings &amp; body]
  (assert-args
     (vector? bindings) "a vector for its binding"
     (even? (count bindings)) "an even number of forms in binding vector")
  `(let* ~(destructure bindings) ~@body))

seancorfield 2021-01-19T06:19:06.077300Z

(even tho' (doc let) says it is a special form)

seancorfield 2021-01-19T06:20:30.078Z

letfn and loop are both macros in Clojure but, again, consider that an implementation detail -- and treat them as if they really are special forms.

tomrbowden 2021-01-19T06:24:27.080500Z

@seancorfield Thank you for that. I guess my understanding of what constitutes a Special Form is a little misguided then — I took them to be “primitives” with different-from-usual Clojure evaluation rules, that could not be defined in terms of other primitives. 😕

tomrbowden 2021-01-19T06:40:42.082300Z

Digging a little more, it seems that there is a function called special-symbol? which says if a symbol is a Special Form, and via a Clojure REPL, I found the following interesting fact:

user=&gt; (special-symbol? 'let)
false
user=&gt; (special-symbol? 'let*)
true
So let* is a Special Form, and let is implemented as a Macro. I will probably need to go and read the source at <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java>

dpsutton 2021-01-19T07:08:36.082600Z

it's not that they can't be defined in terms of other primitives, its that they aren't so defined. In a simple lisp this might be true for ease of construction but there's certainly no reason that when and if couldn't both be special forms. Also, its common for let to be a macro that expands to a closure invoked on the binding values but that can be quite slow in practice.

tomrbowden 2021-01-19T07:34:31.083500Z

Thank you for the clarification. That makes sense now.

maleghast 2021-01-19T10:25:03.085800Z

Morning everyone 🙂 I was just idly wondering what UI Libraries people are tending to go for with their Reagent / ReFrame apps these days, with options like ChakraUI, MaterialUI etc. gaining so much interest and support in the vanillaJS and TypeScript worlds I was keen to figure out what the CLJS “new hotness” is or might be and how much consensus there is on such things..?

msolli 2021-01-21T06:28:29.022Z

I second Bulma - it’s a lovely thing if you don’t want to write any CSS, just use the classes and HTML structure they prescribe. It’s also JS-free, which is a plus. I’m too looking into Tailwind, though, for more control.

RollACaster 2021-01-19T10:34:10.086Z

I am huge fan of https://tailwindcss.com/ because composing tailwind classes feels a bit like composing fns from clojure.core but I don’t think it’s really a “new hotness” and did not see another CLJS project using it yet.

p-himik 2021-01-19T10:34:25.086400Z

I'm pretty content with Material-UI and I use re-com for a couple of projects.

maleghast 2021-01-19T10:36:02.086600Z

Thanks very much for the feedback - will add Tailwind to my research list for sure.

simongray 2021-01-19T10:39:13.086800Z

I am in the process of (slowly) developing my own, mostly for my own purposes: https://github.com/kuhumcst/stucco

maleghast 2021-01-19T10:43:51.087200Z

That is an interesting angle as well @simongray - thx 🙂

simongray 2021-01-19T10:44:13.087400Z

I’m trying to implement some ideas that have been floating in my head for a long time for making a UI toolkit that maps to the shape of Clojure data, that is more declarative in nature, and which can adapt to end user needs in various ways. At this point, it’s quite experimental, so I’m mostly just trying to see which directions I can take it in and how doable these things are in practice.

maleghast 2021-01-19T10:49:15.087600Z

nods - An interesting set of challenges for sure 🙂

flowthing 2021-01-19T11:04:52.087800Z

I've used Bulma in a couple of projects and been quite happy with it. I'd definitely look at something like Tailwind or Tachyons for a new project. I currently work on a project with 8000 lines of Clojure(Script) code, and it has 48 lines of SASS, most of which could possibly be removed. It really is a bliss not to have to maintain CSS separately.

maleghast 2021-01-19T11:26:25.088Z

🙂. Thanks @flowthing

takis_ 2021-01-19T14:45:17.088800Z

Hello i read that clojurescript has no :use ,i want to import all the names from a dsl. I can use (require :refer ) by hand or auto-generated. By hand its too many even if copy paste doesnt look nice,and auto-generated the IDE cant resolve the symbols. Any solution to auto-import the names,and visible to the IDE?

p-himik 2021-01-19T14:49:57.089Z

I'd been looking into it quite some time ago back when I was using Specter with CLJS. I ended up settling on (:require [com.rpl.specter :as s]) and using s/ namespace everywhere. In the end, I liked it enough to actually start using it in CLJ instead of :use.

takis_ 2021-01-19T14:51:06.089200Z

thank you for the reply, but its not nice if nested calls 😞

takis_ 2021-01-19T14:51:21.089400Z

and my dsl will have so many nested calls

p-himik 2021-01-19T14:52:51.089600Z

In this case, you could write a macro that just transforms all call-like forms like (do-stuff ...) into (my-full-ns/do-stuff ...). You would still have to require my-full-ns though.

takis_ 2021-01-19T14:55:39.089800Z

i dont know how to do that easily,my macro should have to find each call and rename it in the code

takis_ 2021-01-19T14:56:01.090Z

nested calls or even (apply myf ....) even harder

takis_ 2021-01-19T14:56:48.090200Z

copy paste by hand i think i will go for now if no other solution ,and see in the future

p-himik 2021-01-19T14:58:09.090600Z

That's just an opportunity to learn then. :) Your macro will have to wrap every top-level call to you library. So e.g. something like

(my-lib/do
  (my-lib/more
    (my-lib/stuff args)))
could become
(my-lib/do
  (more
    (stuff args)))
(you'll just have to make sure to not use any names that are used by Clojure, like map and filter and whatnot).

takis_ 2021-01-19T15:01:40.090800Z

thank you for your idea, i will save it as option,and when i solve bigger problems , i will re-check it

👍 1
Lauri Rutanen 2021-01-19T18:59:38.094100Z

What is the typical way to structure a minimalistic project containing backend + frontend in one repository? Should I have separate entrypoints for frontend and backend?

Lauri Rutanen 2021-01-20T19:16:40.136800Z

Thanks for answers! Based on your answers, I think I'll go with: • separate deps for frontend and backend (no shared) • frontend and backend have clean separation (ie. can be started/stopped separately, code & deps separated)

Fredrik Andersson 2021-01-19T19:19:05.096500Z

I wonder how to "find" a entry in a array (vector?) by a value of a field in the entry

Fredrik Andersson 2021-01-19T19:19:47.097300Z

in javascript i would write something like myarray.find(itm => itm.name === "hello")

2021-01-19T19:23:39.097900Z

In Clojure (first (filter predicate-function-here my-vector)) would do it.

Fredrik Andersson 2021-01-19T19:24:05.098600Z

ah, didn't think about it that way

2021-01-19T19:24:08.098800Z

e.g. (first (filter #(= (:name %) "hello") my-vector))

Fredrik Andersson 2021-01-19T19:24:17.099Z

thanks!

Fredrik Andersson 2021-01-19T19:24:57.100Z

trying to get used to clojurescript little by little 🙂

2021-01-19T19:25:51.101Z

And in case you are wondering, filter returns a lazy sequence, so while it might in some cases (due to a performance optimization called 'chunking') call the function on a few elements of my-vector after the first one that returns true, it will stop very soon after the first matching element.

Fredrik Andersson 2021-01-19T19:26:31.101400Z

ahh

p-himik 2021-01-19T21:35:00.101800Z

If by entrypoints you mean directories in your src, then I'd say no.

clyfe 2021-01-19T21:47:57.102Z

1 git repo, 3 folders (1 for versions), 3 deps.edn (1 is versions); shared deps https://ask.clojure.org/index.php/9849/teams-common-dependencies-tooling-across-multiple-projects

p-himik 2021-01-19T22:01:09.102400Z

FWIW I would say that it would be quite a complexity increase for what I perceive as a "minimalistic full-stack project". :)