This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-08-19
Channels
- # aws (2)
- # babashka (4)
- # babashka-sci-dev (7)
- # beginners (92)
- # biff (7)
- # calva (64)
- # cider (2)
- # cljsrn (14)
- # clojure (8)
- # clojure-australia (5)
- # clojure-europe (14)
- # clojure-norway (8)
- # clojure-spec (36)
- # clojurescript (19)
- # component (15)
- # cursive (1)
- # data-science (6)
- # girouette (5)
- # hyperfiddle (3)
- # juxt (5)
- # leiningen (10)
- # lsp (7)
- # malli (12)
- # nbb (90)
- # polylith (1)
- # portal (11)
- # rdf (7)
- # reagent (6)
- # reitit (40)
- # remote-jobs (1)
- # shadow-cljs (21)
- # specter (5)
- # squint (83)
- # tools-deps (17)
- # vim (7)
Hello Everyone, are there any plans to support list
in clavasript.
it could either be a JS Array or a new custom type.
I think an array makes sense, but it would be nice to be able to distinguish between lists and "vecs" / arrays since e.g. '(+ 1 2 3)
returns a list
I can think of a couple of ways to do that. 1. Attach a tag to the JS Array
function list(...args) { var o = [...args] o[listSymbol] = true; return o; }
(is it possible to use args directly here instead of copying it to o?, seems safe I think?)
probably, I was not sure that's why I copied.
ok, minor detail. yes, I think this would be a good approach. it also relates to how protocols are going to be implemented, but we could align that later probably
also other idea is to use custom type which inherits from Array but I am not sure asto how practicle that is.
class List extends Array {
}
function list(...args) {
return new List(...args)
}
here is a more complete example which fixes javascript quirks
Seems reasonable to me. We can always change this when @lilactown comes up with some new protocol stuff, but for now I'm down with going with this approach
I will try to create an issue in github and implement with PR if it is fine with you
Is there a way to run the clavascript playground locally
thanks
I noticed that core functions for clavascript are implemented in js. Is that the strategy going forward? Now that we have the basic building blocks in js, it might be possible to write the rest of the core functions in clavascipt.
@prabnz Yeah, we could have written all of the core in clava probably. This is a tradeoff, not sure which is best. I'm fine with doing the core libs in JS so we can ensure the code is as small as possible, while still readable.
@borkdude there are a number of open issues in the clavascipt repo. What is the best approach if I want to pick one of themup?
You can discuss the ticket here, but in general adding new core functions should be good tickets to work in on general
cool, is there any mechanism to ensure there is no duplicated effort
thanks, sounds good to me.
I am going to work on mapcat next. now that clavascript has list
should mapcat
return a list
like clojure?
I think we should probably just return an array and reserve List
for code-related stuff: '(+ 1 2 3)
correction - mapcat does not return a list. It returns a sequence
@borkdude I agree with you
are there any concerns that certain operations will be different in clava for example ;clojureScript (conj (map identity [1 2]) "a") => ("a" 1 2) ;clavascrip (conj (map identity [1 2]) "a") => [1 2 "a"]
yeah, map returns an array in clava. this makes me reconsider (conj nil x), maybe we should just default to [x]
and not return the list?
In my experience you almost never want a list, and in the cases you do want this, you could be explicit
I summon the wisdom of @lilactown and @corasaurus-hex here
Also it would be better for treeshaking if the core functions wouldn't be coupled with custom data structures, I guess (although List is trivial)
fair point
But to your question: it's not a concern, clavascript is expected to work differently, and return arrays and objects in most places
I thought I already did that
yes, I changed that. Sorry
ahhh i see! no worries, things are in flux and i'm still on the mend and haven't been keeping up
should we be able to assoc into a list?
Submitted clavascript to HN: https://hn.algolia.com/?dateRange=all&page=0&prefix=false&query=clavascript&sort=byDate&type=story Note: direct linking is punished, this is why I'm posting it as a search ;)
I suppose I should make an account on this orange website
@lilactown I made a commit that allows map
with multiple collections:
(is (eq [[1 4 7] [2 5 8] [3 6 9]]
(jsv! '(apply map vector [[1 2 3] [4 5 6] [7 8 9]]))))
You might want to review this though :)
https://github.com/clavascript/clavascript/commit/2d941c16925f6ae15d9a2ab2679bef47578ae8a1You'll want to call iterable
on the collections before calling es6_iterator
on them to support objects and nil
I would like to try having Clava's core lib focus on taking iterables and returning arrays, eschewing returning lists except when explicitly asked for, e.g. list
and list*
reason being that linked lists in practice are almost never what you want. especially mutable linked lists
I think that having a linked list type in the core lib would be useful for the times when you do need it, you don't need to write your own. e.g. for queues
we have a (list 1 2 3)
type now that works with conj the way you would expect (adds to the front). it's not a Cons though, just a wrapper for array
and it's nice to be able to distinguish list from other types in this case - which might come in handy for the macro feature
@lilactown There's two ways to do macros: 1. We use a Clojure evaluator in the "host". Currently the host can be JVM/bb or Node.js/browser. We could use SCI to cover evaluation in the host, since it covers all of these targets. 2. We first compile macros down to JS and then load these JS files in the compiler, to then further compile code that uses those macros (which is what's supported right now, but it limits the host to run in JS).
For 2 things are further complicated that in clavascript, functions produce JS data structures, so if we go that road, then we should extend the compiler to transform not only CLJ(S) data structures, but also JS
So I'm kinda leaning towards 1 now since it keeps most options open and doesn't require much changes to the compiler
i remember an experiment where someone was dynamically generating JS on the server using Clojure. was that you? that seems really cool
@brandon746 I've updated bb dev
to now sort the names alphabetically on each line, this should help git diffs
Thank you sir 🙂
If we can make reader tags configurable and also expose the assoc
protocol, etc, I guess we could make plugins so people can use their favorite third party immutable collections
It's possible to load ImmutableJS in the playground and use it btw ;) https://twitter.com/borkdude/status/1560711024336150528/photo/1
omg I feel human enough that I can work on something