如何获得运行中的Julia版本的关键字信息?
例如,Python3.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这种检查能在朱莉娅做吗?还是有人有不同的建议,获取信息的朱莉娅关键字运行版本?
编辑:
感谢下面的回复,我得到了一些有趣的建议。然而,似乎缺少了一些东西。例如,在下面提供的每个保留单词列表中,都缺少单词elseif。我会相信elseif不是关键字(或保留词)吗?
此外,当我转到来自intial-reserved-words和reserved-words的Scheme代码时,我会发现以下代码:
(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在最后一行的末尾是评论:
;; todo: make this more complete这似乎意味着,即使是intial-reserved-words和reserved-words列表的联合(或它们在Scheme中被称为什么)也是不完整的。
因此,我一直拖延检查其中一个答案。当我看到朱莉娅代码中的朱莉娅保留词的规范列表时,我很乐意检查一个。如果朱莉娅专家认为下面的建议之一是获得当前版本的朱莉娅关键词(保留词)列表的最佳方式,我将非常感激。
发布于 2018-09-15 02:56:02
不是在朱莉娅,也许是你要找的。在命令行上,键入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)发布于 2018-09-15 00:08:20
阿洛,
有一些关键字,您可以在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)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如果你是朱莉娅的新手,我建议你看看:
这是一堆例子,所以你可以在语言上做实验。我希望它有帮助;)
https://stackoverflow.com/questions/52340237
复制相似问题