Civet icon indicating copy to clipboard operation
Civet copied to clipboard

Bulleted arrays

Open edemaine opened this issue 2 years ago • 1 comments

Inspired by YAML sequences (which use -) and Markdown lists (which allow -, +, or *), I propose supporting indented implicit lists with some kind of bullet operator:

x :=
  • name: 'hello'
    value: 'world'
  • name: 'goodbye'
    value: 'world'
  • item
↓↓↓
const x = [
  { name: 'hello',
    value: 'world' },
  { name: 'goodbye',
    value: 'world' },
  item
]

For Unicode bullets (), this seems like a no-brainer. The question is what ASCII form(s) it should also have.

  • . looks a lot like a bullet and isn't currently meaningful when followed by a space. I think this is the current winner.
  • ~ looks something like a dash and isn't currently meaningful when followed by a space, though we've occasionally discussed it being used for typing (as it was in my typed CoffeeScript branch).
  • -, +, * would be great from a compatibility/familiarity perspective. In particular, I dream of a big YAML subset as being a subset of Civet, in the same way that JSON is a subset of JavaScript. We could also plausibly support them in certain contexts, like right after an assignment as in the example above. But in general we should probably give precedence to these acting like regular binary operators. For example:
    test
      - item1
      - item2
    
    This should probably remain a subtraction, not an implicit function call test([item1, item2]). But I think this is mainly an issue when trying to do indented implicit function calls, which is a bit of an edge case (though admittedly a useful one; implicit objects are used this way all the time). When we're at the "beginning" of an expression, I think we could safely use -, +, *.
  • > is maybe another related option, inspired by the recent JSX ideas, but it has the same limitations as -/+/*.
  • -- is a reasonable option inspired by en-dash (this is how you type it in LaTeX). ++ doesn't make as much sense, and ** already means exponentiation (and >> already means shift-right). The main issue with doubled operators like this is that they look ugly with 2-spaces indentation:
    x :=
      -- name: 'hello'
        value: 'world'
    

Context

Civet (and CoffeeScript) currently lack an implicit array mechanism, unlike objects. They also have an awkward way to write lists of implicit objects — the dedented comma — which this could be a nicer alternative to.

[
  name: 'hello'
  value: 'world'
,
  name: 'goodbye'
  value: 'world'
,
  item
]

edemaine avatar Nov 11 '23 20:11 edemaine

in the same way that JSON is a subset of JavaScript.

Minor correction: this isn't quite true, because LS and PS are treated as line breaks by JavaScript (or at least were before 2019), but are allowed unescaped in JSON strings. JSON5 notes that this is their only incompatibility with ES5.

bbrk24 avatar Nov 11 '23 20:11 bbrk24

I dream of a big YAML subset as being a subset of Civet

@edemaine That would be 🔥

danielbayley avatar Aug 16 '24 10:08 danielbayley