This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-12-17
Channels
- # adventofcode (33)
- # announcements (1)
- # beginners (32)
- # calva (12)
- # cider (1)
- # clojure (73)
- # clojure-belgium (1)
- # clojure-europe (20)
- # clojure-norway (3)
- # datomic (3)
- # emacs (2)
- # fulcro (18)
- # graphql (11)
- # honeysql (1)
- # juxt (1)
- # lsp (10)
- # membrane (13)
- # reitit (1)
- # releases (5)
- # scittle (15)
- # spacemacs (1)
- # squint (36)
- # testing (1)
- # tools-deps (20)
- # xtdb (5)
https://github.com/squint-cljs/squint: ClojureScript syntax to JavaScript compiler
0.0.1
• Fix +
symbol import by bumping shadow-cljs
• Move @babel/preset-react
dependency to dev dependency
So I'm playing around a bit with squint today, first off I'm really impressed by the speed of development, there are definitely some projects I'm working on that need a lot of js interop where I can see this being a gamechanger, though I understand its still early days... I've gotten a sample project working with auto generated react-query hooks and that worked without basically any issues, though now I am trying to iterate over a list of maps and display them and it doesn't seem to be easy. here's a simplified version of what I'm doing
(defn Comments []
(let [queryResponse {:data {:comments [{:comment "hello"}]}}
comments (:comments (:data queryResponse))]
(js/console.log comments)
#jsx [:div
[:h1 "Comments"]
(for [comment comments]
#jsx [:div
[:h2 (:name comment)]
[:p (:body comment)]])]))
and I get this fairly unreadable output
var Comments = function () {
let queryResponse11 = ({ "data": ({ "comments": [({ "comment": "hello" })] }) });
let comments12 = get(get(queryResponse11, "data"), "comments");
console.log(comments12);
return <div><h1>Comments</h1> {(function () {
let iter__24852__auto__17 = function iter__13 (s__14) {
return new LazySeq(function () {
let s__1418 = s__14;
while(true){
let temp__24658__auto__19 = seq(s__1418);
if (temp__24658__auto__19) {
let s__1420 = temp__24658__auto__19;
if (chunked_seq_QMARK_(s__1420)) {
let c__24838__auto__21 = chunk_first(s__1420);
let size__24840__auto__22 = count(c__24838__auto__21);
let b__1623 = chunk_buffer(size__24840__auto__22);
if (coercive_boolean((function () {
let i__1524 = 0;
while(true){
if ((i__1524 < size__24840__auto__22)) {
let comment25 = _nth(c__24838__auto__21, i__1524);
chunk_append(b__1623, <div><h2>{get(comment25, "name")}</h2> <p>{get(comment25, "body")}</p></div>);
let G__26 = unchecked_inc(i__1524);
i__1524 = G__26;
continue;
} else {
return true;};break;
}
})())) {
return chunk_cons(chunk(b__1623), iter__13(chunk_rest(s__1420)));} else {
return chunk_cons(chunk(b__1623), null);}} else {
let comment27 = first(s__1420);
return cons(<div><h2>{get(comment27, "name")}</h2> <p>{get(comment27, "body")}</p></div>, iter__13(rest(s__1420)));}};break;
}
});
};
return iter__24852__auto__17(comments12);
})()}</div>;
}
;
and the error
@react-refresh:278 Uncaught ReferenceError: chunked_seq_QMARK_ is not defined
at LazySeq.f (App.jsx:30:1)
Hi @UGGU8TSMC Please post long code in a thread or gist :)
We should probably remove the for
macro in squint since that's not ported to squint yet
it basically came from cherry and was left in there but it's expected not to work, so we should remove it
ok sorry about that, will make a thread in the future. I've made an https://github.com/squint-cljs/squint/issues/245, happy to try and learn more about how squint works and maybe help with adding some core functions. I guess you have to implement them all in js?
I got my example working with map
so its not a big deal, but for
is nice and I think I lot of people would want that 🙂
was just wondering if theres some limitation that I don't know about regarding jsx and sequences
Looks like this
(:require ["@mui/material/Box" :as Box])
becomes this
import { } from '@mui/material/Box'
I'm trying to get to
import Box from '@mui/material/Box'
@lilactown @corasaurus-hex I'm running into some trouble with trying to make for
work. One of the things is that the original macro calls (seq ..)
to determine if something has elements or not, to stop a recursion.
But in our case seq
returns the original iterable, when it's not an array or string (or something else with length or size). So (seq (map inc []))
returns a LazyIterable which returns no elements.
I tried fixing it like this: get the iterator from the iterable in the seq implement. Take the next element and check if it's .done
- if yes, return null, else return iter
. But this has the effect that the function that is called to realize the first argument is called twice.
not all lazy sequences are fully realizable as they can be infinite and so can the result of for be
I had one variant so far that just realized the first element twice and another variant which was based on an iterator that you can only realize once (since iterators are stateful)
I think that Clojure basically does the "get the first element and see if it's done" thing, but it caches the values
I'm not familiar with the internals of for
. does it work to have a mutable iterator that it uses internally? I would assume not
well, I think the problem with that is that the result would not be "idempotent" right? yeah, caching seems to be necessary
and perhaps also chunking... like, doing the seq stuff really as like it's done in CLJS more or less
I moved the code temporarily to compiler-common/squint, if you're looking for it. I do want to bring it back to the squint repo, except for the common compiler part, still figuring it out...
I think we could cache just the first element, right? or even just whether it's empty or not