JuliaServices / Match.jl

Advanced Pattern Matching for Julia
https://juliaservices.github.io/Match.jl/latest/
Other
240 stars 22 forks source link

head body... tail match #64

Closed xiaodaigh closed 1 year ago

xiaodaigh commented 4 years ago
using Match

@match
([1:4], [a,b...,c])

I was hoping a = 1, b = [2, 3] and c = 4. Python has an unpacking feature similar to this.

gafter commented 1 year ago

The expression [1:4] is an array containing a single element, which is a range. Perhaps you meant the following?

julia> Pkg.status()
      Status `~/.julia/environments/v1.6/Project.toml`
  [7eb4fadd] Match v2.0.0

julia> using Match

julia> @ismatch 1:4 [a, b..., c]
true

julia> a
1

julia> b
2:3

julia> c
4