Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何检查Racket语法中是否存在关键字?_Racket - Fatal编程技术网

如何检查Racket语法中是否存在关键字?

如何检查Racket语法中是否存在关键字?,racket,Racket,我想检查语法对象中是否存在关键字。 当关键字后面跟一个表达式时很容易: (syntax-parse #'(hello #:world "sunny") [(_ (~optional (~seq #:world <adjective>:str))) #'(string-append "Hello world! Today's weather is " (~? <adjective> "unknown"))]) 如何将#:w

我想检查语法对象中是否存在关键字。 当关键字后面跟一个表达式时很容易:

(syntax-parse #'(hello #:world "sunny")
  [(_ (~optional (~seq #:world <adjective>:str)))
   #'(string-append "Hello world! Today's weather is "
                    (~? <adjective> "unknown"))])

如何将
#:world
的存在绑定到语法属性?

您可以使用
~和
将语法绑定到属性:

(syntax-parse #'(hello #:world)
  [(_ (~optional (~and world? #:world)))
   #:with maybe-world (if (attribute world?) #'" world" #'"")
   #'(string-append "Hello" maybe-world "!")])

从文档:

另见。
(syntax-parse #'(hello #:world)
  [(_ (~optional (~and world? #:world)))
   #:with maybe-world (if (attribute world?) #'" world" #'"")
   #'(string-append "Hello" maybe-world "!")])
One use for ~and-patterns is preserving a whole term (including its lexical
context, source location, etc) while also examining its structure.
Syntax classes are useful for the same purpose, but ~and can be lighter weight.