# 13.5 Writing
In addition to the parameters defined in this section, [pretty-print](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print%29%29) conforms to the [print-graph](Writing.html#%28def._%28%28quote._~23~25kernel%29._print-graph%29%29), [print-struct](Writing.html#%28def._%28%28quote._~23~25kernel%29._print-struct%29%29), [print-hash-table](Writing.html#%28def._%28%28quote._~23~25kernel%29._print-hash-table%29%29), [print-vector-length](Writing.html#%28def._%28%28quote._~23~25kernel%29._print-vector-length%29%29), [print-box](Writing.html#%28def._%28%28quote._~23~25kernel%29._print-box%29%29), and [print-as-expression](Writing.html#%28def._%28%28quote._~23~25kernel%29._print-as-expression%29%29) parameters.


# 13.5 Writing
The pretty printer detects structures that have the [prop:custom-write](Printer_Extension.html#%28def._%28%28quote._~23~25kernel%29._prop~3acustom-write%29%29) property and calls the corresponding custom-write procedure. The custom-write procedure can check the parameter [pretty-printing](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-printing%29%29) to cooperate with the pretty-printer. Recursive printing to the port automatically uses pretty printing, but if the structure has multiple recursively printed sub-expressions, a custom-write procedure may need to cooperate more to insert explicit newlines. Use [port-next-location](linecol.html#%28def._%28%28quote._~23~25kernel%29._port-next-location%29%29) to determine the current output column, use [pretty-print-columns](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print-columns%29%29) to determine the target printing width, and use [pretty-print-newline](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print-newline%29%29) to insert a newline (so that the function in the [pretty-print-print-line](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print-print-line%29%29) parameter can be called appropriately). Use [make-tentative-pretty-print-output-port](#%28def._%28%28lib._racket%2Fpretty..rkt%29._make-tentative-pretty-print-output-port%29%29) to obtain a port for tentative recursive prints (e.g., to check the length of the output).


# 13.5 Writing
If the newline? argument is omitted or supplied with true, the [pretty-print-print-line](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print-print-line%29%29) callback is called with false as the first argument to print the last newline after the printed value. If it is supplied with false, the [pretty-print-print-line](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print-print-line%29%29) callback is not called after the printed value.
Changed in version 6.6.0.3 of package base: Added newline? argument.
> ```
(current-output-port)	→
(-> current-output-port)
```
(current-output-port)	→
(-> current-output-port)```

Same as [pretty-print](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print%29%29), but v is printed like [display](Writing.html#%28def._%28%28quote._~23~25kernel%29._display%29%29) instead of like [print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29).

Changed in version 6.6.0.3 of package base: Added newline? argument.

> ```
(pretty-format v [columns #:mode mode) → string?
  v : any/c
  columns : exact-nonnegative-integer? = (pretty-print-columns)
  mode : (or/c 'print 'write 'display) = 'print
```
(parameter)	→```


# 13.5 Writing
Pretty-prints v if v is not [#<void>](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=void_undefined.html&version=8.18.0.13), or prints nothing if v is [#<void>](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=void_undefined.html&version=8.18.0.13). Pass this procedure to [current-print](eval.html#%28def._%28%28quote._~23~25kernel%29._current-print%29%29) to install the pretty printer into the REPL run by [read-eval-print-loop](eval.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._read-eval-print-loop%29%29).


#### 13.6.1 Basic Pretty-Print Options
> ```
(pretty-print-columns)	→
(-> or/c exact-positive-integer? 'infinity)
(pretty-print-columns width) → void?
    width	:
(-> or/c exact-positive-integer? 'infinity)
```
(pretty-print-depth)	→
(-> or/c exact-nonnegative-integer? #f)
(pretty-print-depth depth) → void?
    depth	:
(-> or/c exact-nonnegative-integer? #f)```

Parameter that controls the default depth for recursive pretty printing. Printing to depth means that elements nested more deeply than depth are replaced with “...”; in particular, a depth of 0 indicates that only simple values are printed. A depth of #f (the default) allows printing to arbitrary depths.

> ```
(pretty-print-exact-as-decimal)	→
(-> pretty-print-exact-as-decimal as-decimal?)
```
(pretty-print-.-symbol-without-bars)	→
(-> pretty-print-.-symbol-without-bars on?)```
A [parameter](eval-model.html#%28tech._parameter%29) that controls the printing of the symbol whose print name is just a period. If set to a true value, then such a symbol is printed as only the period. If set to a false value, it is printed as a period with vertical bars surrounding it.
> ```
(pretty-print-show-inexactness)	→
(-> pretty-print-show-inexactness show?)


# 13.5 Writing
```
(pretty-print-abbreviate-read-macros)	→
(-> pretty-print-abbreviate-read-macros abbrev?)```

A [parameter](eval-model.html#%28tech._parameter%29) that controls whether or not quote, unquote, unquote-splicing, etc., are abbreviated with ', ,, ,@, etc. By default, the abbreviations are enabled.

See also [pretty-print-remap-stylable](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print-remap-stylable%29%29).

> ```
(pretty-print-style-table? v)  →  boolean?
  v : any/c
```
(pretty-print-current-style-table)	→
(-> pretty-print-current-style-table style-table)
(pretty-print-current-style-table style-table) → void?
    style-table	:
(-> pretty-print-current-style-table style-table)```
A [parameter](eval-model.html#%28tech._parameter%29) that holds a table of style mappings. See [pretty-print-extend-style-table](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print-extend-style-table%29%29).
> ```
(parameter)	→
(-> listof symbol?)


# 13.5 Writing
```
(pretty-print-remap-stylable)	→
(-> any/c . → . (or/c symbol? #f))
(pretty-print-remap-stylable proc) → void?
    proc	:
(-> any/c . → . (or/c symbol? #f))```

A [parameter](eval-model.html#%28tech._parameter%29) that controls remapping for styles and for the determination of the reader shorthands.

This procedure is called with each sub-expression that appears as the first element in a sequence. If it returns a symbol, the style table is used, as if that symbol were at the head of the sequence. If it returns #f, the style table is treated normally. Similarly, when determining whether to abbreviate reader macros, this parameter is consulted.

#### 13.6.3 Line-Output Hook

> ```
(parameter)	→
```
(pretty-print-print-line)	→
(-> (or/c exact-nonnegative-integer? #f)
    output-port?
    exact-nonnegative-integer?
    (or/c exact-nonnegative-integer? ' infinity)
    . → .
    exact-nonnegative-integer?)
(pretty-print-print-line proc) → void?
    proc	:
(-> (or/c exact-nonnegative-integer? #f)
    output-port?
    exact-nonnegative-integer?
    (or/c exact-nonnegative-integer? ' infinity)
    . → .
    exact-nonnegative-integer?)```
A [parameter](eval-model.html#%28tech._parameter%29) that determines a procedure for printing the newline separator between lines of a pretty-printed value. The procedure is called with four arguments: a new line number, an output port, the old line’s length, and the number of destination columns. The return value from proc is the number of extra characters it printed at the beginning of the new line.


# 13.5 Writing
The proc procedure is called before any characters are printed with 0 as the line number and 0 as the old line length. Whenever the pretty-printer starts a new line, proc is called with the new line’s number (where the first new line is numbered 1) and the just-finished line’s length. The destination-columns argument to proc is always the total width of the destination printing area, or 'infinity if pretty-printed values are not broken into lines.
If the #:newline? argument was omitted or supplied with a true value, proc is also called after the last character of the value has been printed, with #f as the line number and with the length of the last line.
The default proc procedure prints a newline whenever the line number is not 0 and the column count is not 'infinity, always returning 0. A custom proc procedure can be used to print extra text before each line of pretty-printed output; the number of characters printed before each line should be returned by proc so that the next line break can be chosen correctly.
The destination port supplied to proc is generally not the port supplied to [pretty-print](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print%29%29) or [pretty-display](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-display%29%29) (or the current output port), but output to this port is ultimately redirected to the port supplied to [pretty-print](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print%29%29) or [pretty-display](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-display%29%29).


#### 13.6.4 Value Output Hook
> ```
(pretty-print-size-hook)	→
(-> any/c boolean? output-port?
    . → .
    (or/c #f exact-nonnegative-integer?))
(pretty-print-size-hook proc) → void?
    proc	:
(-> any/c boolean? output-port?
    . → .
    (or/c #f exact-nonnegative-integer?))
```
(pretty-print-print-hook)	→
(-> any/c boolean? output-port? . → . void?)
(pretty-print-print-hook proc) → void?
    proc	:
(-> any/c boolean? output-port? . → . void?)```

A [parameter](eval-model.html#%28tech._parameter%29) that determines a print hook for pretty-printing. The print-hook procedure is applied to a value for printing when the sizing hook (see [pretty-print-size-hook](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print-size-hook%29%29)) returns an integer size for the value.

The print hook receives three arguments. The first argument is the value to print. The second argument is a boolean: #t for printing like [display](Writing.html#%28def._%28%28quote._~23~25kernel%29._display%29%29) and #f for printing like [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29). The third argument is the destination port; this port is generally not the port supplied to [pretty-print](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print%29%29) or [pretty-display](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-display%29%29) (or the current output port), but output to this port is ultimately redirected to the port supplied to [pretty-print](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print%29%29) or [pretty-display](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-display%29%29).

> ```
(pretty-print-pre-print-hook)	→
(-> any/c output-port? . → . void)
(pretty-print-pre-print-hook proc) → void?
    proc	:
(-> any/c output-port? . → . void)
```


# 13.5 Writing
(pretty-print-post-print-hook)	→
(-> any/c output-port? . → . void)
(pretty-print-post-print-hook proc) → void?
    proc	:
(-> any/c output-port? . → . void)```
A [parameter](eval-model.html#%28tech._parameter%29) that determines a hook procedure to be called just after an object is printed. The hook receives two arguments: the object and the output port. The port is the one supplied to [pretty-print](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print%29%29) or [pretty-display](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-display%29%29) (or the current output port).


#### 13.6.5 Additional Custom-Output Support
> ```
(pretty-printing)	→
(-> pretty-printing on?)
```
(parameter)	→
(-> any)```

Produces an output port that is suitable for recursive pretty printing without actually producing output. Use such a port to tentatively print when proper output depends on the size of recursive prints. After printing, determine the size of the tentative output using [file-position](port-buffers.html#%28def._%28%28quote._~23~25kernel%29._file-position%29%29).

The out argument should be a pretty-printing port, such as the one supplied to a custom-write procedure when [pretty-printing](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-printing%29%29) is set to true, or another tentative output port. The width argument should be a target column width, usually obtained from [pretty-print-columns](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print-columns%29%29), possibly decremented to leave room for a terminator. The overflow-thunk procedure is called if more than width items are printed to the port or if a newline is printed to the port via [pretty-print-newline](#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print-newline%29%29); it can escape from the recursive print through a continuation as a shortcut, but overflow-thunk can also return, in which case it is called every time afterward that additional output is written to the port.

After tentative printing, either accept the result with [tentative-pretty-print-port-transfer](#%28def._%28%28lib._racket%2Fpretty..rkt%29._tentative-pretty-print-port-transfer%29%29) or reject it with [tentative-pretty-print-port-cancel](#%28def._%28%28lib._racket%2Fpretty..rkt%29._tentative-pretty-print-port-cancel%29%29). Failure to accept or cancel properly interferes with graph-structure printing, calls to hook procedures, etc. Explicitly cancel the tentative print even when overflow-thunk escapes from a recursive print.

> ```
(parameter)	→
```


# 13.5 Writing
(parameter)	→```
Cancels the content of tentative-out, which was produced by [make-tentative-pretty-print-output-port](#%28def._%28%28lib._racket%2Fpretty..rkt%29._make-tentative-pretty-print-output-port%29%29). The main effect of canceling is that graph-reference definitions are undone, so that a future print of a graph-referenced object includes the defining #‹n›=.
------------------------------------------------------------------------


# 13.7 Reader Extension


### 13.7 Reader Extension
Racket’s reader can be extended in three ways: through a reader-macro procedure in a [readtable](readtables.html#%28tech._readtable%29) (see [Readtables](readtables.html)), through a #reader form (see [Reading via an Extension](reader.html#%28part._parse-reader%29)), or through a custom-port byte reader that returns a “special” result procedure (see [Custom Ports](customport.html)). All three kinds of reader extension procedures accept similar arguments, and their results are treated in the same way by [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29) and [read-syntax](Reading.html#%28def._%28%28quote._~23~25kernel%29._read-syntax%29%29) (or, more precisely, by the default read handler; see [port-read-handler](Reading.html#%28def._%28%28quote._~23~25kernel%29._port-read-handler%29%29)).
|                                                                                |
|----------------------------------------------------------------------------------------|
|     [13.7.1 Readtables](readtables.html)                    |
|     [13.7.2 Reader-Extension Procedures](reader-procs.html) |
|     [13.7.3 Special Comments](special-comments.html)        |
------------------------------------------------------------------------


# 13.7.1 Readtables


#### 13.7.1 Readtables
The dispatch table in [Delimiters and Dispatch](reader.html#%28part._default-readtable-dispatch%29) corresponds to the default readtable. By creating a new readtable and installing it via the [current-readtable](Reading.html#%28def._%28%28quote._~23~25kernel%29._current-readtable%29%29) parameter, the reader’s behavior can be extended.
A readtable is consulted at specific times by the reader:
-   when looking for the start of a datum;
-   when determining how to parse a datum that starts with #;
-   when looking for a delimiter to terminate a symbol or number;
-   when looking for an opener (such as (), closer (such as )), or . after the first character parsed as a sequence for a pair, list, vector, or hash table; or
-   when looking for an opener after #‹n› in a vector of specified length ‹n›.
The readtable is ignored at other times. In particular, after parsing a character that is mapped to the default behavior of ;, the readtable is ignored until the comment’s terminating newline is discovered. Similarly, the readtable does not affect string parsing until a closing double-quote is found. Meanwhile, if a character is mapped to the default behavior of (, then it starts a sequence that is closed by any character that is mapped to a closing parenthesis ). An apparent exception is that the default parsing of \| quotes a symbol until a matching character is found, but the parser is simply using the character that started the quote; it does not consult the readtable.


# 13.7.1 Readtables
For many contexts, #f identifies the default readtable. In particular, #f is the initial value for the [current-readtable](Reading.html#%28def._%28%28quote._~23~25kernel%29._current-readtable%29%29) parameter, which causes the reader to behave as described in [The Reader](reader.html).
> ```
(readtable? v)  →  boolean?
  v : any/c
```
Returns #t if v is a readtable, #f otherwise.

> ```
(make-readtable readtable key mode action ...) → readtable?
  readtable : (or/c readtable? #f)
  key : (or/c char? #f)
   mode   :   ( or/c ' terminating-macro
> ' non-terminating-macro
> ' dispatch-macro
> char? )

   action   :   ( or/c procedure?
> readtable?
> #f )```

Creates a new readtable that is like readtable (which can be #f to indicate the default readtable), except that the reader’s behavior is modified for each key according to the given mode and action. The [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29) for [make-readtable](#%28def._%28%28quote._~23~25kernel%29._make-readtable%29%29) applies to all three of key, mode, and action; in other words, the total number of arguments to [make-readtable](#%28def._%28%28quote._~23~25kernel%29._make-readtable%29%29) must be 1 modulo 3.

The possible combinations for key, mode, and action are as follows:

-   char 'terminating-macro proc — causes char to be parsed as a delimiter, and an unquoted/uncommented char in the input string triggers a call to the reader macro proc; the activity of proc is described further below. Conceptually, characters like ;, (, and ) are mapped to terminating reader macros in the default readtable.

-   char 'non-terminating-macro proc — like the 'terminating-macro variant, but char is not treated as a delimiter, so it can be used in the middle of an identifier or number. Conceptually, # is mapped to a non-terminating macro in the default readtable.

-   char 'dispatch-macro proc — like the 'non-terminating-macro variant, but for char only when it follows a # (or, more precisely, when the character follows one that has been mapped to the behavior of # in the default readtable).

-   char like-char readtable — causes char to be parsed in the same way that like-char is parsed in readtable, where readtable can be #f to indicate the default readtable. (The mapping of char does not apply after #, which is configured separately via 'dispatch-macro.) Mapping a character to the same actions as \| in the default reader means that the character starts quoting for symbols, and the same character terminates the quote; in contrast, mapping a character to the same action as a " means that the character starts a string, but the string is still terminated with a closing ". Finally, mapping a character to an action in the default readtable means that the character’s behavior is sensitive to parameters that affect the original character; for example, mapping a character to the same action as a curly brace { in the default readtable means that the character is disallowed when the [read-curly-brace-as-paren](Reading.html#%28def._%28%28quote._~23~25kernel%29._read-curly-brace-as-paren%29%29) parameter is set to #f.

-   #f 'non-terminating-macro proc — replaces the macro used to parse characters with no specific mapping: i.e., the characters (other than # or \|) that can start a symbol or number with the default readtable.

If multiple 'dispatch-macro mappings are provided for a single char, all but the last one are ignored. Similarly, if multiple non-'dispatch-macro mappings are provided for a single char, all but the last one are ignored.

A reader macro proc must accept six arguments, and it can optionally accept two arguments. The first two arguments are always the character that triggered the reader macro and the input port for reading. When the reader macro is triggered by [read-syntax](Reading.html#%28def._%28%28quote._~23~25kernel%29._read-syntax%29%29) (or [read-syntax/recursive](Reading.html#%28def._%28%28quote._~23~25kernel%29._read-syntax%2Frecursive%29%29)), the procedure is passed four additional arguments that represent a source location for already-consumed character(s): the source name, a line number or #f, a column number or #f, and a position or #f. When the reader macro is triggered by [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29) (or [read/recursive](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%2Frecursive%29%29)), the procedure is passed only two arguments if it accepts two arguments, otherwise it is passed six arguments where the third is always #f. See [Reader-Extension Procedures](reader-procs.html) for information on the procedure’s results.

A reader macro normally reads characters from the given input port to produce a value to be used as the “reader macro-expansion” of the consumed characters. The reader macro might produce a special-comment value (see [Special Comments](special-comments.html)) to cause the consumed character to be treated as whitespace, and it might use [read/recursive](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%2Frecursive%29%29) or [read-syntax/recursive](Reading.html#%28def._%28%28quote._~23~25kernel%29._read-syntax%2Frecursive%29%29).

> ```
(readtable-mapping readtable char)
   →    ( or/c char?
> ' terminating-macro
> ' non-terminating-macro )
(or/c #f procedure?)
(or/c #f procedure?)

  readtable : readtable?
  char : char?
```


# 13.7.1 Readtables
(parameter)	→
(-> wrap (parse port (lambda () (read-syntax/recursive src port #f (make-delims-table))) src))```
Creates a special-comment value that encapsulates v. The [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29), [read-syntax](Reading.html#%28def._%28%28quote._~23~25kernel%29._read-syntax%29%29), etc., procedures treat values constructed with [make-special-comment](#%28def._%28%28quote._~23~25kernel%29._make-special-comment%29%29) as delimiting whitespace when returned by a reader-extension procedure (see [Reader-Extension Procedures](reader-procs.html)).
> ```
(special-comment? v)  →  boolean?
  v : any/c


# 13.7.1 Readtables
```
Returns #t if v is the result of make-special-comment, #f otherwise.

> ```
(special-comment-value sc)   →   any
  sc : special-comment?```

Returns the value encapsulated by the special-comment value sc. This value is never used directly by a reader, but it might be used by the context of a [read-char-or-special](Byte_and_String_Input.html#%28def._%28%28quote._~23~25kernel%29._read-char-or-special%29%29), etc., call that detects a special comment.

------------------------------------------------------------------------

# 13.8 Printer Extension

### 13.8 Printer Extension

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>value</p>

<p>[gen:custom-write](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._gen~3acustom-write%29%29) : [any/c](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fprivate%2Fmisc..rkt%29._any%2Fc%29%29)</p></blockquote></td></tr></tbody></table>

A [generic interface](struct-generics.html#%28tech._generic._interface%29) (see [Generic Interfaces](struct-generics.html)) that supplies a method, write-proc used by the default printer to [display](Writing.html#%28def._%28%28quote._~23~25kernel%29._display%29%29), [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29), or [print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29) instances of the structure type.

A write-proc method takes three arguments: the structure to be printed, the target port, and an argument that is #t for [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29) mode, #f for [display](Writing.html#%28def._%28%28quote._~23~25kernel%29._display%29%29) mode, or 0 or 1 indicating the current [quoting depth](printing.html#%28tech._quoting._depth%29) for [print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29) mode. The procedure should print the value to the given port using [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29), [display](Writing.html#%28def._%28%28quote._~23~25kernel%29._display%29%29), [print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29), [fprintf](Writing.html#%28def._%28%28quote._~23~25kernel%29._fprintf%29%29), [write-special](Byte_and_String_Output.html#%28def._%28%28quote._~23~25kernel%29._write-special%29%29), etc.

The [port write handler](Writing.html#%28tech._port._write._handler%29), [port display handler](Writing.html#%28tech._port._display._handler%29), and [print handler](eval.html#%28tech._print._handler%29) are specially configured for a port given to a custom-write procedure. Printing to the port through [display](Writing.html#%28def._%28%28quote._~23~25kernel%29._display%29%29), [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29), or [print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29) prints a value recursively with sharing annotations. To avoid a recursive print (i.e., to print without regard to sharing with a value currently being printed), print instead to a string or pipe and transfer the result to the target port using [write-string](Byte_and_String_Output.html#%28def._%28%28quote._~23~25kernel%29._write-string%29%29) or [write-special](Byte_and_String_Output.html#%28def._%28%28quote._~23~25kernel%29._write-special%29%29). To print recursively to a port other than the one given to the custom-write procedure, copy the given port’s write handler, display handler, and print handler to the other port.

The port given to write-proc is not necessarily the actual target port. In particular, to detect cycles, sharing, and quoting modes (in the case of [print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29)), the printer invokes a custom-write procedure with a port that records information about recursive prints, and does not retain any other output. This information-gathering phase needs the same objects (in the [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29) sense) to be printed as later, so that the recorded information can be correlated with printed values.

Recursive print operations may trigger an escape from a call to write-proc. For example, printing may escape during pretty-printing where a tentative print attempt overflows the line, or it may escape while printing error output that is constrained to a limited width.

The following example definition of a tuple type includes a write-proc procedure that prints the tuple’s list content using angle brackets in [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29) and [print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29) mode and no brackets in [display](Writing.html#%28def._%28%28quote._~23~25kernel%29._display%29%29) mode. Elements of the tuple are printed recursively, so that graph and cycle structure can be represented.

Examples:

> ```racket
> ( define ( tuple-print tuple port mode ) ( when mode ( write-string "<" port ) ) ( let ( [ l ( tuple-ref tuple ) ] [ recur ( case mode [ ( #t ) write ] [ ( #f ) display ] [ else ( lambda ( p port ) ( print p port mode ) ) ] ) ] ) ( unless ( zero? ( vector-length l ) ) ( recur ( vector-ref l 0 ) port ) ( for-each ( lambda ( e ) ( write-string ", " port ) ( recur e port ) ) ( cdr ( vector->list l ) ) ) ) ) ( when mode ( write-string ">" port ) ) )
> ( struct tuple ( ref ) #:methods gen:custom-write [ ( define write-proc tuple-print ) ] )
> > ( display ( tuple # ( 1 2 "a" ) ) )
> 1, 2, a
> > ( print ( tuple # ( 1 2 "a" ) ) )
> <1, 2, "a">
> > ( let ( [ t ( tuple ( vector 1 2 "a" ) ) ] ) ( vector-set! ( tuple-ref t ) 0 t ) ( write t ) )
> #0=<#0#, 2, "a">
> ```

The [make-constructor-style-printer](structutils.html#%28def._%28%28lib._racket%2Fstruct..rkt%29._make-constructor-style-printer%29%29) function can help in the implementation of a write-proc, as in this example:

Examples:

> ```racket
> ( require racket/struct )
> ( struct point ( x y ) #:methods gen:custom-write [ ( define write-proc ( make-constructor-style-printer ( lambda ( obj ) ' point ) ( lambda ( obj ) ( list ( point-x obj ) ( point-y obj ) ) ) ) ) ] )
> > ( print ( point 1 2 ) )
> (point 1 2)
> > ( write ( point 1 2 ) )
> #<point: 1 2>
> ```

Changed in version 8.7.0.5 of package base: Added a check so that omitting write-proc is now a syntax error.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>value</p>

<p>[prop:custom-write](#%28def._%28%28quote._~23~25kernel%29._prop~3acustom-write%29%29) : [struct-type-property?](structprops.html#%28def._%28%28quote._~23~25kernel%29._struct-type-property~3f%29%29)</p></blockquote></td></tr></tbody></table>

A [structure type property](structprops.html#%28tech._structure._type._property%29) (see [Structure Type Properties](structprops.html)) that supplies a procedure that corresponds to [gen:custom-write](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._gen~3acustom-write%29%29)’s write-proc. Using the [prop:custom-write](#%28def._%28%28quote._~23~25kernel%29._prop~3acustom-write%29%29) property is discouraged; use the [gen:custom-write](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._gen~3acustom-write%29%29) [generic interface](struct-generics.html#%28tech._generic._interface%29) instead.

> ```
(custom-write? v)  →  boolean?
  v : any/c
```


# 13.7.1 Readtables
Returns #t if v has the prop:custom-write property, #f otherwise.
> ```
(custom-write-accessor v)
   →   (custom-write? output-port? (or/c #t #f 0 1) .  →  . any)
  v : custom-write?```
Returns the custom-write procedure associated with v.
>
<colgroup><col style="width: 100%" /></colgroup>

<colgroup><col style="width: 100%" /></colgroup>

value

[prop:custom-print-quotable](#%28def._%28%28quote._~23~25kernel%29._prop~3acustom-print-quotable%29%29) : [struct-type-property?](structprops.html#%28def._%28%28quote._~23~25kernel%29._struct-type-property~3f%29%29)

<colgroup><col style="width: 100%" /></colgroup>

value

[custom-print-quotable?](#%28def._%28%28quote._~23~25kernel%29._custom-print-quotable~3f%29%29) : [struct-type-property?](structprops.html#%28def._%28%28quote._~23~25kernel%29._struct-type-property~3f%29%29)

<colgroup><col style="width: 100%" /></colgroup>

value


# 13.7.1 Readtables

[custom-print-quotable-accessor](#%28def._%28%28quote._~23~25kernel%29._custom-print-quotable-accessor%29%29) : [struct-type-property?](structprops.html#%28def._%28%28quote._~23~25kernel%29._struct-type-property~3f%29%29)

A property and associated predicate and accessor. The property value is one of 'self, 'never, 'maybe, or 'always. When a structure has this property in addition to a [prop:custom-write](#%28def._%28%28quote._~23~25kernel%29._prop~3acustom-write%29%29) property value, then the property value affects printing in [print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29) mode; see [The Printer](printing.html). When a value does not have the [prop:custom-print-quotable](#%28def._%28%28quote._~23~25kernel%29._prop~3acustom-print-quotable%29%29), it is equivalent to having the 'self property value, which is suitable both for self-quoting forms and printed forms that are unreadable.
------------------------------------------------------------------------


# 13.9 Serialization


### 13.9 Serialization
|                                                                                |                                                                                |
|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:|
|  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/serialize]()) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") |
The bindings documented in this section are provided by the [racket/serialize]() library, not [racket/base](index.html) or [racket](index.html).
> ```
(serializable? v)  →  boolean?
  v : any/c


# 13.9 Serialization
```
Returns #t if v appears to be serializable, without checking the content of compound values, and #f otherwise. See serialize for an enumeration of serializable values.

> ```
(serialize
    v
   [ #:relative-directory relative-to
    #:deserialize-relative-directory deserialize-relative-to)

   →   any
  v : serializable?
   relative-to   :   ( or/c ( and/c path? complete-path? )
> ( cons/c ( and/c path? complete-path? )
> ( and/c path? complete-path? ) )
> #f )   =   #f

   deserialize-relative-to   :   ( or/c ( and/c path? complete-path? )
> ( cons/c ( and/c path? complete-path? )
> ( and/c path? complete-path? ) )
> #f )
      =   relative-to```

Returns a value that encapsulates the value v. This value includes only readable values, so it can be written to a stream with [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29) or [s-exp->fasl](fasl.html#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29), later read from a stream using [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29) or [fasl->s-exp](fasl.html#%28def._%28%28lib._racket%2Ffasl..rkt%29._fasl-~3es-exp%29%29), and then converted to a value like the original using [deserialize](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._deserialize%29%29). Serialization followed by deserialization produces a value with the same graph structure and mutability as the original value, but the serialized value is a plain tree (i.e., no sharing).

The following kinds of values are serializable:

-   structures created through [serializable-struct](#%28form._%28%28lib._racket%2Fserialize..rkt%29._serializable-struct%29%29) or [serializable-struct/versions](#%28form._%28%28lib._racket%2Fserialize..rkt%29._serializable-struct%2Fversions%29%29), or more generally structures with the [prop:serializable](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._prop~3aserializable%29%29) property (see [prop:serializable](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._prop~3aserializable%29%29) for more information);

-   [prefab](structures.html#%28tech._prefab%29) structures;

-   instances of classes defined with [define-serializable-class](objectserialize.html#%28form._%28%28lib._racket%2Fprivate%2Fclass-internal..rkt%29._define-serializable-class%29%29) or [define-serializable-class*](objectserialize.html#%28form._%28%28lib._racket%2Fprivate%2Fclass-internal..rkt%29._define-serializable-class%2A%29%29);

-   [booleans](booleans.html#%28tech._boolean%29), [numbers](numbers.html#%28tech._number%29), [characters](characters.html#%28tech._character%29), [interned](reader.html#%28tech._interned%29) symbols, [unreadable symbols](symbols.html#%28tech._unreadable._symbol%29), [keywords](keywords.html#%28tech._keyword%29), [strings](strings.html#%28tech._string%29), [byte strings](bytestrings.html#%28tech._byte._string%29), [paths](pathutils.html#%28tech._path%29) (for a specific convention), [regexp values](regexp.html#%28tech._regexp._value%29), [#<void>](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=void_undefined.html&version=8.18.0.13), and the empty list;

-   [pairs](pairs.html#%28tech._pair%29), [mutable pairs](mpairs.html#%28tech._mutable._pair%29), [vectors](vectors.html#%28tech._vector%29), [flvectors](flonums.html#%28tech._flvector%29), [fxvectors](fixnums.html#%28tech._fxvector%29), [box](boxes.html#%28tech._box%29)es, [hash tables](hashtables.html#%28tech._hash._table%29), [sets](sets.html#%28tech._set%29), and [treelists](treelist.html#%28tech._treelist%29);

-   [date](time.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%29%29), [date*](time.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%2A%29%29), [arity-at-least](procedures.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._arity-at-least%29%29) and [srcloc](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._srcloc%29%29) structures; and

-   [module path index](Module_Names_and_Loading.html#%28tech._module._path._index%29) values.

Serialization succeeds for a compound value, such as a pair, only if all content of the value is serializable. If a value given to [serialize](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._serialize%29%29) is not completely serializable, the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised.

If v contains a cycle (i.e., a collection of objects that are all reachable from each other), then v can be serialized only if the cycle includes a mutable value, where a [prefab](structures.html#%28tech._prefab%29) structure counts as mutable only if all of its fields are mutable.

If relative-to is not #f, then paths to serialize that extend the path in relative-to are recorded in relative and platform-independent form. The possible values and treatment of relative-to are the same as for [current-write-relative-directory](Writing.html#%28def._%28%28quote._~23~25kernel%29._current-write-relative-directory%29%29).

If deserialize-relative-to is not #f, then any paths to deserializers as extracted via [prop:serializable](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._prop~3aserializable%29%29) are recorded in relative form. Note that relative-to and deserialize-relative-to are independent, but deserialize-relative-to defaults to relative-to.

> > > The [serialize](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._serialize%29%29) and [deserialize](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._deserialize%29%29) functions currently do not handle certain cyclic values that [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29) and [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29) can handle, such as '#0=(#0#).

See [deserialize](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._deserialize%29%29) for information on the format of serialized data.

Changed in version 6.5.0.4 of package base: Added keywords and regexp values as serializable.
Changed in version 7.0.0.6: Added the #:relative-directory and #:deserialize-relative-directory arguments.

> ```
(deserialize v)  →  any
  v : any/c
```


# 13.9 Serialization
(1)	→
(-> as a fallback)```
Returns #t if v1 and v2 represent the same serialization information.
More precisely, it returns the same value that ([equal?](Equality.html#%28def._%28%28quote._~23~25kernel%29._equal~3f%29%29) ([deserialize](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._deserialize%29%29) v1) ([deserialize](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._deserialize%29%29) v2)) would return if
-   all structure types whose deserializers are accessed with distinct module paths are actually distinct types;
-   all structure types are transparent; and
-   all structure instances contain only the constituent values recorded in each of v1 and v2.
> ```
(deserialize-module-guard)	→
(-> module-path? symbol?
    (or/c void? (cons/c module-path? symbol?)))
(deserialize-module-guard guard) → void?
    guard	:
(-> module-path? symbol?
    (or/c void? (cons/c module-path? symbol?)))


# 13.9 Serialization
```
(parameter)	→```

Like [struct](define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29), but instances of the structure type are serializable with [serialize](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._serialize%29%29). This form is allowed only at the top level or in a module’s top level (so that deserialization information can be found later).

Serialization supports cycles involving the created structure type only when all fields are mutable (or when the cycle can be broken through some other mutable value).

In addition to the bindings generated by [struct](define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29), [serializable-struct](#%28form._%28%28lib._racket%2Fserialize..rkt%29._serializable-struct%29%29) binds deserialize-info:id-v0 to deserialization information. Furthermore, in a module context, it automatically [provide](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._provide%29%29)s this binding in a deserialize-info submodule using [module+](module.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._module%2B%29%29).

The [serializable-struct](#%28form._%28%28lib._racket%2Fserialize..rkt%29._serializable-struct%29%29) form enables the construction of structure instances from places where id is not accessible, since deserialization must construct instances. Furthermore, [serializable-struct](#%28form._%28%28lib._racket%2Fserialize..rkt%29._serializable-struct%29%29) provides limited access to field mutation, but only for instances generated through the deserialization information bound to deserialize-info:id-v0. See [make-deserialize-info](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._make-deserialize-info%29%29) for more information.

Beware that the previous paragraph means that if a serializable struct is exported via [contract-out](attaching-contracts-to-values.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._contract-out%29%29), for example, the contracts are not checked during deserialization. Consider using [struct-guard/c](attaching-contracts-to-values.html#%28form._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._struct-guard%2Fc%29%29) instead.

The -v0 suffix on the deserialization enables future versioning on the structure type through [serializable-struct/versions](#%28form._%28%28lib._racket%2Fserialize..rkt%29._serializable-struct%2Fversions%29%29).

When a supertype is supplied as maybe-super, compile-time information bound to the supertype identifier must include all of the supertype’s field accessors. If any field mutator is missing, the structure type will be treated as immutable for the purposes of marshaling (so cycles involving only instances of the structure type cannot be handled by the deserializer).

Examples:

> ```racket
> > ( serializable-struct point ( x y ) )
> > ( point-x ( deserialize ( serialize ( point 1 2 ) ) ) )
> 1
> ```

> ```
syntax

(define-serializable-struct id-maybe-super (field ...)
> struct-option ... )
```


# 13.9 Serialization
Like serializable-struct, but with the supertype syntax and default constructor name of define-struct.
> ```
syntax
(serializable-struct/versions id maybe-super vers (field ...)
> ( other-version-clause ... )
> struct-option ... )
other-version-clause   =   ( other-vers make-proc-expr
> cycle-make-proc-expr )```
Like [serializable-struct](#%28form._%28%28lib._racket%2Fserialize..rkt%29._serializable-struct%29%29), but the generated deserializer binding is deserialize-info:id-vvers. In addition, deserialize-info:id-vother-vers is bound for each other-vers. The vers and each other-vers must be a literal, exact, nonnegative integer.
Each make-proc-expr should produce a procedure, and the procedure should accept as many argument as fields in the corresponding version of the structure type, and it produces an instance of id. Each cycle-make-proc-expr should produce a procedure of no arguments; this procedure should return two values: an instance x of id (typically with #f for all fields) and a procedure that accepts another instance of id and copies its field values into x.
Examples:


# 13.9 Serialization
> ```racket
> > ( serializable-struct point ( x y ) #:mutable #:transparent )
> > ( define ps ( serialize ( point 1 2 ) ) )
> > ( deserialize ps )
> (point 1 2)
> > ( define x ( point 1 10 ) )
> > ( set-point-x! x x )
> > ( define xs ( serialize x ) )
> > ( deserialize xs )
> #0=(point #0# 10)
> > ( serializable-struct/versions point 1 ( x y z ) ( [ 0 ; Constructor for simple v0 instances: ( lambda ( x y ) ( point x y 0 ) ) ; Constructor for v0 instance in a cycle: ( lambda ( ) ( let ( [ p0 ( point #f #f 0 ) ] ) ( values p0 ( lambda ( p ) ( set-point-x! p0 ( point-x p ) ) ( set-point-y! p0 ( point-y p ) ) ) ) ) ) ] ) #:mutable #:transparent )
> > ( deserialize ( serialize ( point 4 5 6 ) ) )
> (point 4 5 6)
> > ( deserialize ps )
> (point 1 2 0)
> > ( deserialize xs )
> #0=(point #0# 10 0)
> ```
> ```
syntax
(define-serializable-struct/versions id-maybe-super vers (field ...)
> ( other-version-clause ... )
> struct-option ... )


# 13.9 Serialization
```
Like serializable-struct/versions, but with the supertype syntax and default constructor name of define-struct.

> ```
(make-deserialize-info make cycle-make)   →   any
  make : procedure?
  cycle-make : (  →   (values any/c procedure?))```

Produces a deserialization information record to be used by [deserialize](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._deserialize%29%29). This information is normally tied to a particular structure because the structure has a [prop:serializable](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._prop~3aserializable%29%29) property value that points to a top-level variable or module-exported variable that is bound to deserialization information.

The make procedure should accept as many arguments as the structure’s serializer put into a vector; normally, this is the number of fields in the structure. It should return an instance of the structure.

The cycle-make procedure should accept no arguments, and it should return two values: a structure instance x (with dummy field values) and an update procedure. The update procedure takes another structure instance generated by the make, and it transfers the field values of this instance into x.

> <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote>

<p>value</p>

<p>[prop:serializable](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._prop~3aserializable%29%29) : [struct-type-property?](structprops.html#%28def._%28%28quote._~23~25kernel%29._struct-type-property~3f%29%29)</p></blockquote></td></tr></tbody></table>

This property identifies structures and structure types that are [serializable](#%28tech._serializable%29). The property value should be constructed with [make-serialize-info](#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._make-serialize-info%29%29).

> ```
(parameter)	→
(-> any/c . → . vector?)
```


# 13.9 Serialization
(current-load-relative-directory)	→
(-> or/c (void) bytes?)```
The [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29) function serializes v to a byte string, printing it directly to out if out is an output port or returning the byte string otherwise. The [fasl->s-exp](#%28def._%28%28lib._racket%2Ffasl..rkt%29._fasl-~3es-exp%29%29) function decodes a value from a byte string (supplied either directly or as an input port) that was encoded with [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29).
The v argument must be a value that could be [quote](quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29)d as a literal—that is, a value without syntax objects for which ([compile](eval.html#%28def._%28%28quote._~23~25kernel%29._compile%29%29) \`',v) would work and be [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29)able after [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29)—or it can include [correlated objects](linklets.html#%28tech._correlated._object%29) mixed with those values. The byte string produced by [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29) does not use the same format as compiled code, however.


# 13.9 Serialization
If a value within v is not valid as a [quote](quote.html#%28form._%28%28quote._~23~25kernel%29._quote%29%29)d literal, and if handle-fail is not #f, then handle-fail is called on the nested value, and the result of handle-fail is written in that value’s place. The handle-fail procedure might raise an exception instead of returning a replacement value. If handle-fail is #f, then the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised when an invalid value is encountered.
If external-lift? is not #f, then it receives each value v-sub encountered in v by [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29). If the result of external-lift? on v-sub is true, then v-sub is not encoded in the result, and it instead treated as externally lifted. A deserializing [fasl->s-exp](#%28def._%28%28lib._racket%2Ffasl..rkt%29._fasl-~3es-exp%29%29) receives a external-lifts vector that has one value for each externally lifted value, in the same order as passed to external-lift? on serialization.


# 13.9 Serialization
Like ([compile](eval.html#%28def._%28%28quote._~23~25kernel%29._compile%29%29) \`',v), [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29) does not preserve graph structure, support cycles, or handle non-[prefab](structures.html#%28tech._prefab%29) structures. Compose [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29) with [serialize](serialization.html#%28def._%28%28lib._racket%2Fprivate%2Fserialize..rkt%29._serialize%29%29) to preserve graph structure, handle cyclic data, and encode serializable structures. The [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29) and [fasl->s-exp](#%28def._%28%28lib._racket%2Ffasl..rkt%29._fasl-~3es-exp%29%29) functions consult [current-write-relative-directory](Writing.html#%28def._%28%28quote._~23~25kernel%29._current-write-relative-directory%29%29) and [current-load-relative-directory](eval.html#%28def._%28%28quote._~23~25kernel%29._current-load-relative-directory%29%29) (falling back to [current-directory](Filesystem.html#%28def._%28%28quote._~23~25kernel%29._current-directory%29%29)), respectively, in the same way as bytecode saving and loading to store paths in relative form, and they similarly allow and convert constrained [srcloc](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._srcloc%29%29) values (see [Printing Compiled Code](printing.html#%28part._print-compiled%29)).


# 13.9 Serialization
Unless keep-mutable? is provided as true to [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29), then mutable values in v are replaced by immutable values when the result is decoded by [fasl->s-exp](#%28def._%28%28lib._racket%2Ffasl..rkt%29._fasl-~3es-exp%29%29). Unless datum-intern? is provided as #f, then any immutable value produced by [fasl->s-exp](#%28def._%28%28lib._racket%2Ffasl..rkt%29._fasl-~3es-exp%29%29) is filtered by [datum-intern-literal](stxops.html#%28def._%28%28quote._~23~25kernel%29._datum-intern-literal%29%29). The defaults make the composition of [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29) and [fasl->s-exp](#%28def._%28%28lib._racket%2Ffasl..rkt%29._fasl-~3es-exp%29%29) behave like the composition of [write](Writing.html#%28def._%28%28quote._~23~25kernel%29._write%29%29) and [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29).
If skip-prefix? is not #f, then a prefix that identifies the stream as a serialization is not written by [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29) or read by [fasl->s-exp](#%28def._%28%28lib._racket%2Ffasl..rkt%29._fasl-~3es-exp%29%29). Omitting a prefix can save a small amount of space, which can useful when serializing small values, but it gives up a sanity check on the [fasl->s-exp](#%28def._%28%28lib._racket%2Ffasl..rkt%29._fasl-~3es-exp%29%29) that is often useful.


# 13.9 Serialization
The byte-string encoding produced by [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29) is independent of the Racket version, except as future Racket versions introduce extensions that are not currently recognized. In particular, the result of [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29) will be valid as input to any future version of [fasl->s-exp](#%28def._%28%28lib._racket%2Ffasl..rkt%29._fasl-~3es-exp%29%29) (as long as the skip-prefix? arguments are consistent).
Examples:
> ```racket
> > ( define fasl ( s-exp->fasl ( list # ( "speed" ) ' racer #\! ) ) )
> > fasl
> #"racket/fasl:\0\24\34\3 \1\23\5speed\16\5racer\r!"
> > ( fasl->s-exp fasl )
> '(#("speed") racer #\!)
> ```
Changed in version 6.90.0.21 of package base: Made [s-exp->fasl](#%28def._%28%28lib._racket%2Ffasl..rkt%29._s-exp-~3efasl%29%29) format version-independent and added the #:keep-mutable? and #:datum-intern? arguments.
Changed in version 7.3.0.7: Added support for [correlated objects](linklets.html#%28tech._correlated._object%29).
Changed in version 7.5.0.3: Added the #:handle-fail argument.
Changed in version 7.5.0.9: Added the #:external-lift? and #:external-lifts arguments.
Changed in version 8.9.0.4: Added support for [fxvectors](fixnums.html#%28tech._fxvector%29) and [flvectors](flonums.html#%28tech._flvector%29).
------------------------------------------------------------------------


# 13.11 Cryptographic Hashing


### 13.11 Cryptographic Hashing
> ```
(sha1-bytes in [start end) → bytes?
  in : (or/c bytes? input-port?)
  start : exact-nonnegative-integer? = 0
  end : (or/c #f exact-nonnegative-integer?) = #f
(sha224-bytes in [start end)  →  bytes?
  in : (or/c bytes? input-port?)
  start : exact-nonnegative-integer? = 0
  end : (or/c #f exact-nonnegative-integer?) = #f
(sha256-bytes in [start end)  →  bytes?
  in : (or/c bytes? input-port?)
  start : exact-nonnegative-integer? = 0
  end : (or/c #f exact-nonnegative-integer?) = #f
```
(parameter)	→
(-> sha1-bytes #"abc")```

Returns #t if v is a namespace value, #f otherwise.

> ```
(make-empty-namespace)  →  namespace?
```
Creates a new namespace that is empty, and whose module registry contains only mappings for some internal, predefined modules, such as '#%kernel. The namespace’s base phase is the same as the base phase of the current namespace. Attach modules from an existing namespace to the new one with namespace-attach-module.
The new namespace is associated with a new root namespace, which has the same module registry as the returned namespace and has a base phase of 0. The new root namespace is the same as the returned namespace if both have base phase 0.
> ```
(make-base-empty-namespace)   →   namespace?```


# 13.11 Cryptographic Hashing
Creates a new empty [namespace](syntax-model.html#%28tech._namespace%29) like [make-empty-namespace](#%28def._%28%28quote._~23~25kernel%29._make-empty-namespace%29%29), but with [racket/base](index.html) attached. The namespace’s [base phase](syntax-model.html#%28tech._base._phase%29) is the same as the [phase](eval-model.html#%28tech._phase%29) in which the [make-base-empty-namespace](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._make-base-empty-namespace%29%29) function was created.
> ```
(make-base-namespace)  →  namespace?
```
Creates a new namespace like make-empty-namespace, but with racket/base attached and required into the top-level environment. The namespace’s base phase is the same as the phase in which the make-base-namespace function was created.

>
<colgroup><col style="width: 100%" /></colgroup>

syntax

(define-namespace-anchor id)

Binds id to a namespace anchor that can be used with namespace-anchor  →  empty-namespace and namespace-anchor  →  namespace.

This form can be used only in a top-level context or in a module-context.

> ```
(namespace-anchor? v) → boolean?
  v : any/c```

Returns #t if v is a namespace-anchor value, #f otherwise.

> ```
(namespace-anchor  →  empty-namespace a)  →  namespace?
  a : namespace-anchor?
```


# 13.11 Cryptographic Hashing
Returns an empty namespace that shares a module registry and root namespace with the source of the anchor, and whose base phase is the phase in which the anchor was created.
If the anchor is from a define-namespace-anchor form in a module context, then the source is the namespace in which the containing module is instantiated. If the anchor is from a define-namespace-anchor form in a top-level content, then the source is the namespace in which the anchor definition was evaluated.
> ```
(namespace-anchor  →  namespace a)   →   namespace?
  a : namespace-anchor?```
Returns a namespace corresponding to the source of the anchor.
If the anchor is from a [define-namespace-anchor](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-namespace-anchor%29%29) form in a module context, then the result is a namespace for the module’s body in the anchor’s phase. The result is the same as a namespace obtained via [module->namespace](#%28def._%28%28quote._~23~25kernel%29._module-~3enamespace%29%29), and the module is similarly made [available](eval-model.html#%28tech._available%29) if it is not available already.
If the anchor is from a [define-namespace-anchor](#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define-namespace-anchor%29%29) form in a top-level content, then the result is the namespace in which the anchor definition was evaluated.
> ```
(current-namespace)	→
(-> current-namespace n)
(current-namespace n) → void?
    n	:
(-> current-namespace n)


# 13.11 Cryptographic Hashing
```
(parameter)	→```

Similar to [datum->syntax](stxops.html#%28def._%28%28quote._~23~25kernel%29._datum-~3esyntax%29%29) restricted to symbols. The [lexical information](syntax-model.html#%28tech._lexical._information%29) of the resulting identifier corresponds to the top-level environment of the current namespace; the identifier has no source location or properties.

> ```
(current-namespace)	→
(-> current-namespace)
```
(current-namespace)	→
(-> or/c namespace? exact-integer? #f)```
Returns an identifier whose binding is [module](module.html#%28form._%28%28quote._~23~25kernel%29._module%29%29) in the [base phase](syntax-model.html#%28tech._base._phase%29) of where if it is a namespace, or in the where [phase level](syntax-model.html#%28tech._phase._level%29) otherwise.
The [lexical information](syntax-model.html#%28tech._lexical._information%29) of the identifier includes bindings (in the same [phase level](syntax-model.html#%28tech._phase._level%29)) for all syntactic forms that appear in fully expanded code (see [Fully Expanded Programs](syntax-model.html#%28part._fully-expanded%29)), but using the name reported by the second element of [identifier-binding](stxcmp.html#%28def._%28%28quote._~23~25kernel%29._identifier-binding%29%29) for the binding; the [lexical information](syntax-model.html#%28tech._lexical._information%29) may also include other bindings.
> ```
(current-namespace)	→
(-> or/c (→ any) #f)


# 13.11 Cryptographic Hashing
```
(current-namespace)	→
(-> current-namespace)```

Sets the value of sym in the top-level environment of namespace in the [base phase](syntax-model.html#%28tech._base._phase%29), defining sym if it is not already defined.

If map? is supplied as true, then the namespace’s [identifier](syntax-model.html#%28tech._identifier%29) mapping is also adjusted (see [Namespaces](syntax-model.html#%28part._namespace-model%29)) in the [phase level](syntax-model.html#%28tech._phase._level%29) corresponding to the [base phase](syntax-model.html#%28tech._base._phase%29), so that sym maps to the variable.

If as-constant? is true, then the variable is made a constant (so future assignments are rejected) after v is installed as the value.

Changed in version 6.90.0.14 of package base: Added the as-constant? argument.

> ```
(current-namespace)	→
(-> current-namespace)
```
(current-namespace)	→
(-> listof symbol?)```
Returns a list of all symbols that are mapped to variables, syntax, and imports in namespace for the [phase level](syntax-model.html#%28tech._phase._level%29) corresponding to the [namespace](syntax-model.html#%28tech._namespace%29)’s [base phase](syntax-model.html#%28tech._base._phase%29).
> ```
(current-namespace)	→
(-> current-namespace)


# 13.11 Cryptographic Hashing
```
(current-namespace)	→
(-> current-namespace)```

Like [namespace-require](#%28def._%28%28quote._~23~25kernel%29._namespace-require%29%29) for syntax exported from the module, but exported variables at the namespace’s [base phase](syntax-model.html#%28tech._base._phase%29) are treated differently: the export’s current value is copied to a top-level variable in namespace.

Changed in version 6.90.0.16 of package base: Added the namespace optional argument.

> ```
(current-namespace)	→
(-> current-namespace)
```
(current-namespace)	→
(-> current-namespace)```
Like [namespace-require](#%28def._%28%28quote._~23~25kernel%29._namespace-require%29%29), but only the transformer part of the module is executed relative to namespace’s [base phase](syntax-model.html#%28tech._base._phase%29); that is, the module is merely [visit](syntax-model.html#%28tech._visit%29)ed, and not [instantiate](eval-model.html#%28tech._instantiate%29)d (see [Module Expansion, Phases, and Visits](syntax-model.html#%28part._mod-parse%29)). If the required module has not been instantiated before, the module’s variables remain undefined.
Changed in version 6.90.0.16 of package base: Added the namespace optional argument.
> ```
(current-namespace)	→
(-> or module-path? resolved-module-path?)


# 13.11 Cryptographic Hashing
```
(current-namespace)	→
(-> current-namespace)```

Like [namespace-attach-module](#%28def._%28%28quote._~23~25kernel%29._namespace-attach-module%29%29), but the module specified by modname need only be declared (and not necessarily [instantiate](eval-model.html#%28tech._instantiate%29)d) in src-namespace, and the module is merely declared in dest-namespace.

> ```
(current-namespace)	→
(-> current-namespace)
```
Changes the inspector for the instance of the module referenced by modname in namespace’s module registry so that it is controlled by the current code inspector. The given inspector must currently control the invocation of the module in namespace’s module registry, otherwise the inspector is not changed. See also Code Inspectors.
> ```
(namespace-module-registry namespace)   →   any
  namespace : namespace?```
Returns the [module registry](syntax-model.html#%28tech._module._registry%29) of the given namespace. This value is useful only for identification via [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29).
> ```
(namespace-call-with-registry-lock   namespace
    thunk)    →    any
  namespace : namespace?
  thunk : (  →   any)


# 13.11 Cryptographic Hashing
```
(current-namespace)	→
(-> or/c module-path?
    resolved-module-path?
    module-path-index?)```

Returns a namespace that corresponds to the body of an instantiated module in src-namespace’s [module registry](syntax-model.html#%28tech._module._registry%29) and in the src-namespace’s [base phase](syntax-model.html#%28tech._base._phase%29), making the module [available](eval-model.html#%28tech._available%29) for on-demand [visits](syntax-model.html#%28tech._visit%29) at src-namespace’s [base phase](syntax-model.html#%28tech._base._phase%29). The returned namespace has the same [module registry](syntax-model.html#%28tech._module._registry%29) as src-namespace. Modifying a binding in the resulting namespace changes the binding seen in modules that require the namespace’s module.

Module paths in a top-level [require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) expression are resolved with respect to the namespace’s module. New [provide](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._provide%29%29) declarations are not allowed.

If the current code inspector does not control the invocation of the module in src-namespace’s [module registry](syntax-model.html#%28tech._module._registry%29), the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised; see also [Code Inspectors](modprotect.html).

Bindings in the result namespace cannot be modified if the [compile-enforce-module-constants](eval.html#%28def._%28%28quote._~23~25kernel%29._compile-enforce-module-constants%29%29) parameter was true when the module was declared, unless the module declaration itself included assignments to the binding via [set!](set_.html#%28form._%28%28quote._~23~25kernel%29._set%21%29%29).

Changed in version 6.90.0.16 of package base: Added the src-namespace optional argument.

> ```
(current-namespace)	→
(-> current-namespace)
```


# 13.11 Cryptographic Hashing
(parameter)	→
(-> or/c symbol? module-path-index?)```
Returns #f if the module declaration for module-path-index defines sym and exports it unprotected, #t otherwise (which may mean that the symbol corresponds to an unexported definition, a protected export, or an identifier that is not defined at all within the module).
The module-path-index argument can be a symbol; see [Compiled Modules and References](Module_Names_and_Loading.html#%28part._modpathidx%29) for more information on module path indices.
Typically, the arguments to [module-provide-protected?](#%28def._%28%28quote._~23~25kernel%29._module-provide-protected~3f%29%29) correspond to the first two elements of a list produced by [identifier-binding](stxcmp.html#%28def._%28%28quote._~23~25kernel%29._identifier-binding%29%29).
> ```
(variable-reference? v)  →  boolean?
  v : any/c
```
Return #t if v is a variable reference produced by #%variable-reference, #f otherwise.

> ```
(variable-reference-constant? varref)   →   boolean?
  varref : variable-reference?```

Returns #t if the variable represented by varref will retain its current value (i.e., varref refers to a variable that cannot be further modified by [set!](set_.html#%28form._%28%28quote._~23~25kernel%29._set%21%29%29) or [define](define.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._define%29%29)), #f otherwise.

> ```
(variable-reference  →  empty-namespace varref)  →  namespace?
  varref : variable-reference?
```


# 13.11 Cryptographic Hashing
Returns an empty namespace that shares module declarations and instances with the namespace in which varref is instantiated, and with the same phase as varref.
> ```
(variable-reference  →  namespace varref)  →  namespace?
  varref : variable-reference?
```

If varref refers to a [module-level variable](eval-model.html#%28tech._module._level._variable%29), then the result is a namespace for the module’s body in the referenced variable’s [phase](eval-model.html#%28tech._phase%29); the result is the same as a namespace obtained via [module->namespace](#%28def._%28%28quote._~23~25kernel%29._module-~3enamespace%29%29), and the module is similarly made [available](eval-model.html#%28tech._available%29) if it is not available already.

If varref refers to a [top-level variable](eval-model.html#%28tech._top._level._variable%29), then the result is the namespace in which the referenced variable is defined.

> ```
(variable-reference  →  resolved-module-path varref)
  →  (or/c resolved-module-path? #f)
  varref : variable-reference?
```
If varref refers to a module-level variable, the result is a resolved module path naming the module.
If varref refers to a top-level variable, then the result is #f.
> ```
(variable-reference  →  module-path-index varref)
   →   (or/c module-path-index? #f)
  varref : variable-reference?```
If varref refers to a [module-level variable](eval-model.html#%28tech._module._level._variable%29), the result is a [module path index](Module_Names_and_Loading.html#%28tech._module._path._index%29) naming the module.


# 13.11 Cryptographic Hashing
If varref refers to a [top-level variable](eval-model.html#%28tech._top._level._variable%29), then the result is #f.
> ```
(parameter)	→
(-> or/c symbol? (and/c path? complete-path?) #f)
```
If varref refers to a module-level variable, the result is a path or symbol naming the module’s source (which is typically, but not always, the same as in the resolved module path). If the relevant module is a submodule, the result corresponds to the enclosing top-level module’s source.

If varref refers to a top-level variable, then the result is #f.

> ```
(variable-reference  →  phase varref)   →   exact-nonnegative-integer?
  varref : variable-reference?```

Returns the [phase](eval-model.html#%28tech._phase%29) of the variable referenced by varref.

> ```
(variable-reference  →  module-base-phase varref)  →  exact-integer?
  varref : variable-reference?
```
Returns the phase in which the module is instantiated for the variable referenced by varref, or 0 if the variable for varref is not within a module.
For a variable with a module, the result is less than the result of (variable-reference  →  phase varref) by n when the variable is bound at phase level n within the module.
> ```
(variable-reference  →  module-declaration-inspector varref)
   →   inspector?
  varref : variable-reference?```


# 13.11 Cryptographic Hashing
Returns the declaration [inspector](inspectors.html#%28tech._inspector%29) (see [Code Inspectors](modprotect.html)) for the module of varref, where varref must refer to an anonymous module variable as produced by ([#%variable-reference](Locations____variable-reference.html#%28form._%28%28quote._~23~25kernel%29._~23~25variable-reference%29%29)).
> ```
(variable-reference-from-unsafe? varref)  →  boolean?
  varref : variable-reference?
```
(current-eval)	→
(-> any/c . → . any)
(current-eval proc) → void?
    proc	:
(-> any/c . → . any)```

A [parameter](eval-model.html#%28tech._parameter%29) that determines the current evaluation handler. The evaluation handler is a procedure that takes a top-level form and evaluates it, returning the resulting values. The [evaluation handler](#%28tech._evaluation._handler%29) is called by [eval](#%28def._%28%28quote._~23~25kernel%29._eval%29%29), [eval-syntax](#%28def._%28%28quote._~23~25kernel%29._eval-syntax%29%29), the default [load handler](#%28tech._load._handler%29), and [read-eval-print-loop](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._read-eval-print-loop%29%29) to evaluate a top-level form. The handler should evaluate its argument in tail position.

The top-level-form provided to the handler can be a [syntax object](syntax-model.html#%28tech._syntax._object%29), a compiled form, a compiled form wrapped as a syntax object, or an arbitrary datum.

The default handler converts an arbitrary datum to a syntax object using [datum->syntax](stxops.html#%28def._%28%28quote._~23~25kernel%29._datum-~3esyntax%29%29), and then enriches its [lexical information](syntax-model.html#%28tech._lexical._information%29) in the same way as [eval](#%28def._%28%28quote._~23~25kernel%29._eval%29%29). (If top-level-form is a syntax object, then its [lexical information](syntax-model.html#%28tech._lexical._information%29) is not enriched.) The default evaluation handler partially expands the form to splice the body of top-level [begin](begin.html#%28form._%28%28quote._~23~25kernel%29._begin%29%29) forms into the top level (see [expand-to-top-form](Expanding_Top-Level_Forms.html#%28def._%28%28quote._~23~25kernel%29._expand-to-top-form%29%29)), and then individually compiles and evaluates each spliced form before continuing to expand, compile, and evaluate later forms.

> ```
(eval top-level-form)  →  any
  top-level-form : any/c
(eval top-level-form namespace)  →  any
  top-level-form : any/c
  namespace : namespace?
```


# 13.11 Cryptographic Hashing
(parameter)	→
(-> eval-syntax stx)```
Like [eval](#%28def._%28%28quote._~23~25kernel%29._eval%29%29), except that stx must be a syntax object, and its lexical context is not enriched before it is passed to the [evaluation handler](#%28tech._evaluation._handler%29).
> ```
(current-load)	→
(-> path? (or/c #f
    symbol?
    (cons/c (or/c #f symbol?)
    (non-empty-listof symbol?)))
    . → .
    any)
(current-load proc) → void?
    proc	:
(-> path? (or/c #f
    symbol?
    (cons/c (or/c #f symbol?)
    (non-empty-listof symbol?)))
    . → .
    any)
```
(parameter)	→```

> > > <img src="finger.png" width="24" height="24" alt="+" />See also [Namespaces](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=eval.html%23%2528part._namespaces%2529&version=8.18.0.13) in [The Racket Guide](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=index.html&version=8.18.0.13).

Calls the current [load handler](#%28tech._load._handler%29) in tail position. The call is parameterized to set [current-load-relative-directory](#%28def._%28%28quote._~23~25kernel%29._current-load-relative-directory%29%29) to the directory of file, which is resolved relative to the value of [current-directory](Filesystem.html#%28def._%28%28quote._~23~25kernel%29._current-directory%29%29).

> ```
(load-relative file)  →  any
  file : path-string?
```
(parameter)	→```


# 13.11 Cryptographic Hashing
Like [load](#%28def._%28%28quote._~23~25kernel%29._load%29%29), but [load/cd](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._load%2Fcd%29%29) sets both [current-directory](Filesystem.html#%28def._%28%28quote._~23~25kernel%29._current-directory%29%29) and [current-load-relative-directory](#%28def._%28%28quote._~23~25kernel%29._current-load-relative-directory%29%29) before calling the [load handler](#%28tech._load._handler%29).
> ```
(current-load-extension)	→
(-> path? (or/c #f
    symbol?
    (cons/c (or/c #f symbol?)
    (non-empty-listof symbol?)))
    . → .
    any)
(current-load-extension proc) → void?
    proc	:
(-> path? (or/c #f
    symbol?
    (cons/c (or/c #f symbol?)
    (non-empty-listof symbol?)))
    . → .
    any)
```
(Unix)	→```

Sets [current-load-relative-directory](#%28def._%28%28quote._~23~25kernel%29._current-load-relative-directory%29%29) like [load](#%28def._%28%28quote._~23~25kernel%29._load%29%29), and calls the [extension-load handler](#%28tech._extension._load._handler%29) in tail position.

Extensions are supported only when ([system-type](runtime.html#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) 'vm) returns 'racket.

> ```
(load-relative-extension file)  →  any
  file : path-string?
```
(parameter)	→
(-> path? (or/c #f
    symbol?
    (cons/c (or/c #f symbol?)
    (non-empty-listof symbol?)))
    . → . any)```


# 13.11 Cryptographic Hashing
A [parameter](eval-model.html#%28tech._parameter%29) that determines the current compiled-load handler to load from a file that may have a compiled form. The [compiled-load handler](#%28tech._compiled._load._handler%29) is called by [load/use-compiled](#%28def._%28%28quote._~23~25kernel%29._load%2Fuse-compiled%29%29).
The protocol for a [compiled-load handler](#%28tech._compiled._load._handler%29) is the same as for the [load handler](#%28tech._load._handler%29) (see [current-load](#%28def._%28%28quote._~23~25kernel%29._current-load%29%29)), except that a [compiled-load handler](#%28tech._compiled._load._handler%29) is expected to set [current-load-relative-directory](#%28def._%28%28quote._~23~25kernel%29._current-load-relative-directory%29%29) itself. Additionally, the default [compiled-load handler](#%28tech._compiled._load._handler%29) does the following:
-   When the given path ends with ".rkt", no ".rkt" file exists, and when the handler’s second argument is not #f, the default [compiled-load handler](#%28tech._compiled._load._handler%29) checks for a ".ss" file.
-   The default [compiled-load handler](#%28tech._compiled._load._handler%29) checks for the opportunity to load from ".zo" (bytecode) files and, when ([system-type](runtime.html#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) 'vm) returns 'racket, for ".so" (native Unix), ".dll" (native Windows), or ".dylib" (native Mac OS) files.


# 13.11 Cryptographic Hashing
-   When the default [compiled-load handler](#%28tech._compiled._load._handler%29) needs to load from the given path, the given path does not exist, and when the handler’s second argument is not #f, the default [compiled-load handler](#%28tech._compiled._load._handler%29) returns without raising an exception.
The check for a compiled file occurs whenever the given path file ends with any extension (e.g., ".rkt" or ".scrbl"), and the check consults the subdirectories indicated by the [current-compiled-file-roots](#%28def._%28%28quote._~23~25kernel%29._current-compiled-file-roots%29%29) and [use-compiled-file-paths](#%28def._%28%28quote._~23~25kernel%29._use-compiled-file-paths%29%29) parameters relative to file, where the former supplies “roots” for compiled files and the latter provides subdirectories. See also [compiler/compilation-path](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=raco&rel=api_compile-path.html&version=8.18.0.13). A “root” can be an absolute path, in which case file’s directory is combined with [reroot-path](Manipulating_Paths.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._reroot-path%29%29) and the root as the second argument; if the “root” is a relative path, then the relative path is instead suffixed onto the directory of file. The roots are tried in order, and the subdirectories are checked in order within each root. A ".zo" version of the file (whose name is formed by passing file and #".zo" to [path-add-extension](Manipulating_Paths.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._path-add-extension%29%29)) is loaded if it exists directly in one of the indicated subdirectories, or when ([system-type](runtime.html#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) 'vm) returns 'racket, then a ".so"/".dll"/".dylib" version of the file is loaded if it exists within a "native" subdirectory of a [use-compiled-file-paths](#%28def._%28%28quote._~23~25kernel%29._use-compiled-file-paths%29%29) directory, in an even deeper subdirectory as named by [system-library-subpath](runtime.html#%28def._%28%28quote._~23~25kernel%29._system-library-subpath%29%29). A compiled file is loaded only if it checks out according to ([use-compiled-file-check](#%28def._%28%28quote._~23~25kernel%29._use-compiled-file-check%29%29)); with the default parameter value of 'modify-seconds, a compiled file is used only if its modification date is not older than the date for file. If both ".zo" and ".so"/".dll"/".dylib" files are available when ([system-type](runtime.html#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) 'vm) returns 'racket, the ".so"/".dll"/".dylib" file is used. If file ends with ".rkt", no such file exists, the handler’s second argument is a symbol, and a ".ss" file exists, then ".zo" and ".so"/".dll"/".dylib" files are used only with names based on file with its suffixed replaced by ".ss".


# 13.11 Cryptographic Hashing
While a ".zo", ".so", ".dll", or ".dylib" file is loaded, the current [load-relative](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._load-relative%29%29) directory is set to the directory of the original file. If the file to be loaded has the suffix ".ss" while the requested file has the suffix ".rkt", then the [current-module-declare-source](Module_Names_and_Loading.html#%28def._%28%28quote._~23~25kernel%29._current-module-declare-source%29%29) parameter is set to the full path of the loaded file, otherwise the [current-module-declare-source](Module_Names_and_Loading.html#%28def._%28%28quote._~23~25kernel%29._current-module-declare-source%29%29) parameter is set to #f.
If the original file is loaded or a ".zo" variant is loaded, the [load handler](#%28tech._load._handler%29) is called to load the file. If any other kind of file is loaded, the [extension-load handler](#%28tech._extension._load._handler%29) is called.


# 13.11 Cryptographic Hashing
When the default [compiled-load handler](#%28tech._compiled._load._handler%29) loads a module from a bytecode (i.e., ".zo") file, the handler records the bytecode file path in the current namespace’s [module registry](syntax-model.html#%28tech._module._registry%29). More specifically, the handler records the path for the top-level module of the loaded module, which is an enclosing module if the loaded module is a submodule. Thereafter, loads via the default [compiled-load handler](#%28tech._compiled._load._handler%29) for modules within the same top-level module use the recorded file, independent of the file that otherwise would be selected by the [compiled-load handler](#%28tech._compiled._load._handler%29) (e.g., even if the [use-compiled-file-paths](#%28def._%28%28quote._~23~25kernel%29._use-compiled-file-paths%29%29) parameter value changes). The default [module name resolver](Module_Names_and_Loading.html#%28tech._module._name._resolver%29) transfers bytecode-file information when a module declaration is attached to a new namespace. This protocol supports independent but consistent loading of submodules from bytecode files.
> ```
(load/use-compiled file)  →  any
  file : path-string?


# 13.11 Cryptographic Hashing
```
(current-load-relative-directory)	→
(-> or/c (and/c path-string? complete-path?) #f)
(current-load-relative-directory path) → void?
    path	:
(-> or/c (and/c path-string? complete-path?) #f)```

A [parameter](eval-model.html#%28tech._parameter%29) that is set by [load](#%28def._%28%28quote._~23~25kernel%29._load%29%29), [load-relative](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._load-relative%29%29), [load-extension](#%28def._%28%28quote._~23~25kernel%29._load-extension%29%29), [load-relative-extension](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._load-relative-extension%29%29), and the default [compiled-load handler](#%28tech._compiled._load._handler%29), and used by [load-relative](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._load-relative%29%29), [load-relative-extension](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._load-relative-extension%29%29), and the default [compiled-load handler](#%28tech._compiled._load._handler%29).

When a new path or string is provided as the parameter’s value, it is immediately expanded (see [Paths](pathutils.html)) and converted to a path. (The directory need not exist.)

> ```
(use-compiled-file-paths)	→
(-> listof (and/c path? relative-path?))
(use-compiled-file-paths paths) → void?
    paths	:
(-> listof (and/c path? relative-path?))
```
(current-compiled-file-roots)	→
(-> see current-load/use-compiled)
(current-compiled-file-roots paths) → void?
    paths	:
(-> see current-load/use-compiled)```


# 13.11 Cryptographic Hashing
A list of paths and 'sames that is used by the default [compiled-load handler](#%28tech._compiled._load._handler%29) (see [current-load/use-compiled](#%28def._%28%28quote._~23~25kernel%29._current-load%2Fuse-compiled%29%29)).
The parameter is normally initialized to ([list](pairs.html#%28def._%28%28quote._~23~25kernel%29._list%29%29) 'same), but the parameter’s initial value can be adjusted by the installation configuration as reported by ([find-compiled-file-roots](#%28def._%28%28quote._~23~25kernel%29._find-compiled-file-roots%29%29)), and it can be further adjusted by the PLTCOMPILEDROOTS environment variable or the --compiled or -R command-line flag for racket. If the environment variable is defined and not overridden by a command-line flag, it is parsed by first replacing any @(version) with the result of ([version](runtime.html#%28def._%28%28quote._~23~25kernel%29._version%29%29)), then using [path-list-string->path-list](Filesystem.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._path-list-string-~3epath-list%29%29) with a path list produced by ([find-compiled-file-roots](#%28def._%28%28quote._~23~25kernel%29._find-compiled-file-roots%29%29)) to arrive at the parameter’s initial value.
> ```
(find-compiled-file-roots)  →  (listof (or/c path? 'same))


# 13.11 Cryptographic Hashing
```
(find-config-dir)	→
(-> or/c 'modify-seconds 'exists)```

A [parameter](eval-model.html#%28tech._parameter%29) that determines how a compiled file is checked against its source to enable use of the compiled file. By default, the file-check mode is 'modify-seconds, which uses a compiled file when its filesystem modification date is at least as new as the source file’s. The 'exists mode causes a compiled file to be used in place of its source as long as the compiled file exists.

If the PLT_COMPILED_FILE_CHECK environment variable is set to modify-seconds or exists, then the environment variable’s value configures the parameter when Racket starts.

Added in version 6.6.0.3 of package base.

> ```
(read-eval-print-loop)  →  any
```
(current-prompt-read)	→
(-> any)
(current-prompt-read proc) → void?
    proc	:
(-> any)```


# 13.11 Cryptographic Hashing
A [parameter](eval-model.html#%28tech._parameter%29) that determines a prompt read handler, which is a procedure that takes no arguments, displays a prompt string, and returns a top-level form to evaluate. The prompt read handler is called by [read-eval-print-loop](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._read-eval-print-loop%29%29), and after printing a prompt, the handler typically should call the [read interaction handler](#%28tech._read._interaction._handler%29) (as determined by the [current-read-interaction](#%28def._%28%28quote._~23~25kernel%29._current-read-interaction%29%29) parameter) with the port produced by the [interaction port handler](#%28tech._interaction._port._handler%29) (as determined by the [current-get-interaction-input-port](#%28def._%28%28quote._~23~25kernel%29._current-get-interaction-input-port%29%29) parameter).
The default prompt read handler prints \>  and returns the result of
> ```racket
> ( let ( [ in ( ( current-get-interaction-input-port ) ) ] )
> ( ( current-read-interaction ) ( object-name in ) in ) )
> ```


# 13.11 Cryptographic Hashing
If the input and output ports are both terminals (in the sense of [terminal-port?](port-ops.html#%28def._%28%28quote._~23~25kernel%29._terminal-port~3f%29%29)) and if the output port appears to be counting lines (because [port-next-location](linecol.html#%28def._%28%28quote._~23~25kernel%29._port-next-location%29%29) returns a non-#f line and column), then the output port’s line is incremented and its column is reset to 0 via [set-port-next-location!](linecol.html#%28def._%28%28quote._~23~25kernel%29._set-port-next-location%21%29%29) before returning the read result.
> ```
(current-get-interaction-input-port)	→
(-> input-port?)
(current-get-interaction-input-port proc) → void?
    proc	:
(-> input-port?)


# 13.11 Cryptographic Hashing
```
(current-get-interaction-evt)	→
(-> evt?)
(current-get-interaction-evt proc) → void?
    proc	:
(-> evt?)```

A [parameter](eval-model.html#%28tech._parameter%29) that determines the interaction event handler, which returns an [synchronizable event](sync.html#%28tech._synchronizable._event%29) that should be used in combination with blocking that is similar to [read-eval-print-loop](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._read-eval-print-loop%29%29) waiting for input—but where an input port is not read directly, so [current-get-interaction-input-port](#%28def._%28%28quote._~23~25kernel%29._current-get-interaction-input-port%29%29) does not apply.

When the interaction event handler returns an event that becomes ready, and when the event’s ready value is a procedure, then the procedure is meant to be called with zero arguments blocking resumes. The default interaction event handler returns [never-evt](sync.html#%28def._%28%28quote._~23~25kernel%29._never-evt%29%29).

The [racket/gui/base](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=gui&rel=index.html&version=8.18.0.13) library adjusts this parameter’s value by extending the current value. The extension combines the current value’s result with [choice-evt](sync.html#%28def._%28%28quote._~23~25kernel%29._choice-evt%29%29) and an event that becomes ready when a GUI event is available, and the event’s value is a procedure that yields to one or more available GUI events.

Added in version 8.3.0.3 of package base.

> ```
(current-read-interaction)	→
(-> any/c input-port? . → . any)
(current-read-interaction proc) → void?
    proc	:
(-> any/c input-port? . → . any)
```


# 13.11 Cryptographic Hashing
(current-print)	→
(-> any/c . → . any)
(current-print proc) → void?
    proc	:
(-> any/c . → . any)```
A [parameter](eval-model.html#%28tech._parameter%29) that determines the print handler that is called by [read-eval-print-loop](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._read-eval-print-loop%29%29) to print the result of an evaluation (and the result is ignored).
The default [print handler](#%28tech._print._handler%29) [print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29)s the value to the current output port (as determined by the [current-output-port](port-ops.html#%28def._%28%28quote._~23~25kernel%29._current-output-port%29%29) parameter) and then outputs a newline, except that it prints nothing when the value is [#<void>](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=void_undefined.html&version=8.18.0.13).
> ```
(current-compile)	→
(-> any/c boolean? . → . compiled-expression?)
(current-compile proc) → void?
    proc	:
(-> any/c boolean? . → . compiled-expression?)
```
(parameter)	→```

Like [eval](#%28def._%28%28quote._~23~25kernel%29._eval%29%29), but calls the current [compilation handler](#%28tech._compilation._handler%29) in tail position with top-level-form.

> ```
(compile-syntax stx)  →  compiled-expression?
  stx : syntax?
```
Like eval-syntax, but calls the current compilation handler in tail position with stx.
> ```
(compiled-expression-recompile ce)   →   compiled-expression?
  ce : compiled-expression?```


# 13.11 Cryptographic Hashing
Recompiles ce. If ce was compiled as machine-independent and [current-compile-target-machine](#%28def._%28%28quote._~23~25kernel%29._current-compile-target-machine%29%29) is not set to #f, then recompiling effectively converts to the current machine format. Otherwise, recompiling effectively re-runs optimization passes to produce an equivalent compiled form with potentially different performance characteristics.
Added in version 6.3 of package base.
> ```
(compiled-expression-add-target-machine   ce
    other-ce)
  →  compiled-expression?
  ce : compiled-expression?
  other-ce : (or/c compiled-expression? hash?)
```
(parameter)	→```

Returns a value that has the same information as other-ce for [compiled-expression-add-target-machine](#%28def._%28%28quote._~23~25kernel%29._compiled-expression-add-target-machine%29%29), but in a form that can be portably serialized via [racket/fasl](fasl.html).

Added in version 8.17.0.3 of package base.

> ```
(compiled-expression? v)  →  boolean?
  v : any/c
```
Returns #t if v is a compiled form, #f otherwise.
> ```
(compile-enforce-module-constants)	→
(-> compile-enforce-module-constants on?)


# 13.11 Cryptographic Hashing
```

A [parameter](eval-model.html#%28tech._parameter%29) that determines how a module declaration is compiled.

When constants are enforced, and when the macro-expanded body of a module contains no [set!](set_.html#%28form._%28%28quote._~23~25kernel%29._set%21%29%29) assignment to a particular variable defined within the module, then the variable is marked as constant when the definition is evaluated. Afterward, the variable’s value cannot be assigned or undefined through [module->namespace](Namespaces.html#%28def._%28%28quote._~23~25kernel%29._module-~3enamespace%29%29), and it cannot be defined by redeclaring the module.

Enforcing constants allows the compiler to inline some variable values, and it allows the native-code just-in-time compiler to generate code that skips certain run-time checks.

> ```
(parameter)	→
(-> compile-allow-set!-undefined allow?)
```
(compile-context-preservation-enabled)	→
(-> compile-context-preservation-enabled on?)```
A [parameter](eval-model.html#%28tech._parameter%29) that determines whether compilation should avoid function-call inlining and other optimizations that may cause information to be lost from stack traces (as reported by [continuation-mark-set->context](contmarks.html#%28def._%28%28quote._~23~25kernel%29._continuation-mark-set-~3econtext%29%29)). The default is #f, which allows such optimizations.
> ```


# 13.11 Cryptographic Hashing
(current-compile-target-machine)	→
(-> or/c #f (and/c symbol? compile-target-machine?))
(current-compile-target-machine target) → void?
    target	:
(-> or/c #f (and/c symbol? compile-target-machine?))
```
(parameter)	→```

Reports whether sym is a supported compilation target for the currently running Racket.

When ([system-type](runtime.html#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) 'vm) reports 'racket, then the only target symbol is 'racket. When ([system-type](runtime.html#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) 'vm) reports 'chez-scheme, then a symbol corresponding to the current platform is a target, and other targets may also be supported. The 'target-machine mode of [system-type](runtime.html#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) reports the running Racket’s native target machine.

Added in version 7.1.0.6 of package base.

> ```
(current-compile-realm)	→
(-> current-compile-realm realm)
(current-compile-realm realm) → void?
    realm	:
(-> current-compile-realm realm)
```
Determines the realm that is assigned to modules and procedures when they are compiled.
Added in version 8.4.0.2 of package base.
> ```
(eval-jit-enabled)	 →
(  →  eval-jit-enabled on?)```


# 13.11 Cryptographic Hashing
> > > <img src="finger.png" width="24" height="24" alt="+" />See also [Bytecode, Machine Code, and Just-in-Time (JIT) Compilers](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=performance.html%23%2528part._.J.I.T%2529&version=8.18.0.13) in [The Racket Guide](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=index.html&version=8.18.0.13).
A [parameter](eval-model.html#%28tech._parameter%29) that determines whether the native-code just-in-time compiler (JIT) is enabled for code (compiled or not) that is passed to the default evaluation handler. A true parameter value is effective only on platforms for which the JIT is supported and for Racket virtual machines that rely on a JIT.
The default is #t, unless the JIT is not supported by the current platform but is supported on the same virtual machine for other platforms, unless it is disabled through the -j/--no-jit command-line flag to stand-alone Racket (or GRacket), and unless it is disabled through the PLTNOMZJIT environment variable (set to any value).
> ```
(load-on-demand-enabled)	→
(-> load-on-demand-enabled on?)
```
(parameter)	→```

Returns #t if v is a [resolved module path](#%28tech._resolved._module._path%29), #f otherwise.

> ```
(parameter)	→
(-> or/c symbol?
    (and/c path? complete-path?)
    (cons/c (or/c symbol?
    (and/c path? complete-path?))
    (non-empty-listof symbol?)))
```