On this page:
hole
hole?
deref
reset
update
reset-thing
hole-bind
hole-guard

3.13 Holes🔗ℹ

Holes are a simple mutable data structure based on Racket boxes, with an API inspired by Clojure’s atoms. Their purpose is to provide an in-memory data store that is treated as a first-class value, which thus can be bound to a value or passed to functions. They can also be useful for providing a source of shared program state.

procedure

(hole v)  hole?

  v : any?
Creates a hole containing v.

procedure

(hole? v)  boolean?

  v : any?
Returns True if v is a hole.

procedure

(deref hol)  any?

  hol : hole?
Returns the current value contained within hol.

procedure

(reset hol new-val)  hole?

  hol : hole?
  new-val : any?
Resets the current value of hol to new-val, returning the hole.

procedure

(update hol fn args ...)  hole?

  hol : hole?
  fn : fn?
  args : any?
Resets the current value of hol to the result if applying fn to the current value of hol, followed by args, ie. (apply f curr-val args).

syntax

(reset-thing [hol hole?] (field value) ...)

Resets the fields of a Thing contained in hol to the values provided, and returns the hole.

procedure

(hole-bind hol fn)  any?

  hol : hole?
  fn : fn?
Applies fn to the value contained by hol. The monadic bind (>>=) operator for holes.

procedure

(hole-guard test)  any?

  test : boolean?
The monadic guard operator for holes. Primarily of use for the hole-do DSL.