Previous: , Up: Utilities   [Contents][Index]


4.6.3 Miscellaneous

(use-modules (sly utils))

Miscellaneous helpful procedures.

Scheme Syntax: define-guardian name reaper

Define a new guardian called name and call reaper when an object within the guardian is GC’d. Reaping is ensured to happen from the same thread that is running the game loop.

Scheme Procedure: memoize proc

Return a memoizing version of proc.

Scheme Syntax: forever body

Evaluate body in an unbounded loop. Useful in coroutines that have no end.

Scheme Syntax: trampoline proc-name

Create a new procedure that applies the procedure bound to proc-name with all given arguments.

Scheme Syntax: chain* args (proc …) . rest

Handy macro for flattening nested procedure calls where the output of an inner call is the last argument to the outer call.

(chain* (list '(1 2) '(3 4))
  (map +)
  (fold + 0)) ;; => 10
Scheme Syntax: chain arg (proc …) . rest

Like chain* but for a single argument.

(chain '(1 2 3 4)
  (map 1+)
  (fold + 0)) ;; => 14
Scheme Procedure: list->vlist* lst

Convert lst and all sub-lists within to vlists.

Scheme Procedure: list->vlist* lst index […]

Return the element at index index … in the nested vlist structure vlist.