core.match

Head-Tail Pattern Matching Fails for Lists

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

Head-tail pattern matching only seems to work with vectors.

Commit: https://github.com/clojure/core.match/commit/9f4919d855be09a1b32f9e5563ac1c3f5bace642

The following code falls through. (macroexpand appended)

(let [x '(1 2 3)]
  (match [x]
         [[a & as]] :a))
(try
  (clojure.core/cond
    (clojure.core/instance? clojure.lang.IPersistentVector x) (try
                                                                (clojure.core/let 
                                                                  [x_left__3201
                                                                   (clojure.core/subvec
                                                                     x
                                                                     0
                                                                     1)]
                                                                  (clojure.core/cond
                                                                    (clojure.core/and
                                                                      (clojure.core/instance?
                                                                        clojure.lang.IPersistentVector
                                                                        x_left__3201)
                                                                      (clojure.core/=
                                                                        (clojure.core/count
                                                                          x_left__3201)
                                                                        1))
                                                                    (clojure.core/let 
                                                                      [a
                                                                       (clojure.core/nth
                                                                         x_left__3201
                                                                         0)
                                                                       as
                                                                       (clojure.core/subvec
                                                                         x
                                                                         1)]
                                                                      :a)
                                                                    :else
                                                                    (throw
                                                                      clojure.core.match.core/backtrack)))
                                                                (catch
                                                                  java.lang.Exception
                                                                  e__2436__auto__
                                                                  (throw
                                                                    clojure.core.match.core/backtrack)))
    :else (throw clojure.core.match.core/backtrack))
  (catch
    java.lang.Exception
    e__2437__auto__
    (throw clojure.core.match.core/backtrack)))

Activity

Hide
David Nolen added a comment -

This is the expected behavior. If you want to match seqs you have to use the seq pattern syntax.

Show
David Nolen added a comment - This is the expected behavior. If you want to match seqs you have to use the seq pattern syntax.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: