How do I get keyword information for the version of Julia being run?
For example, there are 33 keywords in Python 3.6, but only 31 in 2.7:
# 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
Can this kind of check be done in Julia? Or does someone have a different suggestion for getting info on Julia keywords for the running version?
EDIT:
Thanks to responses below I have gotten some interesting suggestions. However, something seems to be missing. For example, in each list of reserved words provided below, the word elseif
is missing. Am I to believe that elseif
is not a keyword (or reserved word)?
Also when I go to the Scheme code where intial-reserved-words
and reserved-words
come from, I find the following code:
(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
At the end of the last line above is the comment:
;; todo: make this more complete
This seems to imply that even the union of intial-reserved-words
and the reserved-words
lists (or whatever they are called in Scheme) is not complete.
Thus, I have held off on checking one of the answers. I will be happy to check one when I see how to get a canonical list of Julia reserved words in Julia code. If a Julia expert believes one of the suggestions below is the best way to get the list of keywords (reserved words) for the current version of Julia, I would appreciate knowing it.
Not actually in Julia, but maybe what you are looking for. On the command line, typing julia --lisp
will bring you to the Lisp interpreter that Julia uses for parsing, in which you can see the list of reversed words by evaluating reserved-words
(and a lot of others like 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)
Allo,
There are some keywords, you can find them on the Julia documentation.
initial-reserved-words
containing all keywords. You can access it from the command line:$ 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
If you are new to Julia, I recommend you take a look at:
It's a bunch of example so you can experiment on the language. I hope it helps ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With