1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-15 21:24:48 +00:00

Update documentation on keywords.

This commit is contained in:
Calvin Rose 2019-01-02 19:46:24 -05:00
parent e9c94598e6
commit 6afaacf2af
2 changed files with 7 additions and 4 deletions

View File

@ -76,8 +76,11 @@ Janet supports several varieties of types that can be used as labels for things
your program. The most useful type for this purpose is the keyword type. A keyword your program. The most useful type for this purpose is the keyword type. A keyword
begins with a semicolon, and then contains 0 or more alphanumeric or a few other common begins with a semicolon, and then contains 0 or more alphanumeric or a few other common
characters. For example, `:hello`, `:my-name`, `::`, and `:ABC123_-*&^%$` are all keywords. characters. For example, `:hello`, `:my-name`, `::`, and `:ABC123_-*&^%$` are all keywords.
Keywords are actually just special cases of symbols, which are similar but don't start with
a semicolon. The difference between symbols and keywords is that keywords evaluate to themselves, while Keywords, symbols, and strings all behave similarly and can be used as keys for tables and structs.
Symbols and keywords are optimized for fast equality checks, so are preferred for table keys.
The difference between symbols and keywords is that keywords evaluate to themselves, while
symbols evaluate to whatever they are bound to. To have a symbol evaluate to itself, it must be symbols evaluate to whatever they are bound to. To have a symbol evaluate to itself, it must be
quoted. quoted.

View File

@ -31,7 +31,7 @@ false
## Symbols ## Symbols
Janet symbols are represented a sequence of alphanumeric characters Janet symbols are represented a sequence of alphanumeric characters
not starting with a digit. They can also contain the characters not starting with a digit or a colon. They can also contain the characters
\!, @, $, \%, \^, \&, \*, -, \_, +, =, \|, \~, :, \<, \>, ., \?, \\, /, as \!, @, $, \%, \^, \&, \*, -, \_, +, =, \|, \~, :, \<, \>, ., \?, \\, /, as
well as any Unicode codepoint not in the ascii range. well as any Unicode codepoint not in the ascii range.
@ -54,7 +54,7 @@ my-module/my-fuction
## Keywords ## Keywords
Janet keywords are really just symbols that begin with the character :. However, they Janet keywords are like symbols that begin with the character :. However, they
are used differently and treated by the compiler as a constant rather than a name for are used differently and treated by the compiler as a constant rather than a name for
something. Keywords are used mostly for keys in tables and structs, or pieces of syntax something. Keywords are used mostly for keys in tables and structs, or pieces of syntax
in macros. in macros.