text
stringlengths
12
127k
# 15.5 Logging - If the PLTSTDOUT environment variable is defined and is not overridden by a command-line flag, it determines the level of the [log receiver](#%28tech._log._receiver%29) that propagates events to the original output port. The possible values are the same as for PLTSTDERR. The default is "none". - If the PLTSYSLOG environment variable is defined and is not overridden by a command-line flag, it determines the level of the [log receiver](#%28tech._log._receiver%29) that propagates events to the system log. The possible values are the same as for PLTSTDERR. The default is "none" for Unix or "error" for Windows and Mac OS. The [current-logger](#%28def._%28%28quote._~23~25kernel%29._current-logger%29%29) [parameter](eval-model.html#%28tech._parameter%29) determines the current logger that is used by forms such as [log-warning](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._log-warning%29%29). On start-up, the initial value of this parameter is the initial logger. The run-time system sometimes uses the current logger to report events. For example, the bytecode compiler sometimes reports 'warning events when it detects an expression that would produce a run-time error if evaluated. Changed in version 6.6.0.2 of package base: Prior to version 6.6.0.2, parsing of PLTSTDERR and PLTSYSLOG was very strict. Leading and trailing whitespace was forbidden, and anything other than exactly one space character separating two specifications was rejected. Changed in version 6.90.0.17: Added PLTSTDOUT.
#### 15.5.1 Creating Loggers > ``` (logger? v)  →  boolean?   v : any/c ``` (parameter) → (-> or/c symbol? #f)``` Creates a new [logger](#%28tech._logger%29) with an optional topic and parent. The optional propagate-level and propagate-topic arguments constrain the events that are propagated from the new logger to parent (when parent is not #f) in the same way that events are described for a log receiver in [make-log-receiver](#%28def._%28%28quote._~23~25kernel%29._make-log-receiver%29%29). By default, all events are propagated to parent. Changed in version 6.1.1.3 of package base: Removed an optional argument to specify a notification callback, and added propagate-level and propagate-topic constraints for events to propagate. > ``` (parameter) → (-> or/c symbol? #f) ``` (current-logger) → (-> current-logger logger) (current-logger logger) → void? logger : (-> current-logger logger)``` A [parameter](eval-model.html#%28tech._parameter%29) that determines the [current logger](#%28tech._current._logger%29). > <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote> <p>syntax</p>
# 15.5 Logging <p>([define-logger](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._define-logger%29%29) id maybe-parent)</p></blockquote></td></tr><tr><td> </td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /><col style="width: 20%" /></colgroup><tbody><tr><td style="text-align: right;" data-valign="baseline">maybe-parent</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">=</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"><pre><code></code></pre></td></tr><tr><td style="text-align: right;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: center;" data-valign="baseline">|</td><td style="text-align: left;" data-valign="baseline"> </td><td style="text-align: left;" data-valign="baseline">#:parent parent-expr</td></tr></tbody></table></td></tr><tr><td> </td></tr><tr><td><table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td>  </td><td>parent-expr</td><td> </td><td>:</td><td> </td><td>([or/c](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._or%2Fc%29%29) [logger?](#%28def._%28%28quote._~23~25kernel%29._logger~3f%29%29) #f)</td></tr></tbody></table></td></tr></tbody></table>
# 15.5 Logging Defines log-id-fatal, log-id-error, log-id-warning, log-id-info, and log-id-debug as forms like [log-fatal](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._log-fatal%29%29), [log-error](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._log-error%29%29),[log-warning](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._log-warning%29%29), [log-info](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._log-info%29%29), and [log-debug](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._log-debug%29%29). The [define-logger](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._define-logger%29%29) form also defines id-logger, which is a logger with default topic 'id that is a child of the result of parent-expr (if parent-expr does not produce #f), or of ([current-logger](#%28def._%28%28quote._~23~25kernel%29._current-logger%29%29)) if parent-expr not provided; the log-id-fatal, etc. forms use this new logger. The new logger is created when [define-logger](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._define-logger%29%29) is evaluated. Changed in version 7.1.0.9 of package base: Added the #:parent option.
#### 15.5.2 Logging Events > ``` (parameter) → (-> or/c symbol? #f) ``` (parameter) → (-> or/c symbol? #f)``` Reports whether any [log receiver](#%28tech._log._receiver%29) attached to logger or one of its ancestors is interested in level events (or potentially lower) for topic. If topic is #f, the result indicates whether a [log receiver](#%28tech._log._receiver%29) is interested in events at level for any topic. If level is 'none, the result is always #f. Use this function to avoid work generating an event for [log-message](#%28def._%28%28quote._~23~25kernel%29._log-message%29%29) if no receiver is interested in the information; this shortcut is built into [log-fatal](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._log-fatal%29%29), [log-error](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._log-error%29%29), [log-warning](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._log-warning%29%29), [log-info](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._log-info%29%29), [log-debug](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._log-debug%29%29), and forms bound by [define-logger](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._define-logger%29%29), however, so it should not be used with those forms. The result of this function can change if a garbage collection determines that a log receiver is no longer accessible (and therefore that any event information it receives will never become accessible). Changed in version 6.1.1.3 of package base: Added the topic argument. Changed in version 8.10.0.5: Changed the result for 'none to be consistently #f. > ``` (parameter) → (-> or/c log-level/c #f) ```
# 15.5 Logging (parameter) → (-> list/c (or/c #f log-level/c) (or/c #f symbol?) ... ...)``` Summarizes the possible results of [log-max-level](#%28def._%28%28quote._~23~25kernel%29._log-max-level%29%29) on all possible [interned](reader.html#%28tech._interned%29) symbols. The result list contains a sequence of symbols and #f, where the first, third, etc., list element corresponds to a level, and the second, fourth, etc., list element indicates a corresponding topic. The level is the result that [log-max-level](#%28def._%28%28quote._~23~25kernel%29._log-max-level%29%29) would produce for the topic, where the level for the #f topic (which is always present in the result list) indicates the result for any [interned](reader.html#%28tech._interned%29)-symbol topic that does not appear in the list. The result is suitable as a sequence of arguments to [make-log-receiver](#%28def._%28%28quote._~23~25kernel%29._make-log-receiver%29%29) (after a [logger](#%28tech._logger%29) argument) to create a new receiver for events that currently have receivers in logger. Added in version 6.1.1.4 of package base. > ``` (log-level-evt logger)  →  evt?   logger : logger? ``` (parameter) →``` Returns #t if v is a [log receiver](#%28tech._log._receiver%29), #f otherwise. > ``` (parameter) → (-> or/c #f symbol?) ``` Creates a log receiver to receive events of detail level and lower as reported to logger and its descendants, as long as either topic is #f or the event’s topic matches topic.
# 15.5 Logging A log receiver is a synchronizable event. It becomes ready for synchronization when a logging event is received, so use sync to receive a logged event. The log receiver’s synchronization result is an immutable vector containing four values: the level of the event as a symbol, an immutable string for the event message, an arbitrary value that was supplied as the last argument to log-message when the event was logged, and a symbol or #f for the event topic. Multiple pairs of level and topic can be provided to indicate different specific levels for different topics (where topic defaults to #f only for the last given level). A level for a #f topic applies only to events whose topic does not match any other provided topic. If the same topic is provided multiple times, the level provided with the last instance in the argument list takes precedence.
#### 15.5.4 Additional Logging Functions | | | |:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:| |  (require racket/logging) |  package: base | The bindings documented in this section are provided by the racket/logging library, not racket/base or racket. > ``` (log-level/c v) → boolean?   v : any/c``` Returns #t if v is a valid logging level ('none, 'fatal, 'error, 'warning, 'info, or 'debug), #f otherwise. Added in version 6.3 of package base. > ``` (parameter) → (-> (vector/c log-level/c string? any/c (or/c symbol? #f)) any)
# 15.5 Logging ``` (parameter) → (-> any)``` Runs proc, outputting any logging that the execution of proc emits to [current-logger](#%28def._%28%28quote._~23~25kernel%29._current-logger%29%29) at the specified levels and topics. If #:logger is specified, intercepts events sent to that logger, otherwise uses a new child logger of the current logger. Returns whatever proc returns. Example: > ```racket > > ( let ( [ my-log ( open-output-string ) ] ) ( with-logging-to-port my-log ( lambda ( ) ( log-warning "Warning World!" ) ( + 2 2 ) ) ' warning ) ( get-output-string my-log ) ) > "Warning World!\n" > ``` Added in version 6.3 of package base. Changed in version 6.7.0.1: Added #:logger argument. ------------------------------------------------------------------------ # 15.6 Time ### 15.6 Time > ``` (current-seconds) → ``` (current-inexact-milliseconds) →``` Returns the current time in milliseconds since [the epoch](#%28tech._the._epoch%29). The result may contain fractions of a millisecond. Example: > ```racket > > ( current-inexact-milliseconds ) > 1289513737015.418 > ``` In this example, 1289513737015 is in milliseconds and 418 is in microseconds. > ``` (current-inexact-monotonic-milliseconds) →
# 15.5 Logging ``` (parameter) →``` Takes secs-n, a time in seconds since [the epoch](#%28tech._the._epoch%29) (like the value of ([current-seconds](#%28def._%28%28quote._~23~25kernel%29._current-seconds%29%29)), ([file-or-directory-modify-seconds](Filesystem.html#%28def._%28%28quote._~23~25kernel%29._file-or-directory-modify-seconds%29%29) path), or ([/](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._%2F%29%29) ([current-inexact-milliseconds](#%28def._%28%28quote._~23~25kernel%29._current-inexact-milliseconds%29%29)) 1000)), and returns an instance of the [date*](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%2A%29%29) structure type. Note that secs-n can include fractions of a second. If secs-n is too small or large, the [exn:fail](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail%29%29) exception is raised. The resulting [date*](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%2A%29%29) reflects the time according to the local time zone if local-time? is #t, otherwise it reflects a date in UTC. > <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote> <p>struct</p> <table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td>([struct](define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29)</td><td> </td><td>[date](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%29%29)</td><td> (</td><td>second</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td>minute</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td>hour</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td>day</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td>month</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td>year</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td>week-day</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td>year-day</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td>dst?</td></tr><tr><td> </td><td> </td><td> </td><td> </td><td>time-zone-offset)</td></tr></tbody></table></blockquote></td></tr><tr><td>    #:extra-constructor-name [make-date](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._make-date%29%29)</td></tr><tr><td>    #:transparent)</td></tr><tr><td>  second : ([integer-in](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._integer-in%29%29) 0 60)</td></tr><tr><td>  minute : ([integer-in](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._integer-in%29%29) 0 59)</td></tr><tr><td>  hour : ([integer-in](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._integer-in%29%29) 0 23)</td></tr><tr><td>  day : ([integer-in](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._integer-in%29%29) 1 31)</td></tr><tr><td>  month : ([integer-in](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._integer-in%29%29) 1 12)</td></tr><tr><td>  year : [exact-integer?](number-types.html#%28def._%28%28quote._~23~25kernel%29._exact-integer~3f%29%29)</td></tr><tr><td>  week-day : ([integer-in](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._integer-in%29%29) 0 6)</td></tr><tr><td>  year-day : ([integer-in](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._integer-in%29%29) 0 365)</td></tr><tr><td>  dst? : [boolean?](booleans.html#%28def._%28%28quote._~23~25kernel%29._boolean~3f%29%29)</td></tr><tr><td>  time-zone-offset : [exact-integer?](number-types.html#%28def._%28%28quote._~23~25kernel%29._exact-integer~3f%29%29)</td></tr></tbody></table> Represents a date. The second field reaches 60 only for leap seconds. The week-day field is 0 for Sunday, 1 for Monday, etc. The year-day field is 0 for January 1, 1 for January 2, etc.; the year-day field reaches 365 only in leap years. The dst? field is #t if the date reflects a daylight-saving adjustment. The time-zone-offset field reports the number of seconds east of UTC (GMT) for the current time zone (e.g., Pacific Standard Time is -28800), including any daylight-saving adjustment (e.g., Pacific Daylight Time is -25200). When a [date](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%29%29) record is generated by [seconds->date](#%28def._%28%28quote._~23~25kernel%29._seconds-~3edate%29%29) with #f as the second argument, then the dst? and time-zone-offset fields are #f and 0, respectively. The [date](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%29%29) constructor accepts any value for dst? and converts any non-#f value to #t. The value produced for the time-zone-offset field tends to be sensitive to the value of the TZ environment variable, especially on Unix platforms; consult the system documentation (usually under tzset) for details. See also the [racket/date](#%28mod-path._racket%2Fdate%29) library. > <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote> <p>struct</p> <table data-cellpadding="0" data-cellspacing="0"><tbody><tr><td>([struct](define-struct.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._struct%29%29)</td><td> </td><td>[date*](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%2A%29%29) [date](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%29%29) (nanosecond time-zone-name)</td></tr></tbody></table></blockquote></td></tr><tr><td>    #:extra-constructor-name [make-date*](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._make-date%2A%29%29))</td></tr><tr><td>  nanosecond : ([integer-in](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._integer-in%29%29) 0 999999999)</td></tr><tr><td>  time-zone-name : ([and/c](data-structure-contracts.html#%28def._%28%28lib._racket%2Fcontract%2Fbase..rkt%29._and%2Fc%29%29) [string?](strings.html#%28def._%28%28quote._~23~25kernel%29._string~3f%29%29) [immutable?](booleans.html#%28def._%28%28quote._~23~25kernel%29._immutable~3f%29%29))</td></tr></tbody></table> Extends [date](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%29%29) with nanoseconds and a time zone name, such as "MDT", "Mountain Daylight Time", or "UTC". When a [date*](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%2A%29%29) record is generated by [seconds->date](#%28def._%28%28quote._~23~25kernel%29._seconds-~3edate%29%29) with #f as the second argument, then the time-zone-name field is "UTC". The [date*](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%2A%29%29) constructor accepts a mutable string for time-zone-name and converts it to an immutable one. > ``` (current-milliseconds) → ```
# 15.5 Logging (parameter) → (-> or/c #f thread? 'subprocesses)``` Returns an amount of processor time in [fixnum](numbers.html#%28tech._fixnum%29) milliseconds that has been consumed by on the underlying operating system, including both user and system time. - If scope is #f, the reported time is for all Racket threads and [places](places.html#%28tech._place%29). - If scope is a thread, the result is specific to the time while the thread ran, but it may include time for other [places](places.html#%28tech._place%29). The more a thread synchronizes with other threads, the less precisely per-thread processor time is recorded. - If scope is 'subprocesses, the result is the sum of process times for known-completed subprocesses (see [Processes](subprocess.html))—and known-completed children of the subprocesses, etc., on Unix and Mac OS—across all [places](places.html#%28tech._place%29). The precision of the result is platform-specific, and since the result is a [fixnum](numbers.html#%28tech._fixnum%29), the value increases only over a limited (though reasonably long) time on a 32-bit platform. Changed in version 6.1.1.4 of package base: Added 'subprocesses mode. > ``` (current-gc-milliseconds) →
# 15.5 Logging ``` (current-process-milliseconds) →``` Collects timing information for a procedure application. Four values are returned: a list containing the result(s) of applying proc to the arguments in lst, the number of milliseconds of CPU time required to obtain this result, the number of “real” milliseconds required for the result, and the number of milliseconds of CPU time (included in the first result) spent on garbage collection. The reliability of the timing numbers depends on the platform. If multiple Racket threads are running, then the reported time may include work performed by other threads. > <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote> <p>syntax</p> <p>([time](#%28form._%28%28lib._racket%2Fprivate%2Fmore-scheme..rkt%29._time%29%29) body ...+)</p></blockquote></td></tr></tbody></table> Reports [time-apply](#%28def._%28%28quote._~23~25kernel%29._time-apply%29%29)-style timing information for the evaluation of expr directly to the current output port. The result is the result of the last body. #### 15.6.1 Date Utilities > > > For more date & time operations, see [the Gregor: Date and Time documentation](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?tag=%28part._%28.%27%28lib._gregor%2Fscribblings%2Fgregor..scrbl%29.%27._.%27top.%27%29%29&version=8.18.0.13) or [srfi/19](../srfi/srfi-19.html) | | | |:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:| |  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/date](#%28mod-path._racket%2Fdate%29)) |  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/date](#%28mod-path._racket%2Fdate%29) library, not [racket/base](index.html) or [racket](index.html). > ``` (current-date) → ```
# 15.5 Logging (current-inexact-milliseconds) → (-> * 0.001 (current-inexact-milliseconds))``` Converts a date to a string. The returned string contains the time of day only if time?. See also [date-display-format](#%28def._%28%28lib._racket%2Fdate..rkt%29._date-display-format%29%29). > ``` (date-display-format) → (-> or/c ' american ' chinese ' german ' indian ' irish ' iso-8601 ' rfc2822 ' julian) (date-display-format format) → void? format : (-> or/c ' american ' chinese ' german ' indian ' irish ' iso-8601 ' rfc2822 ' julian) ``` Parameter that determines the date string format. The initial format is 'american. > ``` (date → seconds date [local-time?) → exact-integer?   date : date?   local-time? : any/c = #t``` Finds the representation of a date in platform-specific seconds. If the platform cannot represent the specified date, [exn:fail](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail%29%29) exception is raised. The week-day, year-day fields of date are ignored. The dst? and time-zone-offset fields of date are also ignored; the date is assumed to be in local time by default or in UTC if local-time? is #f. > ``` (date* → seconds date [local-time?) → real?   date : date?   local-time? : any/c = #t ``` Like date → seconds, but returns an exact number that can include a fraction of a second based on (date*-nanosecond date) if date is a date* instance. > ```
# 15.5 Logging (find-seconds second     minute             hour             day             month             year            [ local-time?)   →   exact-integer?   second : (integer-in 0 61)   minute : (integer-in 0 59)   hour : (integer-in 0 23)   day : (integer-in 1 31)   month : (integer-in 1 12)   year : exact-nonnegative-integer?   local-time? : any/c = #t``` Finds the representation of a date in platform-specific seconds. The arguments correspond to the fields of the [date](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._date%29%29) structure—in local time by default or UTC if local-time? is #f. If the platform cannot represent the specified date, an error is signaled, otherwise an integer is returned. > ``` (date → julian/scaliger date)  →  exact-integer?   date : date? ``` Converts a date structure (up to 2099 BCE Gregorian) into a Julian date number. The returned value is not a strict Julian number, but rather Scaliger’s version, which is off by one for easier calculations. > ``` (julian/scaliger → string date-number)  →  string?   date-number : exact-integer? ``` Converts a Julian number (Scaliger’s off-by-one version) into a string. > ``` (date → julian/scalinger date)  →  exact-integer?   date : date? (julian/scalinger → string date-number)  →  string?   date-number : exact-integer?
# 15.5 Logging ``` (parameter) → (-> environment-variables? v)``` Returns #t if v is an [environment variable set](#%28tech._environment._variable._set%29), #f otherwise. > ``` (current-environment-variables) → (-> current-environment-variables env) (current-environment-variables env) → void? env : (-> current-environment-variables env) ``` A parameter that determines the environment variable set that is propagated to a subprocess and that is used as the default set for getenv and putenv. > ``` (bytes-environment-variable-name? v)  →  boolean?   v : any/c``` Returns #t if v is a byte string and if it is valid for an environment variable name. An environment variable name must contain no bytes with the value 0 or 61, where 61 is ([char->integer](characters.html#%28def._%28%28quote._~23~25kernel%29._char-~3einteger%29%29) #\\=). On Windows, an environment variable name also must have a non-zero length. > ``` (make-environment-variables name val ... ...)   →  environment-variables?   name : bytes-environment-variable-name?   val : bytes-no-nuls?
# 15.5 Logging ``` Creates a fresh environment variable set that is initialized with the given name to val mappings. > ``` (environment-variables-ref env name)   →  (or/c #f (and/c bytes-no-nuls? immutable?))   env : environment-variables?   name : bytes-environment-variable-name?``` Returns the mapping for name in env, returning #f if name has no mapping. Normally, name should be a byte-string encoding of a string using the default encoding of the current [locale](encodings.html#%28tech._locale%29). On Windows, name is coerced to a UTF-8 encoding and case-normalized. > ``` (environment-variables-set! env     name             maybe-bstr            [ fail)   →   any   env : environment-variables?   name : bytes-environment-variable-name?   maybe-bstr : (or/c bytes-no-nuls? #f)    fail   :   ( →  any)   =   ( lambda ( ) > ( raise ( make-exn:fail .... ) ) ) ``` Changes the mapping for name in env to maybe-bstr. If maybe-bstr is #f and env is the initial environment variable set of the Racket process, then the operating system environment-variable mapping for name is removed. Normally, name and maybe-bstr should be a byte-string encoding of a string using the default encoding of the current locale. On Windows, name is coerced to a UTF-8 encoding and case-normalized, and maybe-bstr is coerced to a UTF-8 encoding if env is the initial environment variable set of the Racket process.
# 15.5 Logging On success, the result of environment-variables-set! is #<void>. If env is the initial environment variable set of the Racket process, then attempting to adjust the operating system environment-variable mapping might fail for some reason, in which case fail is called in tail position with respect to the environment-variables-set!. The default fail raises an exception. > ``` (environment-variables-names env)   →  (listof (and/c bytes-environment-variable-name? immutable?))   env : environment-variables?``` Returns a list of byte strings that corresponds to names mapped by env. > ``` (environment-variables-copy env)  →  environment-variables?   env : environment-variables?
# 15.5 Logging ``` Returns an environment variable set that is initialized with the same mappings as env. > ``` (getenv name)  →  (or/c string-no-nuls? #f)   name : string-environment-variable-name? (putenv name value)  →  boolean?   name : string-environment-variable-name?   value : string-no-nuls?``` Convenience wrappers for [environment-variables-ref](#%28def._%28%28quote._~23~25kernel%29._environment-variables-ref%29%29) and [environment-variables-set!](#%28def._%28%28quote._~23~25kernel%29._environment-variables-set%21%29%29) that convert between strings and byte strings using the current [locale](encodings.html#%28tech._locale%29)’s default encoding (using #\\? as the replacement character for encoding errors) and always using the current [environment variable set](#%28tech._environment._variable._set%29) from [current-environment-variables](#%28def._%28%28quote._~23~25kernel%29._current-environment-variables%29%29). The [putenv](#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._putenv%29%29) function returns #t for success and #f for failure. > ``` (string-environment-variable-name? v)  →  boolean?   v : any/c ``` (parameter) → (-> or/c symbol? string? bytes? exact-positive-integer? vector? #f)```
# 15.5 Logging Returns information about the operating system, build mode, or machine for a running Racket. (Installation tools should use [cross-system-type](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=raco&rel=cross-system.html%23%2528def._%2528%2528lib._setup%252Fcross-system..rkt%2529._cross-system-type%2529%2529&version=8.18.0.13), instead, to support cross-installation.) In 'os mode, the possible symbol results are: - 'unix - 'windows - 'macosx > > > Prior to the introduction of 'os\* and 'arch modes, ([system-library-subpath](#%28def._%28%28quote._~23~25kernel%29._system-library-subpath%29%29) #f) could be used to obtain this information somewhat indirectly. In 'os\* mode, the result is similar to 'os mode, but refined to a specific operating system, such as 'linux or 'freebsd, instead of a generic 'unix classification. In 'arch mode, the result is a symbol representing an architecture. Possible results include 'x86_64, 'i386, 'aarch64, 'arm (32-bit), and 'ppc (32-bit). In 'word mode, the result is either 32 or 64 to indicate whether Racket is running as a 32-bit program or 64-bit program. > > > See [Racket Virtual Machine Implementations](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=guide&rel=performance.html%23%2528part._virtual-machines%2529&version=8.18.0.13) for more information about the 'vm and 'gc mode results. In 'vm mode, the possible symbol results are (see also [Implementations](implementations.html)): - 'racket - 'chez-scheme
# 15.5 Logging In 'gc mode, the possible symbol results are (see also [Implementations](implementations.html)): - 'cgc — when ([system-type](#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) 'vm) is 'racket - '3m — when ([system-type](#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) 'vm) is 'racket - 'cs — when ([system-type](#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) 'vm) is 'chez-scheme In 'link mode, the possible symbol results are: - 'static (Unix) - 'shared (Unix) - 'dll (Windows) - 'framework (Mac OS) Future ports of Racket may expand the list of 'os, 'os\*, 'arch, 'vm, 'gc, and 'link results. In 'machine mode, then the result is a string, which contains further details about the current machine in a platform-specific format. In 'target-machine mode, the result is a symbol for the running Racket’s native bytecode format, or it is #f if there is no native format other than the machine-independent format. If the result is a symbol, then [compile-target-machine?](eval.html#%28def._%28%28quote._~23~25kernel%29._compile-target-machine~3f%29%29) returns #t when applied to the symbol; see also [current-compile-target-machine](eval.html#%28def._%28%28quote._~23~25kernel%29._current-compile-target-machine%29%29).
# 15.5 Logging In 'so-suffix mode, then the result is a byte string that represents the file extension used for shared objects on the current platform. The byte string starts with a period, so it is suitable as a second argument to [path-replace-suffix](Manipulating_Paths.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._path-replace-suffix%29%29). In 'so-mode mode, then the result is 'local if foreign libraries should be opened in “local” mode by default (as on most platforms) or 'global if foreign libraries should be opened in “global” mode. In 'fs-change mode, the result is an immutable vector of four elements. Each element is either #f or a symbol, where a symbol indicates the presence of a property and #f indicates the absence of a property. The possible symbols, in order, are: - 'supported — [filesystem-change-evt](Filesystem.html#%28def._%28%28quote._~23~25kernel%29._filesystem-change-evt%29%29) can produce a [filesystem change event](Filesystem.html#%28tech._filesystem._change._event%29) to monitor filesystem changes; if this symbol is not first in the vector, all other vector elements are #f - 'scalable — resources consumed by a [filesystem change event](Filesystem.html#%28tech._filesystem._change._event%29) are effectively limited only by available memory, as opposed to file-descriptor limits; this property is #f on Mac OS and BSD variants of Unix - 'low-latency — creation and checking of a [filesystem change event](Filesystem.html#%28tech._filesystem._change._event%29) is practically instantaneous; this property is #f on Linux
# 15.5 Logging - 'file-level — a [filesystem change event](Filesystem.html#%28tech._filesystem._change._event%29) can track changes at the level of a file, as opposed to the file’s directory; this property is #f on Windows In 'cross mode, the result reports whether cross-platform build mode has been selected (through the -C or --cross argument to racket; see [Command Line](running-sa.html#%28part._mz-cmdline%29)). The possible symbols are: - 'infer — infer cross-platform mode based on whether ([system-type](#%28def._%28%28quote._~23~25kernel%29._system-type%29%29)) and ([cross-system-type](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=raco&rel=cross-system.html%23%2528def._%2528%2528lib._setup%252Fcross-system..rkt%2529._cross-system-type%2529%2529&version=8.18.0.13)) report the same symbol - 'force — use cross-platform mode, even if the current and target system types are the same, because the current and target executables can be different Changed in version 6.8.0.2 of package base: Added 'vm mode. Changed in version 6.9.0.1: Added 'cross mode. Changed in version 7.1.0.6: Added 'target-machine mode. Changed in version 7.9.0.6: Added 'os\* and 'arch modes. > ``` (system-language+country)  →  string?
# 15.5 Logging ``` Returns a string to identify the current user’s language and country. On Unix and Mac OS, the string is five characters: two lowercase ASCII letters for the language, an underscore, and two uppercase ASCII letters for the country. On Windows, the string can be arbitrarily long, but the language and country are in English (all ASCII letters or spaces) separated by an underscore. On Unix, the result is determined by checking the LC_ALL, LC_TYPE, and LANG environment variables, in that order (and the result is used if the environment variable’s value starts with two lowercase ASCII letters, an underscore, and two uppercase ASCII letters, followed by either nothing or a period). On Windows and Mac OS, the result is determined by system calls. > ``` (system-library-subpath [mode) → path?   mode : (or/c 'cgc '3m 'cs #f) = (system-type 'gc)``` Returns a relative directory path. This string can be used to build paths to system-specific files. For example, when Racket is running on Solaris on a Sparc architecture, the subpath starts "sparc-solaris", while the subpath for Windows on an i386 architecture starts "win32\\\\i386". The optional mode argument specifies the relevant garbage-collection variant, which one of the possible results of ([system-type](#%28def._%28%28quote._~23~25kernel%29._system-type%29%29) 'gc): 'cgc, '3m, or 'cs. It can also be #f, in which case the result is independent of the garbage-collection variant. Installation tools should use [cross-system-library-subpath](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=raco&rel=cross-system.html%23%2528def._%2528%2528lib._setup%252Fcross-system..rkt%2529._cross-system-library-subpath%2529%2529&version=8.18.0.13), instead, to support cross-installation. Changed in version 7.0 of package base: Added 'cs mode. > ``` (version)  →  (and/c string? immutable?) ```
# 15.5 Logging Returns an immutable string indicating the currently executing version of Racket. > ``` (banner)  →  (and/c string? immutable?) ``` Returns an immutable string for Racket’s start-up banner text (or the banner text for an embedding program, such as GRacket). The banner string ends with a newline. > ``` (current-command-line-arguments) → (-> vectorof (and/c string? immutable?)) (current-command-line-arguments argv) → void? argv : (-> vectorof (and/c string? immutable?)) ``` (current-thread-initial-stack-size) → (-> current-thread-initial-stack-size) (current-thread-initial-stack-size size) → void? size : (-> current-thread-initial-stack-size)``` A [parameter](eval-model.html#%28tech._parameter%29) that provides a hint about how much space to reserve for a newly created thread’s local variables. The actual space used by a computation is affected by [JIT](eval.html#%28tech._jit%29) compilation, but it is otherwise platform-independent. > ``` (parameter) → (-> and/c vector? (not/c immutable?))
# 15.5 Logging ``` (parameter) →``` Parses a command line according to the specification in the flag-clauses. The name-expr, if provided, should produce a path or string to be used as the program name for reporting errors when the command-line is ill-formed. It defaults to ([find-system-path](Filesystem.html#%28def._%28%28quote._~23~25kernel%29._find-system-path%29%29) 'run-file). When a path is provided, only the last element of the path is used to report an error. The argv-expr, if provided, must evaluate to a list or a vector of strings. It defaults to ([current-command-line-arguments](runtime.html#%28def._%28%28quote._~23~25kernel%29._current-command-line-arguments%29%29)). The command-line is disassembled into flags, each possibly with flag-specific arguments, followed by (non-flag) arguments. Command-line strings starting with - or + are parsed as flags, but arguments to flags are never parsed as flags, and integers and decimal numbers that start with - or + are not treated as flags. Non-flag arguments in the command-line must appear after all flags and the flags’ arguments. No command-line string past the first non-flag argument is parsed as a flag. The built-in -- flag signals the end of command-line flags; any command-line string past the -- flag is parsed as a non-flag argument. A #:multi, #:once-each, #:once-any, or #:final clause introduces a set of command-line flag specifications. The clause tag indicates how many times the flag can appear on the command line: - #:multi — Each flag specified in the set can be represented any number of times on the command line; i.e., the flags in the set are independent and each flag can be used multiple times. - #:once-each — Each flag specified in the set can be represented once on the command line; i.e., the flags in the set are independent, but each flag should be specified at most once. If a flag specification is represented in the command line more than once, the [exn:fail](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail%29%29) exception is raised. - #:once-any — Only one flag specified in the set can be represented on the command line; i.e., the flags in the set are mutually exclusive. If the set is represented in the command line more than once, the [exn:fail](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail%29%29) exception is raised. - #:final — Like #:multi, except that no argument after the flag is treated as a flag. Note that multiple #:final flags can be specified if they have short names; for example, if -a is a #:final flag, then -aa combines two instances of -a in a single command-line argument. A normal flag specification has four parts: - flags — a flag string, or a set of flag strings. If a set of flags is provided, all of the flags are equivalent. Each flag string must be of the form "-x" or "+x" for some character x, or "--x" or "++x" for some sequence of characters x. An x cannot contain only digits or digits plus a single decimal point, since simple (signed) numbers are not treated as flags. In addition, the flags "--", "-h", and "--help" are predefined and cannot be changed. - ids — identifier that are bound to the flag’s arguments. The number of identifiers determines how many arguments can be provided on the command line with the flag, and the names of these identifiers will appear in the help message describing the flag. The ids are bound to string values in the bodys for handling the flag. - help-spec — a string or sequence of strings that describes the flag. This string is used in the help message generated by the handler for the built-in -h (or --help) flag. A single literal string can be provided, or any number of expressions that produce strings; in the latter case, strings after the first one are displayed on subsequent lines. - bodys — expressions that are evaluated when one of the flags appears on the command line. The flags are parsed left-to-right, and each sequence of bodys is evaluated as the corresponding flag is encountered. When the bodys are evaluated, the preceding ids are bound to the arguments provided for the flag on the command line. A flag specification using [=>](if.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._~3d~3e%29%29) escapes to a more general method of specifying the handler and help strings. In this case, the handler procedure and help string list returned by handler-expr and help-expr are used as in the table argument of [parse-command-line](#%28def._%28%28lib._racket%2Fcmdline..rkt%29._parse-command-line%29%29). A #:usage-help clause inserts text lines immediately after the usage line. Each string in the clause provides a separate line of text. A #:help-labels clause inserts text lines into the help table of command-line flags. Each string in the clause provides a separate line of text. A #:ps clause inserts text lines at the end of the help output. Each string in the clause provides a separate line of text. After the flag clauses, a final clause handles command-line arguments that are not parsed as flags: - Supplying no finish clause is the same as supplying #:args () ([void](void.html#%28def._%28%28quote._~23~25kernel%29._void%29%29)). - For an #:args finish clause, identifiers in arg-formals are bound to the leftover command-line strings in the same way that identifiers are bound for a [lambda](lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._lambda%29%29) expression. Thus, specifying a single id (without parentheses) collects all of the leftover arguments into a list. The effective arity of the arg-formals specification determines the number of extra command-line arguments that the user can provide, and the names of the identifiers in arg-formals are used in the help string. When the command-line is parsed, if the number of provided arguments cannot be matched to identifiers in arg-formals, the [exn:fail](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail%29%29) exception is raised. Otherwise, args clause’s bodys are evaluated to handle the leftover arguments, and the result of the last body is the result of the [command-line](#%28form._%28%28lib._racket%2Fcmdline..rkt%29._command-line%29%29) expression. - A #:handlers finish clause escapes to a more general method of handling the leftover arguments. In this case, the values of the expressions are used like the last two to four arguments [parse-command-line](#%28def._%28%28lib._racket%2Fcmdline..rkt%29._parse-command-line%29%29). Example: > ```racket > ( define verbose-mode ( make-parameter #f ) ) > ( define profiling-on ( make-parameter #f ) ) > ( define optimize-level ( make-parameter 0 ) ) > ( define link-flags ( make-parameter null ) ) > ( define file-to-compile > ( command-line > #:program "compiler" > #:once-each > [ ( "-v" "--verbose" ) "Compile with verbose messages" > ( verbose-mode #t ) ] > [ ( "-p" "--profile" ) "Compile with profiling" > ( profiling-on #t ) ] > #:once-any > [ ( "-o" "--optimize-1" ) "Compile with optimization level 1" > ( optimize-level 1 ) ] > [ "--optimize-2" ( ; show help on separate lines > "Compile with optimization level 2," > "which includes all of level 1" ) > ( optimize-level 2 ) ] > #:multi > [ ( "-l" "--link-flags" ) lf ; flag takes one argument > "Add a flag <lf> for the linker" > ( link-flags ( cons lf ( link-flags ) ) ) ] > #:args ( filename ) ; expect one command-line argument: <filename> > ; return the argument as a filename to compile > filename ) ) > ``` > ``` (str) → (-> or/c string? path?) ```
# 15.5 Logging (non-flag) →``` Returns a string for the current machine’s hostname (including its domain). > ``` (getpid)  →  exact-integer? ``` Returns an integer identifying the current process within the operating system. ------------------------------------------------------------------------ # 16 Memory Management 8.18.0.13 ## 16 Memory Management | | |----------------------------------------------------------------------------------| |     16.1 Weak Boxes | |     16.2 Ephemerons | |     16.3 Wills and Executors | |     16.4 Garbage Collection | |     16.5 Phantom Byte Strings | ------------------------------------------------------------------------ # 16.1 Weak Boxes ### 16.1 Weak Boxes A weak box is similar to a normal box (see Boxes), but when the garbage collector (see Garbage Collection) can prove that the content value of a weak box is only reachable via weak references, the content of the weak box is replaced with #f. A weak reference is a reference through a weak box, through a key reference in a weak hash table (see Hash Tables), through a value in an ephemeron where the value can be replaced by #f (see Ephemerons), or through a custodian (see Custodians). > ``` (make-weak-box v) → weak-box?   v : any/c``` Returns a new weak box that initially contains v. > ``` (weak-box-value weak-box [gced-v) → any/c   weak-box : weak-box?   gced-v : any/c = #f ```
# 15.5 Logging Returns the value contained in weak-box. If the garbage collector has proven that the previous content value of weak-box was reachable only through a weak reference, then gced-v (which defaults to #f) is returned. > ``` (weak-box? v)  →  boolean?   v : any/c ``` Returns #t if v is a weak box, #f otherwise. ------------------------------------------------------------------------ # 16.2 Ephemerons ### 16.2 Ephemerons An ephemeron \[[Hayes97](doc-bibliography.html#%28cite._.Hayes97%29)\] is a generalization of a [weak box](weakbox.html#%28tech._weak._box%29) (see [Weak Boxes](weakbox.html)). Instead of just containing one value, an ephemeron holds two values: one that is considered the value of the ephemeron and another that is the ephemeron’s key. Like the value in a weak box, the value in an ephemeron may be replaced by #f, but when the key is no longer reachable (except possibly via weak references) instead of when the value is no longer reachable. As long as an ephemeron’s value is retained, the reference is considered a non-weak reference. References to the key via the value are treated specially, however, in that the reference does not necessarily count toward the key’s reachability. A [weak box](weakbox.html#%28tech._weak._box%29) can be seen as a specialization of an ephemeron where the key and value are the same. One particularly common use of ephemerons is to combine them with a weak hash table (see [Hash Tables](hashtables.html)) to produce a mapping where the memory manager can reclaim key–value pairs even when the value refers to the key; see [make-ephemeron-hash](hashtables.html#%28def._%28%28quote._~23~25kernel%29._make-ephemeron-hash%29%29). A related use is to retain a reference to a value as long as any value for which it is an [impersonator](chaperones.html#%28tech._impersonator%29) is reachable; see [impersonator-ephemeron](chaperones.html#%28def._%28%28quote._~23~25kernel%29._impersonator-ephemeron%29%29). More precisely, - the value in an ephemeron is replaced by #f when the automatic memory manager can prove that either the ephemeron or the key is reachable only through weak references (see [Weak Boxes](weakbox.html)); and - nothing reachable from the value in an ephemeron counts toward the reachability of an ephemeron key (whether for the same ephemeron or another), unless the same value is reachable through a non-weak reference, or unless the value’s ephemeron key is reachable through a non-weak reference (see [Weak Boxes](weakbox.html) for information on weak references). > ``` (make-ephemeron key v)  →  ephemeron?   key : any/c   v : any/c ```
# 15.5 Logging Returns a new ephemeron whose key is key and whose value is initially v. > ``` (ephemeron-value ephemeron [gced-v retain-v) → any/c   ephemeron : ephemeron?   gced-v : any/c = #f   retain-v : any/c = #f``` Returns the value contained in ephemeron. If the garbage collector has proven that the key for ephemeron is only weakly reachable, then the result is gced-v (which defaults to #f). The retain-v argument is retained as reachable until the ephemeron’s value is extracted. It is useful, for example, when ephemeron was obtained through a weak, [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29)-based mapping from key and ephemeron was created with key as the key; in that case, supplying key as retain-v ensures that ephemeron retains its value long enough for it to be extracted, even if key is otherwise unreachable. Changed in version 7.1.0.10 of package base: Added the retain-v argument. > ``` (ephemeron? v)  →  boolean?   v : any/c
# 15.5 Logging ``` Returns #t if v is an ephemeron, #f otherwise. ------------------------------------------------------------------------ # 16.3 Wills and Executors ### 16.3 Wills and Executors A will executor manages a collection of values and associated will procedures (a.k.a. finalizers). The will procedure for each value is ready to be executed when the value has been proven (by the garbage collector) to be unreachable, except through weak references (see Weak Boxes) or as the registrant for other will executors. A will is useful for triggering clean-up actions on data associated with an unreachable value, such as closing a port embedded in an object when the object is no longer used. Calling the will-execute or will-try-execute procedure executes a will that is ready in the specified will executor. A will executor is also a synchronizable event, so sync or sync/timeout can be used to detect when a will executor has ready wills. Wills are not executed automatically, because certain programs need control to avoid race conditions. However, a program can create a thread whose sole job is to execute wills for a particular executor. If a value is registered with multiple wills (in one or multiple executors), the wills are readied in the reverse order of registration. Since readying a will procedure makes the value reachable again, the will must be executed and the value must be proven again unreachable through only weak references before another of the wills is readied or executed. However, wills for distinct unreachable values are readied at the same time, regardless of whether the values are reachable from each other. A will executor’s registrant is held non-weakly until after the corresponding will procedure is executed. Thus, if the content value of a weak box (see Weak Boxes) is registered with a will executor, the weak box’s content is not changed to #f until all wills have been executed for the value and the value has been proven again reachable through only weak references. A will executor can be used as a synchronizable event (see Events). A will executor is ready for synchronization when will-execute would not block; the synchronization result of a will executor is the will executor itself. These examples show how to run cleanup actions when no synchronization is necessary. It simply runs the registered executors as they become ready in another thread. Examples: > ```racket > > ( define an-executor ( make-will-executor ) ) > > ( void ( thread ( λ ( ) ( let loop ( ) ( will-execute an-executor ) ( loop ) ) ) ) ) > > ( define ( executor-proc v ) ( printf "a-box is now garbage\n" ) ) > > ( define a-box-to-track ( box #f ) ) > > ( will-register an-executor a-box-to-track executor-proc ) > > ( collect-garbage ) > > ( set! a-box-to-track #f ) > > ( collect-garbage ) > a-box is now garbage > ``` > ``` (make-will-executor)  →  will-executor?``` Returns a new will executor with no managed values. > ``` (will-executor? v)  →  boolean?   v : any/c ```
# 15.5 Logging (parameter) → (-> any/c . → . any)``` Registers the value v with the will procedure proc in the will executor executor. When v is proven unreachable, then the procedure proc is ready to be called with v as its argument via [will-execute](#%28def._%28%28quote._~23~25kernel%29._will-execute%29%29) or [will-try-execute](#%28def._%28%28quote._~23~25kernel%29._will-try-execute%29%29). The proc argument is strongly referenced until the will procedure is executed. > ``` (will-execute executor)  →  any   executor : will-executor? ``` Invokes the will procedure for a single “unreachable” value registered with the executor executor. The values returned by the will procedure are the result of the will-execute call. If no will is ready for immediate execution, will-execute blocks until one is ready. > ``` (will-try-execute executor [v) → any   executor : any/c   v : any/c = #f``` Like [will-execute](#%28def._%28%28quote._~23~25kernel%29._will-execute%29%29) if a will is ready for immediate execution. Otherwise, v is returned. Changed in version 6.90.0.4 of package base: Added the v argument. ------------------------------------------------------------------------ # 16.4 Garbage Collection ### 16.4 Garbage Collection Set the PLTDISABLEGC environment variable (to any value) before Racket starts to disable [garbage collection](eval-model.html#%28tech._garbage._collection%29). Set the PLT_INCREMENTAL_GC environment variable to a value that starts with 1, y, or Y to request incremental mode at all times for the [3m](implementations.html#%28tech._3m%29) implementation of Racket, but calling ([collect-garbage](#%28def._%28%28quote._~23~25kernel%29._collect-garbage%29%29) 'incremental) in a program with a periodic task is generally a better mechanism for requesting incremental mode. Set the PLT_INCREMENTAL_GC environment variable to a value that starts with 0, n, or N to disable incremental-mode requests (in all implementations of Racket). Each garbage collection logs a message (see [Logging](logging.html)) at the 'debug level with topic 'GC. In the [CS](implementations.html#%28tech._c%29) and [3m](implementations.html#%28tech._3m%29) implementations of Racket, “major” collections are also logged at the 'debug level with the topic 'GC:major. In the [CS](implementations.html#%28tech._c%29) and [3m](implementations.html#%28tech._3m%29) implementations of Racket, the data portion of the message is an instance of a gc-info [prefab](structures.html#%28tech._prefab%29) structure type with 10 fields as follows, but future versions of Racket may use a gc-info [prefab](structures.html#%28tech._prefab%29) structure with additional fields: > ```racket > ( struct gc-info ( mode pre-amount pre-admin-amount code-amount > post-amount post-admin-amount > start-process-time end-process-time > start-time end-time ) > #:prefab ) > ``` - The mode field is a symbol 'major, 'minor, or 'incremental; 'major indicates a collection that inspects all memory, 'minor indicates collection that mostly inspects just recent allocations, and 'incremental indicates a minor collection that performs extra work toward the next major collection. Changed in version 6.3.0.7 of package base: Changed first field from a boolean (#t for 'major, #f for 'minor) to a mode symbol. - The pre-amount field reports place-local memory use (i.e., not counting the memory use of child places) in bytes at the time that the [garbage collection](eval-model.html#%28tech._garbage._collection%29) started. Additional bytes registered via [make-phantom-bytes](phantom-bytes.html#%28def._%28%28quote._~23~25kernel%29._make-phantom-bytes%29%29) are included. - The pre-admin-amount is a larger number that includes memory use for the garbage collector’s overhead, such as space on memory pages that are mapped but not currently used. - The code-amount field reports additional memory use for generated native code (which is the same just before and after a garbage collection, since it is released via finalization). - The post-amount and post-admin-amount fields correspond to pre-amount and pre-admin-amount, but after garbage collection. In typical configurations, the difference between post-amount and pre-amount contributes to post-admin-amount, since reclaimed pages tend to stay in reserve with the expectation that they’ll be needed again (but the pages are released if multiple collections pass without need for the pages). - The start-process-time and end-process-time fields report processor time (in the sense of [current-process-milliseconds](time.html#%28def._%28%28quote._~23~25kernel%29._current-process-milliseconds%29%29)) at the start and end of garbage collection. The difference between the times is the processor time consumed by collection. - The start-time and end-time fields report real time (in the sense of [current-inexact-milliseconds](time.html#%28def._%28%28quote._~23~25kernel%29._current-inexact-milliseconds%29%29)) at the start and end of garbage collection. The difference between the times is the real time consumed by garbage collection. The format of the logged message’s text is subject to change. Currently, after a prefix that indicates the [place](places.html#%28tech._place%29) and collection mode, the text has the format > ‹used›(‹admin›)\[‹code›\]; free ‹reclaimed›(‹adjust›) ‹elapsed› @ ‹timestamp› > > | | | | > |-------------|-----|---------------------------------------------------------------| > | ‹used› |   | Collectable memory in use just prior to garbage collection | > | ‹admin› |   | Additional memory used as to manage collectable memory | > | ‹code› |   | Additional memory used for generated machine code | > | ‹reclaimed› |   | Collectable memory reclaimed by garbage collection | > | ‹adjust› |   | Negation of change to administrative memory minus ‹reclaimed› | > | ‹elapsed› |   | Processor time used to perform garbage collection | > | ‹timestamp› |   | Processor time since startup of garbage collection’s start | Changed in version 6.3.0.7 of package base: Added PLT_INCREMENTAL_GC. Changed in version 7.6.0.9: Added major-collection logging for the topic 'GC:major. > ``` (parameter) → (-> or/c 'major 'minor 'incremental) ```
# 15.5 Logging (parameter) → (-> or/c #f 'cumulative 'peak custodian?)``` Returns information about memory use: - If mode is #f (the default), the result is an estimate of the number of bytes reachable from any custodian. - If mode is 'cumulative, returns an estimate of the total number of bytes allocated since start up, including bytes that have since been reclaimed by garbage collection. - If mode is 'peak, returns the maximum number of allocated bytes just before any garbage collection in the Racket process since its start. - If mode is a custodian, returns an estimate of the number of bytes of memory occupied by reachable data from mode. This estimate is calculated by the last garbage collection, and can be 0 if none occurred (or if none occurred since the given custodian was created). The [current-memory-use](#%28def._%28%28quote._~23~25kernel%29._current-memory-use%29%29) function does not perform a collection by itself; doing one before the call will generally decrease the result (or increase it from 0 if no collections happened yet). When Racket is compiled without support for memory accounting, the estimate is the same as when mode is #f (i.e., all memory) for any individual custodian. See also [custodian-memory-accounting-available?](custodians.html#%28def._%28%28quote._~23~25kernel%29._custodian-memory-accounting-available~3f%29%29). See also [vector-set-performance-stats!](runtime.html#%28def._%28%28quote._~23~25kernel%29._vector-set-performance-stats%21%29%29).
# 15.5 Logging Changed in version 6.6.0.3 of package base: Added 'cumulative mode. Changed in version 8.10.0.3: Added 'peak mode. > ``` (dump-memory-stats v ...) → any   v : any/c ``` (parameter) →``` Returns #t if v is a [phantom byte string](#%28tech._phantom._byte._string%29), #f otherwise. > ``` (make-phantom-bytes k)  →  phantom-bytes?   k : exact-nonnegative-integer? ``` Creates a phantom byte string that is treated by the Racket memory manager as being k bytes in size. For a large enough k, the exn:fail:out-of-memory exception is raised—either because the size is implausibly large, or because a memory limit has been installed with custodian-limit-memory. > ``` (set-phantom-bytes! phantom-bstr k)  →  phantom-bytes?   phantom-bstr : phantom-bytes?   k : exact-nonnegative-integer?``` Adjusts the size of a [phantom byte string](#%28tech._phantom._byte._string%29) as it is treated by the Racket memory manager. For example, if the memory that phantom-bstr represents is released through a foreign library, then ([set-phantom-bytes!](#%28def._%28%28quote._~23~25kernel%29._set-phantom-bytes%21%29%29) phantom-bstr 0) can reflect the change in memory use. When k is larger than the current size of phantom-bstr, then this function can raise [exn:fail:out-of-memory](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3aout-of-memory%29%29), like [make-phantom-bytes](#%28def._%28%28quote._~23~25kernel%29._make-phantom-bytes%29%29). ------------------------------------------------------------------------
# 17 Unsafe Operations
## 17 Unsafe Operations | | | |:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:| |  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/unsafe/ops]()) |  package: [base](https://pkgs.racket-lang.org/package/base "Install this package using `raco pkg install base`") | All functions and forms provided by [racket/base](index.html) and [racket](index.html) check their arguments to ensure that the arguments conform to contracts and other constraints. For example, [vector-ref](vectors.html#%28def._%28%28quote._~23~25kernel%29._vector-ref%29%29) checks its arguments to ensure that the first argument is a vector, that the second argument is an exact integer, and that the second argument is between 0 and one less than the vector’s length, inclusive.
# 17 Unsafe Operations Functions provided by [racket/unsafe/ops]() are unsafe. They have certain constraints, but the constraints are not checked, which allows the system to generate and execute faster code. If arguments violate an unsafe function’s constraints, the function’s behavior and result is unpredictable, and the entire system can crash or become corrupted. All of the exported bindings of [racket/unsafe/ops]() are protected in the sense of [protect-out](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._protect-out%29%29), so access to unsafe operations can be prevented by adjusting the code inspector (see [Code Inspectors](modprotect.html)).
### 17.1 Unsafe Numeric Operations > ``` (unsafe-fx+ a ...) → fixnum?   a : fixnum? (unsafe-fx- a b ...)  →  fixnum?   a : fixnum?   b : fixnum? (unsafe-fx* a ...)  →  fixnum?   a : fixnum? (unsafe-fxquotient a b)  →  fixnum?   a : fixnum?   b : fixnum? (unsafe-fxremainder a b)  →  fixnum?   a : fixnum?   b : fixnum? (unsafe-fxmodulo a b)  →  fixnum?   a : fixnum?   b : fixnum? (unsafe-fxabs a)  →  fixnum?   a : fixnum? ``` For fixnums: Unchecked versions of fx+, fx-, fx*, fxquotient, fxremainder, fxmodulo, and fxabs. Changed in version 7.0.0.13 of package base: Allow zero or more arguments for unsafe-fx+ and unsafe-fx* and allow one or more arguments for unsafe-fx-. > ``` (unsafe-fxand a ...) → fixnum?   a : fixnum? (unsafe-fxior a ...)  →  fixnum?   a : fixnum? (unsafe-fxxor a ...)  →  fixnum?   a : fixnum? (unsafe-fxnot a)  →  fixnum?   a : fixnum? (unsafe-fxlshift a b)  →  fixnum?   a : fixnum?   b : fixnum? (unsafe-fxrshift a b)  →  fixnum?   a : fixnum?   b : fixnum? (unsafe-fxrshift/logical a b)  →  fixnum?   a : fixnum?   b : fixnum?``` For [fixnums](numbers.html#%28tech._fixnum%29): Unchecked versions of [fxand](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxand%29%29), [fxior](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxior%29%29), [fxxor](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxxor%29%29), [fxnot](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxnot%29%29), [fxlshift](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxlshift%29%29), [fxrshift](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxrshift%29%29), and [fxrshift/logical](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxrshift%2Flogical%29%29). Changed in version 7.0.0.13 of package base: Allow zero or more arguments for [unsafe-fxand](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fxand%29%29), [unsafe-fxior](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fxior%29%29), and [unsafe-fxxor](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fxxor%29%29). Changed in version 8.8.0.5: Added [unsafe-fxrshift/logical](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fxrshift%2Flogical%29%29). > ``` (unsafe-fxpopcount a)  →  fixnum?   a : (and/c fixnum? (not/c negative?)) (unsafe-fxpopcount32 a)  →  fixnum?   a : (and/c fixnum? (integer-in 0 #xFFFFFFFF)) (unsafe-fxpopcount16 a)  →  fixnum?   a : (and/c fixnum? (integer-in 0 #xFFFF)) ```
### 17.1 Unsafe Numeric Operations For fixnums: Unchecked versions of fxpopcount, fxpopcount32, and fxpopcount16. Added in version 8.5.0.6 of package base. > ``` (unsafe-fx+/wraparound a b) → fixnum?   a : fixnum?   b : fixnum? (unsafe-fx-/wraparound [a] b)  →  fixnum?   a : fixnum? = 0   b : fixnum? (unsafe-fx*/wraparound a b)  →  fixnum?   a : fixnum?   b : fixnum? (unsafe-fxlshift/wraparound a b)  →  fixnum?   a : fixnum?   b : fixnum?``` For [fixnums](numbers.html#%28tech._fixnum%29): Unchecked versions of [fx+/wraparound](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fx%2B%2Fwraparound%29%29), [fx-/wraparound](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fx-%2Fwraparound%29%29), [fx*/wraparound](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fx%2A%2Fwraparound%29%29), and [fxlshift/wraparound](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxlshift%2Fwraparound%29%29). Added in version 7.9.0.6 of package base. Changed in version 8.15.0.12: Changed [unsafe-fx-/wraparound](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fx-%2Fwraparound%29%29) to accept a single argument. > ``` (unsafe-fx= a b ...) → boolean?   a : fixnum?   b : fixnum? ([unsafe-fx (unsafe-fx> a b ...)  →  boolean?   a : fixnum?   b : fixnum? ([unsafe-fx (unsafe-fx>= a b ...)  →  boolean?   a : fixnum?   b : fixnum? (unsafe-fxmin a b ...)  →  fixnum?   a : fixnum?   b : fixnum? (unsafe-fxmax a b ...)  →  fixnum?   a : fixnum?   b : fixnum?
### 17.1 Unsafe Numeric Operations ``` For fixnums: Unchecked versions of fx=, fx<, fx>, fx<=, fx>=, fxmin, and fxmax. Changed in version 7.0.0.13 of package base: Allow one or more argument, instead of allowing just two. > ``` (unsafe-fl+ a ...) → flonum?   a : flonum? (unsafe-fl- a b ...)  →  flonum?   a : flonum?   b : flonum? (unsafe-fl* a ...)  →  flonum?   a : flonum? (unsafe-fl/ a b ...)  →  flonum?   a : flonum?   b : flonum? (unsafe-flabs a)  →  flonum?   a : flonum?``` For [flonums](numbers.html#%28tech._flonum%29): Unchecked versions of [fl+](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl%2B%29%29), [fl-](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl-%29%29), [fl*](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl%2A%29%29), [fl/](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fl%2F%29%29), and [flabs](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flabs%29%29). Changed in version 7.0.0.13 of package base: Allow zero or more arguments for [unsafe-fl+](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fl%2B%29%29) and [unsafe-fl*](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fl%2A%29%29) and one or more arguments for [unsafe-fl-](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fl-%29%29) and [unsafe-fl/](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fl%2F%29%29). > ``` (unsafe-fl= a b ...) → boolean?   a : flonum?   b : flonum? ([unsafe-fl (unsafe-fl> a b ...)  →  boolean?   a : flonum?   b : flonum? ([unsafe-fl (unsafe-fl>= a b ...)  →  boolean?   a : flonum?   b : flonum? (unsafe-flmin a b ...)  →  flonum?   a : flonum?   b : flonum? (unsafe-flmax a b ...)  →  flonum?   a : flonum?   b : flonum? ```
### 17.1 Unsafe Numeric Operations For flonums: Unchecked versions of fl=, fl<, fl>, fl<=, fl>=, flmin, and flmax. Changed in version 7.0.0.13 of package base: Allow one or more argument, instead of allowing just two. > ``` (unsafe-flround a) → flonum?   a : flonum? (unsafe-flfloor a)  →  flonum?   a : flonum? (unsafe-flceiling a)  →  flonum?   a : flonum? (unsafe-fltruncate a)  →  flonum?   a : flonum?``` For [flonums](numbers.html#%28tech._flonum%29): Unchecked (potentially) versions of [flround](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flround%29%29), [flfloor](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flfloor%29%29), [flceiling](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flceiling%29%29), and [fltruncate](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._fltruncate%29%29). Currently, these bindings are simply aliases for the corresponding safe bindings. > ``` (unsafe-flsingle a)  →  flonum?   a : flonum?
### 17.1 Unsafe Numeric Operations ``` For flonums: Unchecked (potentially) version of flsingle. Added in version 7.8.0.7 of package base. > ``` (flbit-field a start end)  →  exact-nonnegative-integer?   a : flonum?   start : (integer-in 0 64)   end : (integer-in 0 64)``` For [flonums](numbers.html#%28tech._flonum%29): Unchecked version of [flbit-field](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flbit-field%29%29). Added in version 7.8.0.7 of package base. > ``` (unsafe-flsin a)  →  flonum?   a : flonum? (unsafe-flcos a)  →  flonum?   a : flonum? (unsafe-fltan a)  →  flonum?   a : flonum? (unsafe-flasin a)  →  flonum?   a : flonum? (unsafe-flacos a)  →  flonum?   a : flonum? (unsafe-flatan a)  →  flonum?   a : flonum? (unsafe-fllog a)  →  flonum?   a : flonum? (unsafe-flexp a)  →  flonum?   a : flonum? (unsafe-flsqrt a)  →  flonum?   a : flonum? (unsafe-flexpt a b)  →  flonum?   a : flonum?   b : flonum? ``` For flonums: Unchecked (potentially) versions of flsin, flcos, fltan, flasin, flacos, flatan, fllog, flexp, flsqrt, and flexpt. Currently, some of these bindings are simply aliases for the corresponding safe bindings. > ``` (unsafe-make-flrectangular a b)   →   ( and/c complex? > ( lambda ( c ) ( flonum? ( real-part c ) ) ) > ( lambda ( c ) ( flonum? ( imag-part c ) ) ) )   a : flonum?   b : flonum? (unsafe-flreal-part a)  →  flonum?    a   :   ( and/c complex? > ( lambda ( c ) ( flonum? ( real-part c ) ) ) > ( lambda ( c ) ( flonum? ( imag-part c ) ) ) ) (unsafe-flimag-part a)  →  flonum?    a   :   ( and/c complex?
### 17.1 Unsafe Numeric Operations > ( lambda ( c ) ( flonum? ( real-part c ) ) ) > ( lambda ( c ) ( flonum? ( imag-part c ) ) ) )``` For [flonums](numbers.html#%28tech._flonum%29): Unchecked versions of [make-flrectangular](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._make-flrectangular%29%29), [flreal-part](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flreal-part%29%29), and [flimag-part](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flimag-part%29%29). > ``` (unsafe-fx → fl a)  →  flonum?   a : fixnum? (unsafe-fl → fx a)  →  fixnum?   a : flonum? ``` Unchecked versions of fx → fl and fl → fx. Changed in version 7.7.0.8 of package base: Changed unsafe-fl → fx to truncate. > ``` (unsafe-flrandom rand-gen)  →  (and flonum? (>/c 0) ([``` Unchecked version of [flrandom](flonums.html#%28def._%28%28lib._racket%2Fflonum..rkt%29._flrandom%29%29). ### 17.2 Unsafe Character Operations > ``` (unsafe-char=? a b ...) → boolean?   a : char?   b : char? ([unsafe-char (unsafe-char>? a b ...)  →  boolean?   a : char?   b : char? ([unsafe-char (unsafe-char>=? a b ...)  →  boolean?   a : char?   b : char? (unsafe-char → integer a)  →  fixnum?   a : char? ``` (parameter) → (-> parameter)```
### 17.1 Unsafe Numeric Operations Unsafe variants of [car](pairs.html#%28def._%28%28quote._~23~25kernel%29._car%29%29), [cdr](pairs.html#%28def._%28%28quote._~23~25kernel%29._cdr%29%29), [mcar](mpairs.html#%28def._%28%28quote._~23~25kernel%29._mcar%29%29), [mcdr](mpairs.html#%28def._%28%28quote._~23~25kernel%29._mcdr%29%29), [set-mcar!](mpairs.html#%28def._%28%28quote._~23~25kernel%29._set-mcar%21%29%29), and [set-mcdr!](mpairs.html#%28def._%28%28quote._~23~25kernel%29._set-mcdr%21%29%29). > ``` (unsafe-cons-list v rest)  →  (and/c pair? list?)   v : any/c   rest : list? ``` Unsafe variant of cons that produces a pair that claims to be a list—without checking whether rest is a list. > ``` (unsafe-list-ref lst pos)  →  any/c   lst : pair?   pos : (and/c exact-nonnegative-integer? fixnum?) (unsafe-list-tail lst pos)  →  any/c   lst : any/c   pos : (and/c exact-nonnegative-integer? fixnum?)``` Unsafe variants of [list-ref](pairs.html#%28def._%28%28quote._~23~25kernel%29._list-ref%29%29) and [list-tail](pairs.html#%28def._%28%28quote._~23~25kernel%29._list-tail%29%29), where pos must be a [fixnum](numbers.html#%28tech._fixnum%29), and lst must start with at least ([add1](generic-numbers.html#%28def._%28%28quote._~23~25kernel%29._add1%29%29) pos) (for [unsafe-list-ref](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-list-ref%29%29)) or pos (for [unsafe-list-tail](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-list-tail%29%29)) pairs. > ``` (parameter) → (-> unsafe-set-immutable-cdr! p v) ``` (parameter) → (-> unsafe-set-box! b k)```
### 17.1 Unsafe Numeric Operations Unsafe versions of [unbox](boxes.html#%28def._%28%28quote._~23~25kernel%29._unbox%29%29) and [set-box!](boxes.html#%28def._%28%28quote._~23~25kernel%29._set-box%21%29%29), where the box\* variants can be faster but do not work on [impersonators](chaperones.html#%28tech._impersonator%29). > ``` (unsafe-box*-cas! loc old new)  →  boolean?   loc : box?   old : any/c   new : any/c ``` (parameter) → (-> unsafe-vector-ref v k)``` Unsafe versions of [vector-length](vectors.html#%28def._%28%28quote._~23~25kernel%29._vector-length%29%29), [vector-ref](vectors.html#%28def._%28%28quote._~23~25kernel%29._vector-ref%29%29), [vector-set!](vectors.html#%28def._%28%28quote._~23~25kernel%29._vector-set%21%29%29), [vector-cas!](vectors.html#%28def._%28%28quote._~23~25kernel%29._vector-cas%21%29%29), [vector-copy](vectors.html#%28def._%28%28lib._racket%2Fvector..rkt%29._vector-copy%29%29), [vector-set/copy](vectors.html#%28def._%28%28lib._racket%2Fvector..rkt%29._vector-set%2Fcopy%29%29), and [vector-append](vectors.html#%28def._%28%28lib._racket%2Fvector..rkt%29._vector-append%29%29), where the vector\* variants can be faster but do not work on [impersonators](chaperones.html#%28tech._impersonator%29). A vector’s size can never be larger than a [fixnum](numbers.html#%28tech._fixnum%29), so even [vector-length](vectors.html#%28def._%28%28quote._~23~25kernel%29._vector-length%29%29) always returns a fixnum. Changed in version 6.11.0.2 of package base: Added [unsafe-vector*-cas!](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-vector%2A-cas%21%29%29). Changed in version 8.11.1.9: Added [unsafe-vector-copy](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-vector-copy%29%29), [unsafe-vector*-copy](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-vector%2A-copy%29%29), [unsafe-vector-set/copy](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-vector-set%2Fcopy%29%29), [unsafe-vector*-set/copy](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-vector%2A-set%2Fcopy%29%29), [unsafe-vector-append](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-vector-append%29%29), and [unsafe-vector*-append](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-vector%2A-append%29%29). > ``` (unsafe-vector* → immutable-vector! v)   →  (and/c vector? immutable?)   v : (and/c vector? (not/c impersonator?)) ```
### 17.1 Unsafe Numeric Operations Similar to vector → immutable-vector, but potentially destroys v and reuses it space, so v must not be used after calling unsafe-vector* → immutable-vector!. Added in version 7.7.0.6 of package base. > ``` (ch) → ( → unsafe-string-ref str k)``` Unsafe versions of [string-length](strings.html#%28def._%28%28quote._~23~25kernel%29._string-length%29%29), [string-ref](strings.html#%28def._%28%28quote._~23~25kernel%29._string-ref%29%29), and [string-set!](strings.html#%28def._%28%28quote._~23~25kernel%29._string-set%21%29%29). The [unsafe-string-ref](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-string-ref%29%29) procedure can be used only when the result will be a Latin-1 character. A string’s size can never be larger than a [fixnum](numbers.html#%28tech._fixnum%29) (so even [string-length](strings.html#%28def._%28%28quote._~23~25kernel%29._string-length%29%29) always returns a fixnum). > ``` (unsafe-string → immutable-string! str)   →  (and/c string? immutable?)   str : string?
### 17.1 Unsafe Numeric Operations ``` (parameter) → (-> parameter)``` Unsafe versions of [bytes-length](bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes-length%29%29), [bytes-ref](bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes-ref%29%29), [bytes-set!](bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes-set%21%29%29), and [bytes-copy!](bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes-copy%21%29%29). A bytes’s size can never be larger than a [fixnum](numbers.html#%28tech._fixnum%29) (so even [bytes-length](bytestrings.html#%28def._%28%28quote._~23~25kernel%29._bytes-length%29%29) always returns a fixnum). Changed in version 7.5.0.15 of package base: Added [unsafe-bytes-copy!](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-bytes-copy%21%29%29). > ``` (unsafe-bytes → immutable-bytes! bstr)   →  (and/c bytes? immutable?)   bstr : bytes? ``` (parameter) → (-> parameter)``` Unsafe versions of [fxvector-length](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxvector-length%29%29), [fxvector-ref](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxvector-ref%29%29), and [fxvector-set!](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxvector-set%21%29%29). A [fxvector](fixnums.html#%28tech._fxvector%29)’s size can never be larger than a [fixnum](numbers.html#%28tech._fixnum%29) (so even [fxvector-length](fixnums.html#%28def._%28%28lib._racket%2Ffixnum..rkt%29._fxvector-length%29%29) always returns a fixnum). > ``` (parameter) → (-> unsafe-flvector-ref v k)
### 17.1 Unsafe Numeric Operations ``` (parameter) → (-> unsafe-f64vector-set! vec k n)``` Unsafe versions of [f64vector-ref](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=foreign&rel=homogeneous-vectors.html%23%2528def._%2528%2528lib._ffi%252Fvector..rkt%2529._f64vector-ref%2529%2529&version=8.18.0.13) and [f64vector-set!](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=foreign&rel=homogeneous-vectors.html%23%2528def._%2528%2528lib._ffi%252Fvector..rkt%2529._f64vector-set%2521%2529%2529&version=8.18.0.13). > ``` (parameter) → (-> integer-in -32768 32767) ``` (parameter) → (-> integer-in 0 65535)``` Unsafe versions of [u16vector-ref](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=foreign&rel=homogeneous-vectors.html%23%2528def._%2528%2528lib._ffi%252Fvector..rkt%2529._u16vector-ref%2529%2529&version=8.18.0.13) and [u16vector-set!](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=foreign&rel=homogeneous-vectors.html%23%2528def._%2528%2528lib._ffi%252Fvector..rkt%2529._u16vector-set%2521%2529%2529&version=8.18.0.13). > ``` (stencil-vector-mask-width) → (-> integer-in 0 (sub1 (expt 2 (stencil-vector-mask-width))))
### 17.1 Unsafe Numeric Operations ``` (parameter) → (-> unsafe-struct-set! v k val)``` Unsafe field access and update for an instance of a structure type, where the struct\* variants can be faster but do not work on [impersonators](chaperones.html#%28tech._impersonator%29). The index k must be between 0 (inclusive) and the number of fields in the structure (exclusive). In the case of [unsafe-struct-set!](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-struct-set%21%29%29), [unsafe-struct*-set!](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-struct%2A-set%21%29%29), and [unsafe-struct*-cas!](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-struct%2A-cas%21%29%29), the field must be mutable. The [unsafe-struct*-cas!](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-struct%2A-cas%21%29%29) operation is analogous to [box-cas!](boxes.html#%28def._%28%28quote._~23~25kernel%29._box-cas%21%29%29) to perform an atomic compare-and-set. Changed in version 6.11.0.2 of package base: Added [unsafe-struct*-cas!](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-struct%2A-cas%21%29%29). > ``` (unsafe-struct*-type v)  →  struct-type?   v : any/c ``` Similar to struct-info, but without an inspector check, returning only the first result, and without support for impersonators. Added in version 8.8.0.3 of package base. > ``` (unsafe-mutable-hash-iterate-first hash)  →  (or/c #f any/c)   hash : (and/c hash? (not/c immutable?) hash-strong?)
### 17.1 Unsafe Numeric Operations (unsafe-mutable-hash-iterate-next hash pos)  →  (or/c #f any/c)   hash : (and/c hash? (not/c immutable?) hash-strong?)   pos : any/c (unsafe-mutable-hash-iterate-key hash pos)  →  any/c   hash : (and/c hash? (not/c immutable?) hash-strong?)   pos : any/c (unsafe-mutable-hash-iterate-key   hash             pos             bad-index-v)   →   any/c   hash : (and/c hash? (not/c immutable?) hash-strong?)   pos : any/c   bad-index-v : any/c (unsafe-mutable-hash-iterate-value   hash             pos)   →   any/c   hash : (and/c hash? (not/c immutable?) hash-strong?)   pos : any/c (unsafe-mutable-hash-iterate-value   hash             pos             bad-index-v)   →   any/c   hash : (and/c hash? (not/c immutable?) hash-strong?)   pos : any/c   bad-index-v : any/c (unsafe-mutable-hash-iterate-key+value   hash             pos)   →   any/c   any/c   hash : (and/c hash? (not/c immutable?) hash-strong?)   pos : any/c (unsafe-mutable-hash-iterate-key+value   hash       pos       bad-index-v)     →   any/c   any/c   hash : (and/c hash? (not/c immutable?) hash-strong?)   pos : any/c   bad-index-v : any/c (unsafe-mutable-hash-iterate-pair hash pos)  →  pair?   hash : (and/c hash? (not/c immutable?) hash-strong?)   pos : any/c (unsafe-mutable-hash-iterate-pair   hash             pos             bad-index-v)   →   pair?   hash : (and/c hash? (not/c immutable?) hash-strong?)   pos : any/c   bad-index-v : any/c (unsafe-immutable-hash-iterate-first hash)  →  (or/c #f any/c)   hash : (and/c hash? immutable?)
### 17.1 Unsafe Numeric Operations (unsafe-immutable-hash-iterate-next   hash             pos)   →   (or/c #f any/c)   hash : (and/c hash? immutable?)   pos : any/c (unsafe-immutable-hash-iterate-key   hash             pos)   →   any/c   hash : (and/c hash? immutable?)   pos : any/c (unsafe-immutable-hash-iterate-key   hash             pos             bad-index-v)   →   any/c   hash : (and/c hash? immutable?)   pos : any/c   bad-index-v : any/c (unsafe-immutable-hash-iterate-value   hash             pos)   →   any/c   hash : (and/c hash? immutable?)   pos : any/c (unsafe-immutable-hash-iterate-value   hash             pos             bad-index-v)   →   any/c   hash : (and/c hash? immutable?)   pos : any/c   bad-index-v : any/c (unsafe-immutable-hash-iterate-key+value   hash             pos)   →   any/c   any/c   hash : (and/c hash? immutable?)   pos : any/c (unsafe-immutable-hash-iterate-key+value   hash       pos       bad-index-v)     →   any/c   any/c   hash : (and/c hash? immutable?)   pos : any/c   bad-index-v : any/c (unsafe-immutable-hash-iterate-pair   hash             pos)   →   pair?   hash : (and/c hash? immutable?)   pos : any/c (unsafe-immutable-hash-iterate-pair   hash             pos             bad-index-v)   →   pair?   hash : (and/c hash? immutable?)   pos : any/c   bad-index-v : any/c (unsafe-weak-hash-iterate-first hash)  →  (or/c #f any/c)   hash : (and/c hash? hash-weak?) (unsafe-weak-hash-iterate-next hash pos)  →  (or/c #f any/c)   hash : (and/c hash? hash-weak?)   pos : any/c
### 17.1 Unsafe Numeric Operations (unsafe-weak-hash-iterate-key hash pos)  →  any/c   hash : (and/c hash? hash-weak?)   pos : any/c (unsafe-weak-hash-iterate-key   hash             pos             bad-index-v)   →   any/c   hash : (and/c hash? hash-weak?)   pos : any/c   bad-index-v : any/c (unsafe-weak-hash-iterate-value hash pos)  →  any/c   hash : (and/c hash? hash-weak?)   pos : any/c (unsafe-weak-hash-iterate-value   hash             pos             bad-index-v)   →   any/c   hash : (and/c hash? hash-weak?)   pos : any/c   bad-index-v : any/c (unsafe-weak-hash-iterate-key+value   hash             pos)   →   any/c   any/c   hash : (and/c hash? hash-weak?)   pos : any/c (unsafe-weak-hash-iterate-key+value   hash             pos             bad-index-v)   →   any/c   any/c   hash : (and/c hash? hash-weak?)   pos : any/c   bad-index-v : any/c (unsafe-weak-hash-iterate-pair hash pos)  →  pair?   hash : (and/c hash? hash-weak?)   pos : any/c (unsafe-weak-hash-iterate-pair   hash             pos             bad-index-v)   →   pair?   hash : (and/c hash? hash-weak?)   pos : any/c   bad-index-v : any/c (unsafe-ephemeron-hash-iterate-first hash)  →  (or/c #f any/c)   hash : (and/c hash? hash-ephemeron?) (unsafe-ephemeron-hash-iterate-next   hash             pos)   →   (or/c #f any/c)   hash : (and/c hash? hash-ephemeron?)   pos : any/c (unsafe-ephemeron-hash-iterate-key   hash             pos)   →   any/c   hash : (and/c hash? hash-ephemeron?)   pos : any/c (unsafe-ephemeron-hash-iterate-key   hash             pos             bad-index-v)   →   any/c
### 17.1 Unsafe Numeric Operations   hash : (and/c hash? hash-ephemeron?)   pos : any/c   bad-index-v : any/c (unsafe-ephemeron-hash-iterate-value   hash             pos)   →   any/c   hash : (and/c hash? hash-ephemeron?)   pos : any/c (unsafe-ephemeron-hash-iterate-value   hash             pos             bad-index-v)   →   any/c   hash : (and/c hash? hash-ephemeron?)   pos : any/c   bad-index-v : any/c (unsafe-ephemeron-hash-iterate-key+value   hash             pos)   →   any/c   any/c   hash : (and/c hash? hash-ephemeron?)   pos : any/c (unsafe-ephemeron-hash-iterate-key+value   hash       pos       bad-index-v)     →   any/c   any/c   hash : (and/c hash? hash-ephemeron?)   pos : any/c   bad-index-v : any/c (unsafe-ephemeron-hash-iterate-pair   hash             pos)   →   pair?   hash : (and/c hash? hash-ephemeron?)   pos : any/c (unsafe-ephemeron-hash-iterate-pair   hash             pos             bad-index-v)   →   pair?   hash : (and/c hash? hash-ephemeron?)   pos : any/c   bad-index-v : any/c``` Unsafe versions of [hash-iterate-key](hashtables.html#%28def._%28%28quote._~23~25kernel%29._hash-iterate-key%29%29) and similar procedures. These operations support [chaperones](chaperones.html#%28tech._chaperone%29) and [impersonators](chaperones.html#%28tech._impersonator%29).
### 17.1 Unsafe Numeric Operations Each unsafe ...-first and ...-next procedure may return, instead of a number index, an internal representation of a view into the hash structure, enabling faster iteration. The result of these ...-first and ...-next functions should be given as pos to the corresponding unsafe accessor functions. If the pos provided to an accessor function for a mutable hash was formerly a [valid hash index](hashtables.html#%28tech._valid._hash._index%29) but is no longer a [valid hash index](hashtables.html#%28tech._valid._hash._index%29) for hash, and if bad-index-v is not provided, then the [exn:fail:contract](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3acontract%29%29) exception is raised. No behavior is specified for a pos that was never a [valid hash index](hashtables.html#%28tech._valid._hash._index%29) for hash. Note that bad-index-v argument is technically not useful for the unsafe-immutable-hash-iterate- functions, since an index cannot become invalid for an immutable hash. Added in version 6.4.0.6 of package base. Changed in version 7.0.0.10: Added the optional bad-index-v argument. Changed in version 8.0.0.10: Added ephemeron variants. > ``` (unsafe-make-srcloc   source             line             column             position             span)   →   srcloc?   source : any/c   line : (or/c exact-positive-integer? #f)   column : (or/c exact-nonnegative-integer? #f)   position : (or/c exact-positive-integer? #f)   span : (or/c exact-nonnegative-integer? #f)
### 17.1 Unsafe Numeric Operations ``` Unsafe version of srcloc. Added in version 7.2.0.10 of package base. ### 17.4 Unsafe Extflonum Operations > ``` (unsafe-extfl+ a b)  →  extflonum?   a : extflonum?   b : extflonum? (unsafe-extfl- a b)  →  extflonum?   a : extflonum?   b : extflonum? (unsafe-extfl* a b)  →  extflonum?   a : extflonum?   b : extflonum? (unsafe-extfl/ a b)  →  extflonum?   a : extflonum?   b : extflonum? (unsafe-extflabs a)  →  extflonum?   a : extflonum?``` Unchecked versions of [extfl+](extflonums.html#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extfl%2B%29%29), [extfl-](extflonums.html#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extfl-%29%29), [extfl*](extflonums.html#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extfl%2A%29%29), [extfl/](extflonums.html#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extfl%2F%29%29), and [extflabs](extflonums.html#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extflabs%29%29). > ``` (unsafe-extfl= a b) → boolean?   a : extflonum?   b : extflonum? ([unsafe-extfl (unsafe-extfl> a b)  →  boolean?   a : extflonum?   b : extflonum? ([unsafe-extfl (unsafe-extfl>= a b)  →  boolean?   a : extflonum?   b : extflonum? (unsafe-extflmin a b)  →  extflonum?   a : extflonum?   b : extflonum? (unsafe-extflmax a b)  →  extflonum?   a : extflonum?   b : extflonum? ``` Unchecked versions of extfl=, extfl<, extfl>, extfl<=, extfl>=, extflmin, and extflmax. > ``` (unsafe-extflround a) → extflonum?   a : extflonum? (unsafe-extflfloor a)  →  extflonum?   a : extflonum?
### 17.1 Unsafe Numeric Operations (unsafe-extflceiling a)  →  extflonum?   a : extflonum? (unsafe-extfltruncate a)  →  extflonum?   a : extflonum?``` Unchecked (potentially) versions of [extflround](extflonums.html#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extflround%29%29), [extflfloor](extflonums.html#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extflfloor%29%29), [extflceiling](extflonums.html#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extflceiling%29%29), and [extfltruncate](extflonums.html#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extfltruncate%29%29). Currently, these bindings are simply aliases for the corresponding safe bindings. > ``` (unsafe-extflsin a)  →  extflonum?   a : extflonum? (unsafe-extflcos a)  →  extflonum?   a : extflonum? (unsafe-extfltan a)  →  extflonum?   a : extflonum? (unsafe-extflasin a)  →  extflonum?   a : extflonum? (unsafe-extflacos a)  →  extflonum?   a : extflonum? (unsafe-extflatan a)  →  extflonum?   a : extflonum? (unsafe-extfllog a)  →  extflonum?   a : extflonum? (unsafe-extflexp a)  →  extflonum?   a : extflonum? (unsafe-extflsqrt a)  →  extflonum?   a : extflonum? (unsafe-extflexpt a b)  →  extflonum?   a : extflonum?   b : extflonum?
### 17.1 Unsafe Numeric Operations ``` Unchecked (potentially) versions of extflsin, extflcos, extfltan, extflasin, extflacos, extflatan, extfllog, extflexp, extflsqrt, and extflexpt. Currently, some of these bindings are simply aliases for the corresponding safe bindings. > ``` (unsafe-fx → extfl a)  →  extflonum?   a : fixnum? (unsafe-extfl → fx a)  →  fixnum?   a : extflonum?``` Unchecked (potentially) versions of [fx->extfl](extflonums.html#%28def._%28%28lib._racket%2Fextflonum..rkt%29._fx-~3eextfl%29%29) and [extfl->fx](extflonums.html#%28def._%28%28lib._racket%2Fextflonum..rkt%29._extfl-~3efx%29%29). Changed in version 7.7.0.8 of package base: Changed [unsafe-fl->fx](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-fl-~3efx%29%29) to truncate. > ``` (parameter) → (-> unsafe-extflvector-ref v k) ``` Unchecked versions of extflvector-length, extflvector-ref, and extflvector-set!. A extflvector’s size can never be larger than a fixnum (so even extflvector-length always returns a fixnum).
### 17.5 Unsafe Impersonators and Chaperones > ``` (unsafe-impersonate-procedure proc     replacement-proc       prop       prop-val ...       ...)     →  (and/c procedure? impersonator?)   proc : procedure?   replacement-proc : procedure?   prop : impersonator-property?   prop-val : any``` Like [impersonate-procedure](chaperones.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._impersonate-procedure%29%29), but assumes that replacement-proc calls proc itself. When the result of [unsafe-impersonate-procedure](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-impersonate-procedure%29%29) is applied to arguments, the arguments are passed on to replacement-proc directly, ignoring proc. At the same time, [impersonator-of?](chaperones.html#%28def._%28%28quote._~23~25kernel%29._impersonator-of~3f%29%29) reports #t when given the result of [unsafe-impersonate-procedure](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-impersonate-procedure%29%29) and proc.
### 17.5 Unsafe Impersonators and Chaperones If proc is itself an impersonator that is derived from [impersonate-procedure*](chaperones.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._impersonate-procedure%2A%29%29) or [chaperone-procedure*](chaperones.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._chaperone-procedure%2A%29%29), beware that replacement-proc will not be able to call it correctly. Specifically, the impersonator produced by [unsafe-impersonate-procedure](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-impersonate-procedure%29%29) will not get passed to a wrapper procedure that was supplied to [impersonate-procedure*](chaperones.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._impersonate-procedure%2A%29%29) or [chaperone-procedure*](chaperones.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._chaperone-procedure%2A%29%29) to generate proc. Finally, unlike [impersonate-procedure](chaperones.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._impersonate-procedure%29%29), [unsafe-impersonate-procedure](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-impersonate-procedure%29%29) does not specially handle [impersonator-prop:application-mark](chaperones.html#%28def._%28%28quote._~23~25kernel%29._impersonator-prop~3aapplication-mark%29%29) as a prop.
### 17.5 Unsafe Impersonators and Chaperones The unsafety of [unsafe-impersonate-procedure](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-impersonate-procedure%29%29) is limited to the above differences from [impersonate-procedure](chaperones.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._impersonate-procedure%29%29). The contracts on the arguments of [unsafe-impersonate-procedure](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-impersonate-procedure%29%29) are checked when the arguments are supplied. As an example, assuming that f accepts a single argument and is not derived from [impersonate-procedure*](chaperones.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._impersonate-procedure%2A%29%29) or [chaperone-procedure*](chaperones.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._chaperone-procedure%2A%29%29), then > ```racket > ( λ ( f ) > ( unsafe-impersonate-procedure > f > ( λ ( x ) > ( if ( number? x ) > ( error ' no-numbers! ) > ( f x ) ) ) ) ) > ``` is equivalent to > ```racket > ( λ ( f ) > ( impersonate-procedure > f > ( λ ( x ) > ( if ( number? x ) > ( error ' no-numbers! ) > x ) ) ) ) > ```
### 17.5 Unsafe Impersonators and Chaperones Similarly, with the same assumptions about f, the following two procedures wrap-f1 and wrap-f2 are almost equivalent; they differ only in the error message produced when their arguments are functions that return multiple values (and that they update different global variables). The version using [unsafe-impersonate-procedure](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-impersonate-procedure%29%29) will signal an error in the [let](let.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._let%29%29) expression about multiple return values, whereas the one using [impersonate-procedure](chaperones.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._impersonate-procedure%29%29) signals an error from [impersonate-procedure](chaperones.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._impersonate-procedure%29%29) about multiple return values. > ```racket > ( define log1-args ' ( ) ) > ( define log1-results ' ( ) ) > ( define wrap-f1 > ( λ ( f ) > ( impersonate-procedure > f > ( λ ( arg ) > ( set! log1-args ( cons arg log1-args ) ) > ( values ( λ ( res ) > ( set! log1-results ( cons res log1-results ) ) > res ) > arg ) ) ) ) ) > ( define log2-args ' ( ) ) > ( define log2-results ' ( ) ) > ( define wrap-f2 > ( λ ( f ) > ( unsafe-impersonate-procedure > f > ( λ ( arg ) > ( set! log2-args ( cons arg log2-args ) ) > ( let ( [ res ( f arg ) ] ) > ( set! log2-results ( cons res log2-results ) ) > res ) ) ) ) ) > ``` Added in version 6.4.0.4 of package base. > ```
### 17.5 Unsafe Impersonators and Chaperones (unsafe-chaperone-procedure proc     wrapper-proc       prop       prop-val ...       ...)     →  (and/c procedure? chaperone?)   proc : procedure?   wrapper-proc : procedure?   prop : impersonator-property?   prop-val : any ``` Like unsafe-impersonate-procedure, but creates a chaperone. Since wrapper-proc will be called in lieu of proc, wrapper-proc is assumed to return a chaperone of the value that proc would return. Added in version 6.4.0.4 of package base. > ``` (unsafe-impersonate-vector vec     replacement-vec       prop       prop-val ...       ...)     →  (and/c vector? impersonator?)   vec : vector?   replacement-vec : (and/c vector? (not/c impersonator?))   prop : impersonator-property?   prop-val : any/c``` Like [impersonate-vector](chaperones.html#%28def._%28%28quote._~23~25kernel%29._impersonate-vector%29%29), but instead of going through interposition procedures, all accesses to the impersonator are dispatched to replacement-vec. The result of [unsafe-impersonate-vector](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-impersonate-vector%29%29) is an impersonator of vec. Added in version 6.9.0.2 of package base. > ``` (unsafe-chaperone-vector vec     replacement-vec       prop       prop-val ...       ...)     →  (and/c vector? chaperone?)   vec : vector?   replacement-vec : (and/c vector? (not/c impersonator?))   prop : impersonator-property?   prop-val : any/c ``` Like unsafe-impersonate-vector, but the result of unsafe-chaperone-vector is a chaperone of vec.
### 17.5 Unsafe Impersonators and Chaperones Added in version 6.9.0.2 of package base.
### 17.6 Unsafe Assertions > ``` (unsafe-assert-unreachable)  →  none/c``` Like [assert-unreachable](unreachable.html#%28def._%28%28quote._~23~25kernel%29._assert-unreachable%29%29), but the contract of [unsafe-assert-unreachable](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-assert-unreachable%29%29) is never satisfied, and the “unsafe” implication is that anything at all can happen if a call to [unsafe-assert-unreachable](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-assert-unreachable%29%29) is reached. The compiler may take advantage of its liberty to pick convenient or efficient behavior in place of a call to [unsafe-assert-unreachable](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-assert-unreachable%29%29). For example, the expression > ```racket > ( lambda ( x ) > ( if ( pair? x ) > ( car x ) > ( unsafe-assert-unreachable ) ) ) > ``` may be compiled to code equivalent to > ([lambda](lambda.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._lambda%29%29) (x) ([unsafe-car](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-car%29%29) x)) because choosing to make ([unsafe-assert-unreachable](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-assert-unreachable%29%29)) behave the same as ([unsafe-car](#%28def._%28%28lib._racket%2Funsafe%2Fops..rkt%29._unsafe-car%29%29) x) makes both branches of the [if](if.html#%28form._%28%28quote._~23~25kernel%29._if%29%29) the same, and then [pair?](pairs.html#%28def._%28%28quote._~23~25kernel%29._pair~3f%29%29) test can be eliminated.
### 17.6 Unsafe Assertions Added in version 8.0.0.11 of package base.
### 17.7 Unsafe Undefined | | | |:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:| |  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/unsafe/undefined](#%28mod-path._racket%2Funsafe%2Fundefined%29)) |  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/unsafe/undefined](#%28mod-path._racket%2Funsafe%2Fundefined%29) library, not [racket/base](index.html) or [racket](index.html).
### 17.7 Unsafe Undefined The constant [unsafe-undefined](#%28def._%28%28lib._racket%2Funsafe%2Fundefined..rkt%29._unsafe-undefined%29%29) is used internally as a placeholder value. For example, it is used by [letrec](let.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._letrec%29%29) as a value for a variable that has not yet been assigned a value. Unlike the undefined value exported by [racket/undefined](undefined.html), however, the [unsafe-undefined](#%28def._%28%28lib._racket%2Funsafe%2Fundefined..rkt%29._unsafe-undefined%29%29) value should not leak as the result of a safe expression, and it should not be passed as an optional argument to a procedure (because it may count as “no value provided”). Expression results that potentially produce [unsafe-undefined](#%28def._%28%28lib._racket%2Funsafe%2Fundefined..rkt%29._unsafe-undefined%29%29) can be guarded by [check-not-unsafe-undefined](#%28def._%28%28lib._racket%2Funsafe%2Fundefined..rkt%29._check-not-unsafe-undefined%29%29), so that an exception can be raised instead of producing an undefined value. The [unsafe-undefined](#%28def._%28%28lib._racket%2Funsafe%2Fundefined..rkt%29._unsafe-undefined%29%29) value is always [eq?](Equality.html#%28def._%28%28quote._~23~25kernel%29._eq~3f%29%29) to itself. Added in version 6.0.1.2 of package base. Changed in version 6.90.0.29: Procedures with optional arguments sometimes use the [unsafe-undefined](#%28def._%28%28lib._racket%2Funsafe%2Fundefined..rkt%29._unsafe-undefined%29%29) value internally to mean “no argument supplied.”
### 17.7 Unsafe Undefined > <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote> <p>value</p> <p>[unsafe-undefined](#%28def._%28%28lib._racket%2Funsafe%2Fundefined..rkt%29._unsafe-undefined%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> The unsafe “undefined” constant. See above for important constraints on the use of [unsafe-undefined](#%28def._%28%28lib._racket%2Funsafe%2Fundefined..rkt%29._unsafe-undefined%29%29). > ``` (parameter) → ``` (parameter) →``` The same as [check-not-unsafe-undefined](#%28def._%28%28lib._racket%2Funsafe%2Fundefined..rkt%29._check-not-unsafe-undefined%29%29), except that the error message (if any) is along the lines of “sym: undefined; assignment before initialization.” > ``` (chaperone-struct-unsafe-undefined v)  →  any/c   v : any/c ``` (find-config-dir) → (-> such as current-load-relative-directory)``` Produces a list of paths, which is normally used to initialize [current-library-collection-paths](#%28def._%28%28quote._~23~25kernel%29._current-library-collection-paths%29%29), as follows:
### 17.7 Unsafe Undefined - The path produced by ([build-path](Manipulating_Paths.html#%28def._%28%28quote._~23~25kernel%29._build-path%29%29) ([find-system-path](Filesystem.html#%28def._%28%28quote._~23~25kernel%29._find-system-path%29%29) 'addon-dir) name "collects") is the first element of the default collection path list, unless the value of the [use-user-specific-search-paths](#%28def._%28%28quote._~23~25kernel%29._use-user-specific-search-paths%29%29) parameter is #f. - Extra directories provided in pre-extras are included next to the default collection path list, converted to complete paths relative to the executable. - If the directory specified by ([find-system-path](Filesystem.html#%28def._%28%28quote._~23~25kernel%29._find-system-path%29%29) 'collects-dir) is absolute, or if it is relative (to the executable) and it exists, then it is added to the end of the default collection path list. - Extra directories provided in post-extras are included last in the default collection path list, converted to complete paths relative to the executable. - If config has a value for 'collects-search-dirs, then it is used in place of the default collection path list (as constructed by the preceding three bullets), and the default is spliced in place of any #f within the 'collects-search-dirs list. If config does not have a 'collects-search-dirs value, then the default collection path list is used.
### 17.7 Unsafe Undefined - If the PLTCOLLECTS environment variable is defined, it is combined with the default list using [path-list-string->path-list](Filesystem.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._path-list-string-~3epath-list%29%29), as long as the value of [use-user-specific-search-paths](#%28def._%28%28quote._~23~25kernel%29._use-user-specific-search-paths%29%29) is true. If it is not defined or if the value [use-user-specific-search-paths](#%28def._%28%28quote._~23~25kernel%29._use-user-specific-search-paths%29%29) is #f, the collection path list as constructed by the preceding four bullets is used directly. Note that on Unix and Mac OS, paths are separated by :, and on Windows by ;. Also, [path-list-string->path-list](Filesystem.html#%28def._%28%28lib._racket%2Fprivate%2Fmisc..rkt%29._path-list-string-~3epath-list%29%29) splices the default paths at an empty path, for example, with many Unix shells you can set PLTCOLLECTS to ":‘pwd‘", "‘pwd‘:", or "‘pwd‘" to specify search the current directory after, before, or instead of the default paths, respectively. Changed in version 8.4.0.3 of package base: Added the config and name arguments. > ``` (find-library-collection-links [config] name)   →  (listof (or/c #f (and/c path? complete-path?)))   config : hash? = (read-installation-configuration-table)   name : (get-installation-name config)
### 17.7 Unsafe Undefined ``` (find-config-dir) → (-> regexp-match? #rx"[.]rkt$" file)``` Returns the path to the file indicated by file in the collection specified by the collections, where the second collection (if any) names a sub-collection, and so on. The search uses the values of [current-library-collection-links](#%28def._%28%28quote._~23~25kernel%29._current-library-collection-links%29%29) and [current-library-collection-paths](#%28def._%28%28quote._~23~25kernel%29._current-library-collection-paths%29%29). > > > See also [collection-search](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=raco&rel=collection-search.html%23%2528def._%2528%2528lib._setup%252Fcollection-search..rkt%2529._collection-search%2529%2529&version=8.18.0.13) in [setup/collection-search](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=raco&rel=collection-search.html&version=8.18.0.13). If file is not found, but file ends in ".rkt" and a file with the suffix ".ss" exists, then the directory of the ".ss" file is used. If file is not found and the ".rkt"/".ss" conversion does not apply, but a directory corresponding to the collections is found, then a path using the first such directory is returned. If check-compiled? is true, then the search also depends on [use-compiled-file-paths](eval.html#%28def._%28%28quote._~23~25kernel%29._use-compiled-file-paths%29%29) and [current-compiled-file-roots](eval.html#%28def._%28%28quote._~23~25kernel%29._current-compiled-file-roots%29%29); if file is not found, then a compiled form of file with the suffix ".zo" is checked in the same way as the default [compiled-load handler](eval.html#%28tech._compiled._load._handler%29). If a compiled file is found, the result from [collection-file-path](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._collection-file-path%29%29) reports the location that file itself would occupy (if it existed) for the found compiled file. Finally, if the collection is not found, and if fail-proc is provided, then fail-proc is applied to an error message (that does not start "collection-file-path:" or otherwise claim a source), and its result is the result of [collection-file-path](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._collection-file-path%29%29). If fail-proc is not provided and the collection is not found, then the [exn:fail:filesystem](exns.html#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._exn~3afail~3afilesystem%29%29) exception is raised. Examples: > ```racket > > ( collection-file-path "main.rkt" "racket" "base" ) > #<path:path/to/collects/racket/base/main.rkt> > > ( collection-file-path "sandwich.rkt" "bologna" ) > collection-file-path: collection not found > collection: "bologna" > in collection directories: > /Users/robby/snapshot/racket/racket/collects/ > ... [260 additional linked and package directories] > ``` Changed in version 6.0.1.12 of package base: Added the check-compiled? argument. > ``` (collection-path collection ...+) → path?   collection : path-string? (collection-path   collection             ...+             #:fail fail-proc)   →   any   collection : path-string?   fail-proc : (string? . → . any) ```
### 17.7 Unsafe Undefined (current-library-collection-paths) → (-> listof (and/c path? complete-path?)) (current-library-collection-paths paths) → void? paths : (-> listof (and/c path? complete-path?))``` Parameter that determines a list of complete directory paths for finding libraries (as referenced in [require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29), for example) through the default [module name resolver](Module_Names_and_Loading.html#%28tech._module._name._resolver%29) and for finding paths through [collection-path](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._collection-path%29%29) and [collection-file-path](#%28def._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._collection-file-path%29%29). See [Collection Search Configuration](#%28part._collects-search%29) for more information. > ``` (current-library-collection-links) → (-> listof (or/c #f (and/c path? complete-path?) (hash/c (or/c (and/c symbol? module-path?) #f) (listof (and/c path? complete-path?))))) (current-library-collection-links paths) → void? paths : (-> listof (or/c #f (and/c path? complete-path?) (hash/c (or/c (and/c symbol? module-path?) #f) (listof (and/c path? complete-path?)))))
### 17.7 Unsafe Undefined ``` (use-user-specific-search-paths) → (-> use-user-specific-search-paths on?)``` Parameter that determines whether user-specific paths, which are in the directory produced by ([find-system-path](Filesystem.html#%28def._%28%28quote._~23~25kernel%29._find-system-path%29%29) 'addon-dir), are included in search paths for collections and other files. For example, the initial value of [find-library-collection-paths](#%28def._%28%28quote._~23~25kernel%29._find-library-collection-paths%29%29) omits the user-specific collection directory when this parameter’s value is #f. If -U or --no-user-path argument to racket, then [use-user-specific-search-paths](#%28def._%28%28quote._~23~25kernel%29._use-user-specific-search-paths%29%29) is initialized to #f. > ``` (use-collection-link-paths) → (-> use-collection-link-paths on?) ``` (read-installation-configuration-table) → (-> and/c hash? immutable?)``` Returns the content of the installation’s "config.rktd" file (see [Installation Configuration and Search Paths](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=raco&rel=config-file.html&version=8.18.0.13)) as long as that content is a [hash table](hashtables.html#%28tech._hash._table%29), and otherwise returns an empty hash table. Added in version 8.4.0.3 of package base. ------------------------------------------------------------------------
# 18.3 Interactive Help
### 18.3 Interactive Help | | | |:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:| |  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/help]()) |  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/help]() and [racket/init](running-sa.html#%28mod-path._racket%2Finit%29) libraries, which means that they are available when the Racket executable is started with no command-line arguments. They are not provided by [racket/base](index.html) or [racket](index.html). > <table data-cellpadding="0" data-cellspacing="0"><colgroup><col style="width: 100%" /></colgroup><tbody><tr><td><blockquote> <p>syntax</p>
# 18.3 Interactive Help <p>[help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29)</p></blockquote></td></tr><tr><td>([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) string ...)</td></tr><tr><td>([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) id)</td></tr><tr><td>([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) id #:from module-path)</td></tr><tr><td>([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) #:search datum ...)</td></tr></tbody></table> For general help, see the [main documentation page](../index.html). The [help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) form searches the documentation and opens a web browser (using the user’s selected browser) to display the results. > > > See [net/sendurl](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=net&rel=sendurl.html&version=8.18.0.13) for information on how the user’s browser is launched to display help information. A simple [help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) or ([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29)) form opens the main documentation page. The ([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) string [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29)) form—using literal strings, as opposed to expressions that produce strings—performs a string-matching search. For example, > ([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) "web browser" "firefox")
# 18.3 Interactive Help searches the documentation index for references that include the phrase “web browser” or “firefox.” A ([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) id) form looks for documentation specific to the current binding of id. For example, > ```racket > ( require net/url ) > ( help url->string ) > ``` opens a web browser to show the documentation for [url->string](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=net&rel=url.html%23%2528def._%2528%2528lib._net%252Furl..rkt%2529._url-%7E3estring%2529%2529&version=8.18.0.13) from the [net/url](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=net&rel=url.html&version=8.18.0.13) library. For the purposes of [help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29), a [for-label](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for-label%29%29) require introduces a binding without actually executing the [net/url](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=net&rel=url.html&version=8.18.0.13) library—for cases when you want to check documentation, but cannot or do not want to run the providing module. > ```racket > ( require racket/gui ) ; does not work in racket > ( require ( for-label racket/gui ) ) ; ok in racket > ( help frame% ) > ``` If id has no for-label and normal binding, then [help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) lists all libraries that are known to export a binding for id.
# 18.3 Interactive Help The ([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) id #:from module-path) variant is similar to ([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) id), but using only the exports of module-path. (The module-path module is required [for-label](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._for-label%29%29) in a temporary namespace.) > ([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) [frame%](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?doc=gui&rel=frame_.html&version=8.18.0.13) #:from racket/gui) ; equivalent to the above The ([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) #:search datum [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29)) form is similar to ([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) string [...](stx-patterns.html#%28form._%28%28lib._racket%2Fprivate%2Fstxcase-scheme..rkt%29._......%29%29)), where any non-string form of datum is converted to a string using [display](Writing.html#%28def._%28%28quote._~23~25kernel%29._display%29%29). No datum is evaluated as an expression. For example, > ([help](#%28form._%28%28lib._racket%2Fhelp..rkt%29._help%29%29) #:search "web browser" firefox) also searches the documentation index for references that include the phrase “web browser” or “firefox.” ------------------------------------------------------------------------
# 18.4 Interaction Configuration
### 18.4 Interaction Configuration | | | |:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:| |  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/interaction-info]()) |  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/interaction-info]() library, not [racket/base](index.html) or [racket](index.html). The [racket/interaction-info]() library provides a way to register a langauge’s configuration for a [read](Reading.html#%28def._%28%28quote._~23~25kernel%29._read%29%29)-[eval](eval.html#%28def._%28%28quote._~23~25kernel%29._eval%29%29)-[print](Writing.html#%28def._%28%28quote._~23~25kernel%29._print%29%29) loop and editor. > ``` (current-interaction-info) → (-> or/c #f (vector/c module-path? symbol? any/c)) (current-interaction-info info) → void? info : (-> or/c #f (vector/c module-path? symbol? any/c))
# 18.4 Interaction Configuration ``` (parameter) → (-> e.g., in a tool that uses racket/enter)``` Procedure variant of [enter!](#%28form._%28%28lib._racket%2Fenter..rkt%29._enter%21%29%29), where verbosity is passed along to [dynamic-rerequire](#%28def._%28%28lib._racket%2Frerequire..rkt%29._dynamic-rerequire%29%29) and re-require-enter? determines whether [dynamic-enter!](#%28def._%28%28lib._racket%2Fenter..rkt%29._dynamic-enter%21%29%29) requires racket/enter in a newly entered namespace. Added in version 6.0.0.1 of package base. #### 18.5.2 Loading and Reloading Modules | | | |:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------:| |  ([require](require.html#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._require%29%29) [racket/rerequire](#%28mod-path._racket%2Frerequire%29)) |  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/rerequire](#%28mod-path._racket%2Frerequire%29) library, not [racket/base](index.html) or [racket](index.html). > ``` (dynamic-rerequire module-path    [ #:verbosity verbosity)   →   (listof path?)   module-path : module-path?   verbosity : (or/c 'all 'reload 'none) = 'reload ```
# 18.4 Interaction Configuration (current-error-port) → (-> string? . → . any)``` A [parameter](eval-model.html#%28tech._parameter%29) that determines the way that trace output is displayed. The string given to proc is a trace; it does not end with a newline, but it may contain internal newlines. Each call or result is converted into a string using [pretty-print](pretty-print.html#%28def._%28%28lib._racket%2Fpretty..rkt%29._pretty-print%29%29). The parameter’s default value prints the given string followed by a newline to ([current-output-port](port-ops.html#%28def._%28%28quote._~23~25kernel%29._current-output-port%29%29)). > ``` (parameter) →
# 18.4 Interaction Configuration ``` (current-trace-print-args) → (-> symbol? list? (listof keyword?) list? number? void?) (current-trace-print-args trace-print-args) → void? trace-print-args : (-> symbol? list? (listof keyword?) list? number? void?)``` The value of this parameter is invoked to print out the arguments of a traced call. It receives the name of the function, the function’s ordinary arguments, its keywords, the values of the keywords, and a number indicating the depth of the call. Modifying this and [current-trace-print-results](#%28def._%28%28lib._racket%2Ftrace..rkt%29._current-trace-print-results%29%29) is useful to to get more readable or additional output when tracing syntax transformers. For example, we can use [debug-scopes](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?tag=%28mod-path._.%27debug-scopes.%27%29&version=8.18.0.13) to add scopes information to the trace, (see [debug-scopes](https://plt.cs.northwestern.edu/new-snapshots/new-snapshots/doc/local-redirect/index.html?tag=%28mod-path._.%27debug-scopes.%27%29&version=8.18.0.13) for an example), or remove source location information to just display the shape of the syntax object In this example, we update the printers [current-trace-print-args](#%28def._%28%28lib._racket%2Ftrace..rkt%29._current-trace-print-args%29%29) and [current-trace-print-results](#%28def._%28%28lib._racket%2Ftrace..rkt%29._current-trace-print-results%29%29) by storing the current printers (ctpa and ctpr) to cast syntax objects to datum using [syntax->datum](stxops.html#%28def._%28%28quote._~23~25kernel%29._syntax-~3edatum%29%29) and then pass the transformed arguments and results to the previous printer. When tracing, syntax arguments will be displayed without source location information, shortening the output. Examples: > ```racket > > ( require ( for-syntax racket/trace ) ) > > ( begin-for-syntax ( current-trace-print-args ( let ( [ ctpa ( current-trace-print-args ) ] ) ( lambda ( s l kw l2 n ) ( ctpa s ( map syntax->datum l ) kw l2 n ) ) ) ) ( current-trace-print-results ( let ( [ ctpr ( current-trace-print-results ) ] ) ( lambda ( s r n ) ( ctpr s ( map syntax->datum r ) n ) ) ) ) ) > > ( trace-define-syntax fact ( syntax-rules ( ) [ ( _ x ) 120 ] ) ) > > ( fact 5 ) > >(fact '(fact 5)) <120> 120 > ``` We must take care when modifying these parameters, especially when the transformation makes assumptions about or changes the type of the argument/result of the traced identifier. This modification of [current-trace-print-args](#%28def._%28%28lib._racket%2Ftrace..rkt%29._current-trace-print-args%29%29) and [current-trace-print-results](#%28def._%28%28lib._racket%2Ftrace..rkt%29._current-trace-print-results%29%29) is an imperative update, and will affect all traced identifiers. This example assumes all arguments and results to all traced functions will be syntax objects, which is the case only if you are only tracing syntax transformers. If used as-is, the above code could result in type errors when tracing both functions and syntax transformers. It would be better to use [syntax->datum](stxops.html#%28def._%28%28quote._~23~25kernel%29._syntax-~3edatum%29%29) only when the argument or result is actually a syntax object, for example, by defining maybe-syntax->datum as follows. Examples: > ```racket > > ( require ( for-syntax racket/trace ) ) > > ( begin-for-syntax ( define ( maybe-syntax->datum syn? ) ( if ( syntax? syn? ) ( syntax->datum syn? ) syn? ) ) ( current-trace-print-args ( let ( [ ctpa ( current-trace-print-args ) ] ) ( lambda ( s l kw l2 n ) ( ctpa s ( map maybe-syntax->datum l ) kw l2 n ) ) ) ) ( current-trace-print-results ( let ( [ ctpr ( current-trace-print-results ) ] ) ( lambda ( s l n ) ( ctpr s ( map maybe-syntax->datum l ) n ) ) ) ) ( trace-define ( precompute-fact syn n ) ( datum->syntax syn ( apply * ( build-list n add1 ) ) ) ) ) > > ( trace-define ( run-time-fact n ) ( apply * ( build-list n add1 ) ) ) > > ( require ( for-syntax syntax/parse ) ) > > ( trace-define-syntax ( fact syn ) ( syntax-parse syn [ ( _ x:nat ) ( precompute-fact syn ( syntax->datum #' x ) ) ] [ ( _ x ) #' ( run-time-fact x ) ] ) ) > > ( fact 5 ) > >(fact '(fact 5)) >(precompute-fact '(fact 5) 5) <120> 120 > > ( fact ( + 2 3 ) ) > >(fact '(fact (+ 2 3))) <'(run-time-fact (+ 2 3))>(run-time-fact 5) <120> 120 > ``` > ``` (current-trace-print-results) → (-> symbol? list? number? any) (current-trace-print-results trace-print-results) → void? trace-print-results : (-> symbol? list? number? any) ```
# 18.4 Interaction Configuration (current-prefix-in) → (-> current-prefix-in prefix) (current-prefix-in prefix) → void? prefix : (-> current-prefix-in prefix)``` This string is used by the default value of [current-trace-print-args](#%28def._%28%28lib._racket%2Ftrace..rkt%29._current-trace-print-args%29%29) indicating that the current line is showing the a call to a traced function. It defaults to ">". > ``` (current-prefix-out) → (-> current-prefix-out prefix) (current-prefix-out prefix) → void? prefix : (-> current-prefix-out prefix) ``` (E) →``` (struct) → (-> if.html#%28form._%28%28lib._racket%2Fprivate%2Fletstx-scheme..rkt%29._~3d~3e%29%29) ``` ------------------------------------------------------------------------