► |  | The Racket Reference

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

▼ | 13 | Input and Output

13.1 | Ports
13.2 | Byte and String Input
13.3 | Byte and String Output
13.4 | Reading
13.5 | Writing
13.6 | Pretty Printing
13.7 | Reader Extension
13.8 | Printer Extension
13.9 | Serialization
13.10 | Fast-Load Serialization
13.11 | Cryptographic Hashing

On this page:

s-exp->fasl
fasl->s-exp

top ← prev up next →

#### 13.10`` Fast-Load Serialization

(require racket/fasl) | package: base

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

> > procedure
> > (s-exp->fasl |  | v |
> > | [ | out |
> > |  | #:keep-mutable? keep-mutable?]) |
> → (or/c (void) bytes?)
> v : any/c
> out : (or/c output-port? #f) = #f
> keep-mutable? : any/c = #f
> > procedure
> > (fasl->s-exp |  | in |  |  |  |
> > | [ | #:datum-intern? datum-intern?]) |  | → |  | any/c
> in : (or/c input-port? bytes?)
> datum-intern? : any/c = #t

The s-exp->fasl 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 function decodes a value from a byte string (supplied either directly or as an input port) that was encoded with s-exp->fasl.

The v argument must be a value that could be quoted as a literal—that is, a value without syntax objects for which (compile `',v) would work and be readable after write. The byte string produced by s-exp->fasl does not use the same format as compiled code, however.

Like (compile `',v), s-exp->fasl does not preserve graph structure, support cycles, or handle non-prefab structures. Compose s-exp->fasl with serialize to preserve graph structure, handle cyclic data, and encode serializable structures. The s-exp->fasl and fasl->s-exp functions consult current-write-relative-directory and current-load-relative-directory, respectively, in the same way as bytecode saving and loading to store paths in relative form, and they similarly allow and convert constrained srcloc values (see Printing Compiled Code).

Unless keep-mutable? is provided as true to s-exp->fasl, then mutable values in v are replaced by immutable values when the result is decoded by fasl->s-exp. Unless datum-intern? is provided as #f, then any immutable value produced by fasl->s-exp is filtered by datum-intern-literal. The defaults make the composition of s-exp->fasl and fasl->s-exp behave like the composition of write and read.

The byte-string encoding produced by s-exp->fasl 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 will be valid as input to any future version of fasl->s-exp.

Examples:

> > (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 format version-independent and added the #:keep-mutable? and #:datum-intern? arguments.

top ← prev up next →