Skip to content

match with shorter list pattern #1611

@z-rui

Description

@z-rui

How to interpret the following?

(match [1 2]
  [x] 1
  [x y] 2)

With Janet 1.38.0, it evaluates to 1, instead of 2.

It looks like a list pattern only needs to match the prefix of the target value. The documentation is a bit vague:

an array or bracket tuple will match only if all of its elements match the corresponding elements in x.

Is this a bug or a feature? I think prefix matching can be better expressed as [x & _]. (Side note: currently this will make a slice for the rest elements and bind it to _, probably not needed.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions