首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >朱莉娅1.0中的关键词(或保留词)

朱莉娅1.0中的关键词(或保留词)
EN

Stack Overflow用户
提问于 2018-09-14 23:14:41
回答 2查看 1.2K关注 0票数 5

如何获得运行中的Julia版本的关键字信息?

例如,Python3.6中有33个关键字,但2.7中只有31个:

代码语言:javascript
复制
# 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-wordsreserved-words的Scheme代码时,我会发现以下代码:

代码语言:javascript
复制
(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

在最后一行的末尾是评论:

代码语言:javascript
复制
;; todo: make this more complete

这似乎意味着,即使是intial-reserved-wordsreserved-words列表的联合(或它们在Scheme中被称为什么)也是不完整的。

因此,我一直拖延检查其中一个答案。当我看到朱莉娅代码中的朱莉娅保留词的规范列表时,我很乐意检查一个。如果朱莉娅专家认为下面的建议之一是获得当前版本的朱莉娅关键词(保留词)列表的最佳方式,我将非常感激。

EN

回答 2

Stack Overflow用户

发布于 2018-09-15 02:56:02

不是在朱莉娅,也许是你要找的。在命令行上,键入julia --lisp将带您到Julia用于解析的Lisp解释器,在该解释器中,您可以通过计算reserved-words (以及许多其他类似于operators)来查看倒排单词的列表。

代码语言:javascript
复制
> 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)
票数 9
EN

Stack Overflow用户

发布于 2018-09-15 00:08:20

阿洛,

有一些关键字,您可以在Julia文件上找到它们。

代码语言:javascript
复制
$ 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)
  • 或者您可以自己创建一个数组:
代码语言:javascript
复制
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

如果你是朱莉娅的新手,我建议你看看:

这是一堆例子,所以你可以在语言上做实验。我希望它有帮助;)

票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52340237

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档