Can `match` in Racket have patterns with variables from an outer scope?

前端 未结 1 2124
深忆病人
深忆病人 2021-02-18 21:13

Consider the following example:

#lang racket

(match \'(cat . doge)
  [`(,a . ,b)
   (match b
     [a #t]
     [_ #f])]
  [_ \"Not a pair\"])

T

相关标签:
1条回答
  • 2021-02-18 21:29

    Use ==:

    (match '(cat . doge)
      [`(,a . ,b)
       (match b
         [(== a) #t]
         [_      #f])]
      [_ "Not a pair"])
    

    Due to the placement in the docs, == is easy to overlook.

    0 讨论(0)
提交回复
热议问题