Civet icon indicating copy to clipboard operation
Civet copied to clipboard

Semiautovivification

Open anhnhoktvn opened this issue 1 year ago • 4 comments

It's nice to have Semiautovivification from livescript Screenshot_2023-04-01_10-12-33

anhnhoktvn avatar Apr 01 '23 03:04 anhnhoktvn

We can currently do something similar with:

x = {}
(x.'hello world' ?= []).2 = 3

I'm not convinced that an additional specialized syntax is worth it in this case.

STRd6 avatar Apr 01 '23 16:04 STRd6

I just used it a lot in past. Quite elegant. How do we do this

x.[]arr.{}1.y = 9

in Civet way?

anhnhoktvn avatar Apr 05 '23 08:04 anhnhoktvn

Currently:

( ( x.arr ?= [] )[1] ?= {} ).y = 9

It may make sense to try something like this for a possible future syntax:

x.arr?=[][1]?={}.y = 9

STRd6 avatar Apr 05 '23 15:04 STRd6

Now that we have pipes:

x |> .foo ?= [] |> .append 5
x |> .foo ?= {} |> &[key] ?= [] |> .push value
(x.foo ??= []).append(5);
((x.foo ??= {})[key] ??= []).push(value);

STRd6 avatar Mar 03 '24 16:03 STRd6