开发者

rewriting match-lambda

As an exercise I am trying to define a rule match-rewriter that behaves the same as match-lambda but returns its argument if no match is found. So far I have this:

(define-syntax match-rewriter
  (syntax-rules ()
    ((_ (patt body) ...)
      (λ (x) (match x (patt body) ...)))))

which seems to work perfectly if a match is found.

But, I can't figure out how to return the argument x if no match is found.

I know that match will throw an exception if no match is found. But I can't figure out how to catch it and I would like a simpl开发者_运维知识库er solution if one exists.


If this question is about the Racket's match, then just add a clause that matches anything:

(match x [patt body] ... [_ x])
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜