4.9 Keywords

► |  | The Racket Reference

1 | Language Model
2 | Notation for Documentation
3 | Syntactic Forms
4 | Datatypes
5 | Structures
6 | Classes and Objects
7 | Units
8 | Contracts
9 | Pattern Matching
10 | Control Flow
11 | Concurrency and Parallelism
12 | Macros
13 | Input and Output
14 | Reflection and Security
15 | Operating System
16 | Memory Management
17 | Unsafe Operations
18 | Running Racket
| Bibliography
| Index

▼ | 4 | Datatypes

4.1 | Equality
4.2 | Booleans
4.3 | Numbers
4.4 | Strings
4.5 | Byte Strings
4.6 | Characters
4.7 | Symbols
4.8 | Regular Expressions
4.9 | Keywords
4.10 | Pairs and Lists
4.11 | Mutable Pairs and Lists
4.12 | Vectors
4.13 | Stencil Vectors
4.14 | Boxes
4.15 | Hash Tables
4.16 | Treelists
4.17 | Sequences and Streams
4.18 | Dictionaries
4.19 | Sets
4.20 | Procedures
4.21 | Void
4.22 | Undefined

► | 4.9 | Keywords

4.9.1 | Additional Keyword Functions

On this page:

keyword?
keyword->string
string->keyword
keyword<?
4.9.1 Additional Keyword Functions
keyword->immutable-string

Racket
top contents ← prev up next →

### 4.9 Keywords🔗ℹ

> > > Keywords in The Racket Guide introduces keywords.

A keyword is like an interned symbol, but its printed form starts with #:, and a keyword cannot be used as an identifier. Furthermore, a keyword by itself is not a valid expression, though a keyword can be quoted to form an expression that produces the symbol.

Two keywords are eq? if and only if they print the same (i.e., keywords are always interned).

Like symbols, keywords are only weakly held by the internal keyword table; see Symbols for more information.

See Reading Keywords for information on reading keywords and Printing Keywords for information on printing keywords.

> procedure (keyword? v) → boolean?
> v : any/c

Returns #t if v is a keyword, #f otherwise.

Examples:

> > (keyword? '#:apple)
> #t
> > (keyword? 'define)
> #f
> > (keyword? '#:define)
> #t

> procedure (keyword->string keyword) → string?
> keyword : keyword?

Returns a string for the displayed form of keyword, not including the leading #:.

See also keyword->immutable-string from racket/keyword.

Example:

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

> procedure (string->keyword str) → keyword?
> str : string?

Returns a keyword whose displayed form is the same as that of str, but with a leading #:.

Example:

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

> procedure (keyword<? a-keyword b-keyword ...) → boolean?
> a-keyword : keyword?
> b-keyword : keyword?

Returns #t if the arguments are sorted, where the comparison for each pair of keywords is the same as using keyword->string with string->bytes/utf-8 and bytes<?.

Example:

> > (keyword<? '#:apple '#:banana)
> #t

Changed in version 7.0.0.13 of package base: Allow one argument, in addition to allowing two or more.

#### 4.9.1 Additional Keyword Functions🔗ℹ

(require racket/keyword) | package: base

The bindings documented in this section are provided by the racket/keyword library, not racket/base or racket.

Added in version 7.6 of package base.

> procedure (keyword->immutable-string sym) → (and/c string? immutable?)
> sym : keyword?

Like keyword->string, but the result is an immutable string, not necessarily freshly allocated.

Examples:

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

Added in version 7.6 of package base.

top contents ← prev up next →