开发者

What means "(? symbol? name)"?

I had problem even in choosing a title for this question. Please feel free to edit it.

I got this Scheme code and did not understand this block.

(define (func b)
 (match b
   [(list (? symbol? x) rhs) ...

The trouble part is (? symbol? x). I guess it's a comparator of some sort, but I didn't find anything abo开发者_StackOverflow社区ut it anywhere! It's hard to search it, since I don't know how to name this command.

I would like to get at least its name, further explanations are appreciated. =)

Thanks!


Just found it!

It's a specific case of (match ...) syntax. Found it here: Pattern Matching

More specific:

(match val-expr clause ...)

clause = [pat expr ...+]
| [pat (=> id) expr ...+]

Where pat is

pat ::= id [match anything, bind identifier]
(...)
| (? expr pat ...) [match if (expr value) and pat]

So I was kinda right: it's checking if x is a symbol.

I was lucky! Please complete this topic! Many thanks!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜