Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.
This repository was archived by the owner on Jan 9, 2023. It is now read-only.

A nested sequence containing a single unit is redundant #8

@lgarron

Description

@lgarron

The following prints false:

var original = new Alg.Group(
  new Alg.Sequence([
    new Alg.BlockMove("R", 1)
  ]),
  1
)
var parsed = parse(algToString(original));
console.log(structureEquals(original, parsed));

Ideally, I'd like there to be only a single representation of this alg.
One possibility is to have a nested kind of sequence that must have at least two units in it. The parser actually uses this requirement to avoid unnecessary nesting (which is why parsed is different):

: REPEATED_UNIT OPTIONAL_WHITESPACE REPEATED_UNIT

Ideas:

  1. Create a different kind of sequence for a nested alg that requires at least two members.
  1. Define every Algorithm with nested algs to have its own lists, e.g. a commutator has {A: Unit[], B: Unit[]}. This requires making sure to call the Sequence processing code for each of the components in every relevant Algorithm in every traversal, possibly leading to subtle bugs.
  2. Don't allow anything except a Sequence to contain a Unit, and require a Sequence layer.
  • This results in larger data structures, and an extra level of access in some cases. However, code might be more consistent, because looking inside a nested alg always requires going through a Sequence the same way.

See https://gist.github.com/lgarron/f33d88a571f4bc9536801a8a7b035a91 for more thoughts on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions