0

我正在尝试使用 match-lambda 对 letrec 的调用进行模式匹配。在我看来,这种模式:

(match-lambda
  (`(letrec ((,<var> ,<val>) . (,<vars> ,<vals>)) ,<expr> . ,<exprs>)
   `(<match>))

应该匹配以下形式的调用:

(letrec ((<var> <val>) ...) <expr> ...)

但是,当然,这是行不通的。

任何建议表示赞赏。

4

2 回答 2

1

我认为您需要使用以下...语法match-lambda

(match-lambda
  (`(letrec ((,<var> ,<val>) ...) ,<expr> ...)
    body))
于 2011-03-15T04:09:56.040 回答
0

I'm not sure, but I think the problem might be with the ((,<var> ,<val>) . (,<vars> ,<vals>)). This is identical to ((,<var> ,<val>) ,<vars> ,<vals>) which isn't what you want. Perhaps try something like ((,<var> ,<val>) . ,<vars-vals>))?


I also looked into the documentation and it seems like letrec shouldn't be part of your expression, and you should possibly use match-lambda*.

Try

(match-lambda
  (`(((,<var> ,<val>) . ,<vars-vals>) ,<expr> . ,<exprs>)
   `(<match>)))

(although of course, I could be wrong)

于 2011-03-18T13:31:50.397 回答