如何获取正在运行的Julia版本的关键字信息?
例如,Python 3.6中有33个关键字,但2.7中只有31个:
# This is Python 3.6 code running in a file:
import keyword
print(len(keyword.kwlist))
## Output: 33
# This is Python 2.7 code running in a file:
import keyword
print len(keyword.kwlist)
## Output: 31
Run Code Online (Sandbox Code Playgroud)
这种检查可以在朱莉娅完成吗?或者有人对获取正在运行的版本的Julia关键字的信息有不同的建议吗?
编辑:
感谢下面的回复,我得到了一些有趣的建议.然而,似乎缺少某些东西.例如,在下面提供的每个保留字列表中,elseif缺少该字.我是否相信这elseif不是关键字(或保留字)?
此外,当我转到Scheme代码的位置intial-reserved-words和reserved-words来源时,我发现以下代码:
(define initial-reserved-words '(begin while if for try return break continue
function macro quote let local global const do
struct
module baremodule using import export))
(define initial-reserved-word? (Set initial-reserved-words))
(define reserved-words (append initial-reserved-words '(end else catch finally true false))) ;; todo: make this more complete
Run Code Online (Sandbox Code Playgroud)
在上面最后一行的末尾是评论:
;; todo: make this more complete
Run Code Online (Sandbox Code Playgroud)
这似乎意味着的,即使是工会intial-reserved-words和reserved-words列表(或任何他们被称为方案)是不完整的.
因此,我一直在检查其中一个答案.当我看到如何在Julia代码中获得Julia保留字的规范列表时,我将很乐意检查一个.如果朱莉娅专家认为以下建议中的一个是获取当前Julia版本的关键字列表(保留字)的最佳方式,我将不胜感激.
实际上并不是朱莉娅,但也许你正在寻找.在命令行中,键入julia --lisp将带您进入Julia用于解析的Lisp解释器,在该解释器中,您可以通过评估reserved-words(以及许多其他类似的operators)来查看反向词的列表.
> julia --lisp
; _
; |_ _ _ |_ _ | . _ _
; | (-||||_(_)|__|_)|_)
;-------------------|----------------------------------------------------------
> reserved-words
(begin while if for try return break continue function macro quote let local
global const do struct type immutable importall module baremodule using import
export end else catch finally true false)
Run Code Online (Sandbox Code Playgroud)
异基因,
有一些关键字,您可以在Julia文档中找到它们.
initial-reserved-words包含所有关键字的值.您可以从命令行访问它:$ julia --lisp
; _
; |_ _ _ |_ _ | . _ _
; | (-||||_(_)|__|_)|_)
;-------------------|-------------------------------------------------------
> initial-reserved-words
(begin while if for try return break continue function macro quote let local
global const do struct module baremodule using import export)
Run Code Online (Sandbox Code Playgroud)
keywords = ("begin","while","if","for","try","return","break","continue","function","macro",
"quote","let","local","global","const","do","struct","module","baremodule",
"using","import","export")
print(length(keywords)) # 22
Run Code Online (Sandbox Code Playgroud)
如果您是Julia的新手,我建议您看看:
这是一堆示例,因此您可以尝试使用该语言.我希望它有所帮助;)