core.match

Simple capturing of :or matches with :as doesn't work

Details

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

Description

All three of these expressions should work (according to @dnolen in IRC):

user> (match/match [5] [((:or 5 6) :as x)] x)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context
user> (match/match [5] [(:or (5 :as x) (6 :as x))] x)
5
user> (match/match [5] [(:or (5 :as x) (6 :as y))] x)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context

(The first makes sense to me, but the latter two don't; e.g. should y be nil in the last example, or something else?)

Though it's not necessary, it'd be nice if the following "sugared" form worked, too:

user> (match/match [5] [(:or 5 6 :as x)] x)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context

Activity

Chas Emerick made changes -
Field Original Value New Value
Description All three of these expressions should work (according to @dnolen in IRC):

{code}
user> (match/match [5] [((:or 5 6) :as x)] x)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context
user> (match/match [5] [(:or (5 :as x) (6 :as x))] x)
5
user> (match/match [5] [(:or (5 :as x) (6 :as y))] x)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context
{code}

(The first makes sense to me, but the latter two don't; e.g. should {{y}} be {{nil}} in the last example?)

Though it's not necessary, it'd be nice if the following "sugared" form worked, too:

{code}
user> (match/match [5] [(:or 5 6 :as x)] x)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context
{code}
All three of these expressions should work (according to @dnolen in IRC):

{code}
user> (match/match [5] [((:or 5 6) :as x)] x)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context
user> (match/match [5] [(:or (5 :as x) (6 :as x))] x)
5
user> (match/match [5] [(:or (5 :as x) (6 :as y))] x)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context
{code}

(The first makes sense to me, but the latter two don't; e.g. should {{y}} be {{nil}} in the last example, or something else?)

Though it's not necessary, it'd be nice if the following "sugared" form worked, too:

{code}
user> (match/match [5] [(:or 5 6 :as x)] x)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: x in this context
{code}
Hide
Greg Chapman added a comment -

Same problem occurs with :guard patterns:

user=> (match/match 1 ((_ :guard odd?) :as n) n :else 0)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: n in this context

Show
Greg Chapman added a comment - Same problem occurs with :guard patterns: user=> (match/match 1 ((_ :guard odd?) :as n) n :else 0) CompilerException java.lang.RuntimeException: Unable to resolve symbol: n in this context
Hide
Jan-Paul Bultmann added a comment - - edited

Some weirdness is also going on with `&` in vectors.

This is the working vector matching behaviour without `&`.

(match [[1 2 3]]
[([u v w] :as a)] a)
=> [1 2 3]

And this is the result of adding a rest match.

(match [[1 2 3]]
[([h & r] :as a)] a)
=> [1]

Both should be the same.

Show
Jan-Paul Bultmann added a comment - - edited Some weirdness is also going on with `&` in vectors. This is the working vector matching behaviour without `&`. (match [[1 2 3]] [([u v w] :as a)] a) => [1 2 3] And this is the result of adding a rest match. (match [[1 2 3]] [([h & r] :as a)] a) => [1] Both should be the same.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: