2020-11-29 00:28:46 +01:00
|
|
|
#lang scribble/manual
|
2020-11-29 23:07:40 +01:00
|
|
|
@(require scribble/example racket/sandbox
|
|
|
|
(for-label racket graph "../utils.rkt"))
|
2020-11-29 00:28:46 +01:00
|
|
|
|
|
|
|
@title[#:tag "utils"]{dds/utils: Various Utilities}
|
|
|
|
|
2020-11-29 21:41:00 +01:00
|
|
|
@defmodule[dds/utils]
|
|
|
|
|
|
|
|
This module defines miscellaneous utilities, supporting the other modules of
|
|
|
|
the package: evaluating sexps, manipulating lists,
|
|
|
|
@hyperlink["https://orgmode.org/"]{Org-mode} interoperability, etc.
|
|
|
|
|
2022-01-16 21:09:50 +01:00
|
|
|
@bold{Note:} I am currently migrating this module to Typed Racket.
|
|
|
|
This documentation only lists the functions and the types which have already
|
|
|
|
been converted. However, the typed part is currently hidden in an untyped
|
|
|
|
module, so you cannot yet use the types directly.
|
2020-11-29 23:07:40 +01:00
|
|
|
|
|
|
|
@(define utils-evaluator
|
|
|
|
(parameterize ([sandbox-output 'string]
|
|
|
|
[sandbox-error-output 'string]
|
|
|
|
[sandbox-memory-limit 50])
|
|
|
|
(make-evaluator 'racket/base #:requires '("utils.rkt"))))
|
|
|
|
|
2022-01-16 21:00:41 +01:00
|
|
|
@section{Base types}
|
|
|
|
|
|
|
|
@defidform[Variable]{
|
|
|
|
|
|
|
|
Any Racket symbol. Designates a variable in a discrete dynamical network.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@defform[(VariableMapping A)]{
|
|
|
|
|
|
|
|
An immutable mapping (a hash table) assigning elements of type @racket[A] to
|
|
|
|
the variables.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-11-29 21:41:00 +01:00
|
|
|
@section{Hashtable injection}
|
|
|
|
|
|
|
|
This section defines some utilities to streamline the usage of hash tables
|
|
|
|
mapping symbols to values. The goal is essentially to avoid having to write
|
2020-11-29 23:07:40 +01:00
|
|
|
explicit @racket[hash-ref] calls.
|
|
|
|
|
|
|
|
@defproc[(eval-with [ht variable-mapping?] [expr any/c]) any]{
|
|
|
|
|
|
|
|
Temporarily injects the mappings from the given hash table as bindings in
|
|
|
|
a namespace including @racket[racket/base] and then evaluates the expression.
|
|
|
|
|
|
|
|
@examples[#:eval utils-evaluator
|
|
|
|
(let ([ht (hash 'a 1 'b 1)])
|
|
|
|
(eval-with ht '(+ b a 1)))
|
|
|
|
]
|
|
|
|
|
|
|
|
The local bindings from the current lexical scope are not
|
|
|
|
conserved. Therefore, the following outputs an error about a
|
|
|
|
missing identifier:
|
|
|
|
|
|
|
|
@examples[#:eval utils-evaluator
|
|
|
|
(eval:error
|
|
|
|
(let ([ht (hash 'a 1 'b 1)]
|
|
|
|
[z 1])
|
|
|
|
(eval-with ht '(+ b z a 1)))
|
|
|
|
)]}
|
2020-11-29 21:41:00 +01:00
|
|
|
|
|
|
|
@section{Analysis of quoted expressions}
|
|
|
|
|
|
|
|
@section{Org-mode interoperability}
|
|
|
|
|
|
|
|
Org-mode supports laying out the output of code blocks as tables, which is very
|
|
|
|
practical for various variable mappings (e.g., states). However, when the hash
|
|
|
|
table maps variables to lists, Org-mode will create a column per list element,
|
|
|
|
which may or may not be the desired effect. This section defines some
|
|
|
|
utilities for nicer interoperation with Org-mode tables. It also defines some
|
|
|
|
shortcuts to reduce the number of words to type when using dds with Org-mode.
|
|
|
|
See
|
|
|
|
@hyperlink["https://git.marvid.fr/scolobb/dds/src/branch/master/example/example.org"]{example.org}
|
|
|
|
for examples of usage.
|
|
|
|
|
|
|
|
@section{Additional graph utilities}
|
|
|
|
|
|
|
|
@section{Pretty printing}
|
|
|
|
|
|
|
|
@section{Additional list and hash map utilities}
|
|
|
|
|
|
|
|
@section{Functions and procedures}
|
|
|
|
|
|
|
|
@section{Randomness}
|
|
|
|
|
|
|
|
@section{Additional stream utilities}
|
|
|
|
|
|
|
|
@section{Boolean operations}
|