Scheme: pattern matching syntax
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)
精彩评论