Skip to content

Have superpose and collapse use explicit tuple (using the , constructor) #1030

@ngeiswei

Description

@ngeiswei

Suggestion

Modify superpose and collapse to assume an actual tuple constructed with ,. So instead of writing

!(superpose (A B C))

we would write

!(superpose (, A B C))

Likewise, collapse would output a tuple constructed with ,. So for instance

(= (foo) A)
(= (foo) B)
(= (foo) C)
!(collapse (foo))

would output

[(, A B C)]

Why?

  1. Avoid having collapse trigger an unintended reduction. For instance
    (= (f $x $y) (+ $x $y))
    (= (foo) f)
    (= (foo) 1)
    (= (foo) 2)
    !(collapse (foo))
    may output
    [3]
    I know it currently outputs
    [(f 1 2)]
    but a slight change in the definition of collapse may make it output 3 in the future, it is too brittle in my opinion.
  2. By using , when wanting to represent a tuple the user makes it clear what is the intent. Think of the difference between
    !(superpose (f 1 2))
    which may evoke the idea of superposing the result of (f 1 2) instead of
    !(superpose (, f 1 2))
    which clearly evokes the idea of superposing f, 1 and 2.
  3. We can introduce an actual Tuple type (maybe a subtype of Expression?) and refine the type signature of superpose and certainly other functions.

Why not?

It breaks backward compatibility. But MeTTa is alpha, so...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions