Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bulleted arrays #803

Closed
edemaine opened this issue Nov 11, 2023 · 2 comments · Fixed by #1361
Closed

Bulleted arrays #803

edemaine opened this issue Nov 11, 2023 · 2 comments · Fixed by #1361
Labels
proposal Proposal or discussion about a significant language feature

Comments

@edemaine
Copy link
Collaborator

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 edemaine added the proposal Proposal or discussion about a significant language feature label Nov 11, 2023
@edemaine edemaine changed the title Bulleted lists Bulleted arrays Nov 11, 2023
@bbrk24
Copy link
Contributor

bbrk24 commented Nov 11, 2023

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.

@danielbayley
Copy link
Contributor

danielbayley commented Aug 16, 2024

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

That would be 🔥 @edemaine, you might also want to check out YAMLScript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Proposal or discussion about a significant language feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants