Fork me on GitHub
#squint
<
2022-08-19
>
Prabhjot Singh03:08:20

Hello Everyone, are there any plans to support list in clavasript.

borkdude05:08:32

@prabnz Do you have a suggestion to which JS type this should match?

Prabhjot Singh05:08:09

it could either be a JS Array or a new custom type.

borkdude05:08:39

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

Prabhjot Singh05:08:16

I can think of a couple of ways to do that. 1. Attach a tag to the JS Array

Prabhjot Singh05:08:20

function list(...args) { var o = [...args] o[listSymbol] = true; return o; }

borkdude05:08:34

(is it possible to use args directly here instead of copying it to o?, seems safe I think?)

Prabhjot Singh06:08:55

probably, I was not sure that's why I copied.

borkdude06:08:28

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

Prabhjot Singh06:08:34

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)
}

Prabhjot Singh06:08:43

here is a more complete example which fixes javascript quirks

borkdude06:08:52

what happens if you type: new List(1,2,3)[0]?

borkdude06:08:20

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

Prabhjot Singh06:08:58

I will try to create an issue in github and implement with PR if it is fine with you

borkdude06:08:03

sounds good

Prabhjot Singh08:08:58

Is there a way to run the clavascript playground locally

borkdude08:08:40

@prabnz You can use ./node_cli.js --show -e '(println :hello)'

Prabhjot Singh12:08:11

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.

borkdude12:08:39

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

Prabhjot Singh13:08:18

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

borkdude13:08:58

You can discuss the ticket here, but in general adding new core functions should be good tickets to work in on general

Prabhjot Singh13:08:51

cool, is there any mechanism to ensure there is no duplicated effort

borkdude13:08:16

You can just make a comment: will work on a PR or so.

borkdude13:08:20

Do you have any other ideas?

Prabhjot Singh13:08:42

thanks, sounds good to me.

Prabhjot Singh13:08:51

I am going to work on mapcat next. now that clavascript has list should mapcat return a list like clojure?

borkdude13:08:49

I think we should probably just return an array and reserve List for code-related stuff: '(+ 1 2 3)

Prabhjot Singh13:08:17

correction - mapcat does not return a list. It returns a sequence

Prabhjot Singh13:08:06

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"]

borkdude13:08:39

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?

borkdude13:08:12

In my experience you almost never want a list, and in the cases you do want this, you could be explicit

borkdude13:08:10

I summon the wisdom of @lilactown and @corasaurus-hex here

borkdude13:08:09

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)

borkdude13:08:23

But to your question: it's not a concern, clavascript is expected to work differently, and return arrays and objects in most places

borkdude14:08:49

let's change conj to default nil to []

Cora (she/her)14:08:17

I thought I already did that

Prabhjot Singh14:08:58

yes, I changed that. Sorry

borkdude14:08:10

aah, ok then. I'll revert this change now

Cora (she/her)14:08:51

ahhh i see! no worries, things are in flux and i'm still on the mend and haven't been keeping up

❤️ 1
Cora (she/her)14:08:36

should we be able to assoc into a list?

borkdude14:08:39

Well, clojure does not support this

borkdude14:08:15

Fixed/reverted on main

borkdude14:08:48

Submitted clavascript to HN: https://hn.algolia.com/?dateRange=all&amp;page=0&amp;prefix=false&amp;query=clavascript&amp;sort=byDate&amp;type=story Note: direct linking is punished, this is why I'm posting it as a search ;)

Cora (she/her)14:08:15

I suppose I should make an account on this orange website

borkdude15:08:25

@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/2d941c16925f6ae15d9a2ab2679bef47578ae8a1

lilactown15:08:39

You'll want to call iterable on the collections before calling es6_iterator on them to support objects and nil

lilactown15:08:07

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*

lilactown15:08:59

reason being that linked lists in practice are almost never what you want. especially mutable linked lists

borkdude15:08:02

fully agree, this is the case right now on main

1
lilactown15:08:06

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

borkdude15:08:44

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

borkdude15:08:19

The reason for this is that '(1 2 3) currently didn't work

borkdude15:08:38

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

borkdude15:08:54

which I'm not yet sure how to solve, I can go into more detail on that in a thread

borkdude15:08:08

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

borkdude15:08:03

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

borkdude15:08:31

So I'm kinda leaning towards 1 now since it keeps most options open and doesn't require much changes to the compiler

lilactown16:08:59

it kind of sounds like how cljs eventually got to be "self hosted"

lilactown16:08:41

i think having cross-platform support is more powerful than going all in on JS

lilactown16:08:10

i remember an experiment where someone was dynamically generating JS on the server using Clojure. was that you? that seems really cool

lilactown16:08:18

feels like there's something there

borkdude16:08:22

yes, that was me

lilactown15:08:30

sure, i'm curious

borkdude17:08:06

@brandon746 I've updated bb dev to now sort the names alphabetically on each line, this should help git diffs

💙 1
Brandon Stubbs17:08:31

Thank you sir 🙂

borkdude18:08:11

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

borkdude18:08:36

e.g. #fb/map {:a 1} would create an immutable js map ;)

borkdude19:08:58

It's possible to load ImmutableJS in the playground and use it btw ;) https://twitter.com/borkdude/status/1560711024336150528/photo/1

Cora (she/her)23:08:18

omg I feel human enough that I can work on something

didibus23:08:21

Do we need sequences? Or could it just be all transducers only