arr-ai / arrai

The ultimate data engine.
http://arr.ai
Apache License 2.0
20 stars 15 forks source link

Consider changing pattern wildcard syntax #564

Open marcelocantos opened 4 years ago

marcelocantos commented 4 years ago

Please do not post any internal, closed source snippets on this public issue tracker!

Purpose

Please describe the end goal you are trying to achieve that has led you to request this feature.

... in pattern syntax is a bit verbose at times, e.g. https://github.com/anz-bank/sysl-go/blob/3452b0c2d89fb05d2eb8a89a6365868c58bee69c/codegen/arrai/go.arrai#L22:L22:

{'typeRef': {'ref': {'appname': {'part': (a: [(s: appname), ...])}, ...}, ...}, ...}

Consider alternative syntaxes.

Suggested approaches

What have you tried, and how might this problem be solved?

Alternative 1: *

{'typeRef': {'ref': {'appname': {'part': (a: [(s: appname), *])}, *}, *}, *}

Pros:

  1. Save two characters per instance.
  2. Works well with proposed ? pattern for arrays ([1, 2, ?, 4, *, 8, 9]). Feels like shell globbing.

Cons:

  1. Still noisy

Alternative 2: !

Use ! to fail if additional elements are present.

{'typeRef': {'ref': {'appname': {'part': (a: [(s: appname!)]!)!}}}}

Pros:

  1. Simpler for the common "don't care" scenario. The above could be further simplified:
    {'typeRef': {'ref': {'appname': {'part': (a: [(s: appname)])}}}}

Cons:

  1. Still need syntax (retain ... or switch to *) to bind a name to extras.
  2. Not as safe. The intent behind ... was to require positive affirmation that additional elements are acceptable. This has proven to be a weak argument because forgetting to add ... also causes annoying bugs to surface when additional attributes or keys are introduced.

Proposed strategy

Based on discussion, we'll implement the following stepwise strategy:

For arrays, it's less clear what the right default is. Perhaps there should be no default, and so all array patterns would have to end in either * or !.