开发者

Scheme: pattern matching syntax

开发者 https://www.devze.com 2023-02-13 22:11 出处:网络
I am trying to do some fairly complicated pattern matching using match-lambda.However I am having a lot of trouble deciphering the syntax for the patterns and the matches and Googling hasn\'t turned u

I am trying to do some fairly complicated pattern matching using match-lambda. However I am having a lot of trouble deciphering the syntax for the patterns and the matches and Googling hasn't turned up any decent references.

One thing that seems like it ought to be simple is matching the string '(PARAMS: (y)) using this pattern:

开发者_如何学Go(`(PARAMS: (,<arg>))
 <match>

But it doesn't work.

The pattern:

(`(PARAMS: ,<arg>)
 `<match>

matches '(PARAMS: y) but I would really like to be able to put the paramaters I am matching in brackets.

Strangely, the pattern:

(`(PARAMS: (y))
 `<match>

does not even match '(PARAMS: (y)). It seems there is something about parentheses that I do not understand.


Try posting a small complete program. This works fine for me:

#lang racket

(match `(PARAMS: (y))
  [`(PARAMS: (,var)) 'yep]
  [otherise 'nope])

==>

'yep

(also, cf. comment to your question, above)

0

精彩评论

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

关注公众号