1 Welcome to PLT Scheme
2 Scheme Essentials
3 Built-In Datatypes
4 Expressions and Definitions
5 Programmer-Defined Datatypes
6 Modules
7 Input and Output
8 Contracts
9 Classes and Objects
10 Exceptions and Control
11 Iterations and Comprehensions
12 Regular-Expression Matching (Regexps)
13 Pattern Matching
14 Quasiquoting
15 Units (Higher-Order Modules)
16 Threads
17 Syntactic Extension (Macros)
18 Reflection and Dynamic Evaluation
19 Reader Extension
20 Security
21 Memory Management
22 Performance
23 Foreign-Function Interface (FFI)
24 Scripts
25 Graphical User Interfaces (GUIs)
26 More Tools
Index

contents

 index

← prev  up  next →

 

3.7 Keywords

A keyword value is similar to a symbol (see Symbols), but its printed form is prefixed with #:.

Reading Keywords in PLT Scheme Reference documents the fine points of the syntax of keywords.

Examples:

  > (string->keyword "apple")

  #:apple

  > '#:apple

  #:apple

  > (eq? '#:apple (string->keyword "apple"))

  #t

More precisely, a keyword is analogous to an identifier; in the same way that an identifier can be quoted to produce a symbol, a keyword can be quoted to produce a value. The same term “keyword” is used in both cases, but we sometimes use keyword value to refer more specifically to the result of a quote-keyword expression or of string->keyword. An unquoted keyword is not an expression, just as an unquoted identifier does not produce a symbol:

Examples:

  > not-a-symbol-expression

  reference to undefined identifier: not-a-symbol-expression

  > #:not-a-keyword-expression

  expand: a keyword is not an expression in:

  #:not-a-keyword-expression

Despite their similarities, keywords are used in a different way than identifiers or symbols. Keywords are intented for use (unquoted) as special markers in argument lists and in certain syntactic forms.

Need some examples here, once we have more keyword-based procedures and syntax in place...

Keywords should not be used simply as another kind of symbol. Use symbols, instead of keywords, for run-time flags and enumerations.

Examples:

  > (bytes->path #"/usr/tmp" 'unix) ; 'unix, not '#:unix

  #<path:/usr/tmp>

 

contents

 index

← prev  up  next →