/
reserved.hy
33 lines (25 loc) · 866 Bytes
/
reserved.hy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
;;; Get a frozenset of Hy reserved words
(import sys keyword)
(setv _cache None)
(defn macros []
"Return a frozenset of Hy's core macro names."
(frozenset (map hy.unmangle (+
(list (.keys hy.core.result_macros.__macros__))
(list (.keys hy.core.macros.__macros__))))))
(defn names []
"Return a frozenset of reserved symbol names.
The result of the first call is cached.
The output includes all of Hy's core functions and macros, plus all
Python reserved words. All names are in unmangled form (e.g.,
``not-in`` rather than ``not_in``).
Examples:
::
=> (import hy.extra.reserved)
=> (in \"defclass\" (hy.extra.reserved.names))
True
"
(global _cache)
(when (is _cache None)
(setv _cache (| (macros) (frozenset (map hy.unmangle
keyword.kwlist)))))
_cache)