Miscellaneous
Buffered channels.
usage
(import :std/misc/channel)
make-channel
usage
(make-channel ...)
Please document me!
channel?
usage
(channel? ...)
Please document me!
channel-put
usage
(channel-put ...)
Please document me!
channel-try-put
usage
(channel-try-put ...)
Please document me!
channel-sync
usage
(channel-sync ...)
Please document me!
channel-get
usage
(channel-get ...)
Please document me!
channel-try-get
usage
(channel-try-get ...)
Please document me!
channel-close
usage
(channel-close ...)
Please document me!
channel-closed?
usage
(channel-closed? ...)
Please document me!
Asynchronous Completions
usage
(import :std/misc/completion)
completion
usage
(defsyntax completion ...)
Completion type for user-defined generics.
make-completion
usage
(make-completion)
=> <completion>
Creates a new asynchronous completion.
completion?
usage
(completion? obj)
=> boolean
Returns true if the object is a completion.
completion-ready?
usage
(completion-ready? c)
=> boolean
Returns true if the completion is ready.
completion-wait!
usage
(completion-wait! c)
c := competion
=> any
Waits on the completion until it has been posted with completion-post!
or an error
has been signaled with completion-error!
. If the completion was posted, the posted
value is returned. If an error was signalled, then it is raised as an exception.
completion-post!
usage
(completion-post! c val)
c := completion
Posts the completion with value val
.
completion-error!
usage
(completion-error! c exn)
exn := completion
Signals an error in the completion.
with-completion-error
usage
(with-completion-error c body ...)
c := completion
Evaluates body ...
with an exception handler that signals an error in the completion.
Thread Barriers
usage
(import :std/misc/barrier)
barrier
usage
(defsyntax barrier ...)
Barrier type for user-defined generics.
make-barrier
usage
(make-barrier limit)
limit := fixnum
=> <barrier>
Create a barrier, awaiting for limit
threads.
barrier?
usage
(barrier? obj)
=> boolean
Returns true if the object is a barrier.
barrier-wait!
usage
(barrier-wait! b)
b := barrier
Waits on a thread barrier until it has been posted limit
times with barrier-post!
or an error has been signaled with barrier-error!
.
barrier-post!
usage
(barrier-post! b)
b := barrier
Posts the barrier.
barrier-error!
usage
(barrier-error! b exn)
Signals an error on the barrier.
with-barrier-error
usage
(with-barrier-error b body ...)
b := barrier
Evaluates body ...
with an exception handler that signals an error in the barrier.
Deques
usage
(import :std/misc/deque)
deque
(defsyntax deque ...)
Deque type for user-defined generics.
make-deque
usage
(make-deque)
=> <deque>
Creates a new deque.
deque?
usage
(deque? obj)
=> boolean
Returns true if the object is a deque.
deque-length
usage
(deque-length dq)
dq := deque
=> integer
Returns the size of the deque.
deque-empty?
usage
(deque-empty? dq)
dq := deque
=> boolean
Returns true if the deque is empty.
push-front!
usage
(push-front! dq v)
dq := deque
Enqueues (pushes) the value v
to the front of the queue.
pop-front!
usage
(pop-front! dq [default])
dq := deque
=> any
Pops the front of the queue and a returns the value. If the deque is empty and a default value is supplied, then it is returned. Otherwise an error is raised.
peek-front
usage
(peek-front dq [default])
dq := deque
=> any
Peeks the front of the queue and a returns the value without popping it If the deque is empty and a default value is supplied, then it is returned. Otherwise an error is raised.
push-back!
usage
(push-back! dq v)
Enqueues (pushes) the value v
to the back of the queue.
pop-back!
usage
(pop-back! dq [default])
dq := deque
=> any
Pops the back of the queue and a returns the value. If the deque is empty and a default value is supplied, then it is returned. Otherwise an error is raised.
peek-back
usage
(peek-back dq [default])
dq := deque
=> any
Peeks the back of the queue and a returns the value without popping it If the deque is empty and a default value is supplied, then it is returned. Otherwise an error is raised.
deque->list
usage
(deque->list dq)
dq := deque
=> list
Returns a list of the value contained in the deque, in order.
List utilities
usage
(import :std/misc/list)
alist?
usage
(alist? ...)
Please document me!
plist?
usage
(plist? ...)
Please document me!
plist->alist
usage
(plist->alist ...)
Please document me!
alist->plist
usage
(alist->plist ...)
Please document me!
length=?
usage
(length=? ...)
Please document me!
length=n?
usage
(length=n? ...)
Please document me!
length<?
usage
(length<? ...)
Please document me!
length<n?
usage
(length<n? ...)
Please document me!
length<=?
usage
(length<=? ...)
Please document me!
length<=n?
usage
(length<=n? ...)
Please document me!
length>?
usage
(length>? ...)
Please document me!
length>n?
usage
(length>n? ...)
Please document me!
length>=?
usage
(length>=? ...)
Please document me!
length>=n?
usage
(length>=n? ...)
Please document me!
call-with-list-builder
usage
(call-with-list-builder ...)
Please document me!
with-list-builder
usage
(with-list-builder ...)
Please document me!
snoc
usage
(snoc ...)
Please document me!
append1
usage
(append1 ...)
Please document me!
for-each!
usage
(for-each! ...)
Please document me!
push!
usage
(push! ...)
Please document me!
flatten1
usage
> (flatten1 [1 [2]])
=> (1 2)
> (flatten1 [1 [2] [[3]]])
=> (1 2 (3))
Removes one layer of a nested proper list.
flatten
usage
> (flatten [1 [2]])
=> (1 2)
> (flatten [1 [2] [[3]]])
=> (1 2 3)
Removes all nested layers of a proper list.
when-list-or-empty
usage
(when-list-or-empty list body ...)
Macro which evaluates the body only if the passed value is a non-empty list, otherwise an empty list is returned.
LRU caches
usage
(import :std/misc/lru)
lru-cache
usage
(defsyntax lru-cache ...)
LRU cache type for user-defined generics.
make-lru-cache
usage
(make-lru-cache cap)
cap := fixnum; LRU cache capacity
=> <lru-cache>
Creates a new LRU cache with capacity cap
, which must be > 1.
lru-cache?
usage
(lru-cache? obj)
=> boolean
Returns true if the object is an LRU cache.
lru-cache-ref
usage
(lru-cache-ref lru key [default])
lru := lru-cache
Returns the association of key
in the LRU cache, and promotes the node to the head of the
LRU queue. If there is no association, then default is returned. If the default is omitted,
then an error is raised.
lru-cache-get
usage
(lru-cache-get lru key)
lru := lru-cache
Same as (lru-cache-ref lru key #f)
.
lru-cache-put!
usage
(lru-cache-put! lru key val)
lru := lru-cache
Puts an association of key
to val
into the LRU cache.
If the cache is full, then the tail of the LRU queue (ie the value least recently used)
is dropped from the cache.
lru-cache-remove!
usage
(lru-cache-remove! lru key)
lru := lru-cache
Removes the association of key
from the LRU cache.
lru-cache-size
usage
(lru-cache-size lru)
lru := lru-cache
=> fixnum
Returns the current size of the LRU cache.
lru-cache-capacity
usage
(lru-cache-capacity lru)
lru := lru-cache
=> fixnum
Returns the capacity of the LRU cache.
lru-cache-flush!
usage
(lru-cache-flush! lru)
lru := lru-cache
Clears the LRU cache.
lru-cache-for-each
usage
(lru-cache-for-each proc lru)
proc := lambda (key value)
lru := lru-cache
Applies (proc key val)
for every key-value association in the LRU cache,
in most recently used order.
lru-cache-walk
usage
(lru-cache-walk lru proc)
Same as (lru-cache-for-each proc lru)
.
lru-cache-fold
usage
(lru-cache-fold proc iv lru)
proc := lambda (key value r)
lru := lru-cache
Folds the LRU cache in Most Recently Used order.
lru-cache-foldr
usage
(lru-cache-foldr proc iv lru)
proc := lambda (key value r)
lru := lru-cache
Folds the LRU cache in Least Recently Used order.
lru-cache->list
usage
(lru-cache->list lru)
=> alist
Returns an alist of key-value associations in the cache.
in-lru-cache
usage
(in-lru-cache lru)
lru := lru-cache
=> iterator
Creates an iterator over the LRU cache.
in-lru-cache-keys
usage
(in-lru-cache-keys lru)
lru := lru-cache
=> iterator
Creates an iterator over the LRU cache keys.
in-lru-cache-values
usage
(in-lru-cache-values lru)
lru := lru-cache
=> iterator
Creates an iterator over the LRU cache values.
Port utilities
usage
(import :std/misc/ports)
copy-port
usage
(copy-port ...)
Please document me!
read-all-as-string
usage
(read-all-as-string ...)
Please document me!
read-file-string
usage
(read-file-string ...)
Please document me!
read-all-as-lines
usage
(read-all-as-lines ...)
Please document me!
read-file-lines
usage
(read-file-lines ...)
Please document me!
Port Destructor
(defmethod {destroy <port>} close-port)
The module also defines a destroy
method for ports, so that they can
be used in with-destroy
forms and other primitives that use the destroy
idiom.
Priority Queues
usage
(import :std/misc/pqueue)
pqueue
(defsyntax pqueue ...)
Priority queue type, for user-defined generics.
make-pqueue
usage
(make-pqueue prio [cmp = <])
prio := lambda (any) => any; element priority function
cmp := priority comparison function
=> pqueue
Creates a new priority queue.
pqueue?
usage
(pqueue? obj)
=> boolean
Returns true if the object is a priority queue.
pqueue-empty?
usage
(pqueue-empty? pq)
pq := pqueue
=> boolean
Returns true if the priority queue is empty.
pqueue-size
usage
(pqueue-size pq)
pq := pqueue
=> integer
Returns the size of the priority queue.
pqueue-peek
usage
(pqueue-peek pq [default])
pq := pqueue
=> any
Peeks the next value in the queue, without popping it. If the queue is empty and a default value is supplied, then it is returned. Otherwise an error is raised.
pqueue-pop!
usage
(pqueue-pop! pq [default])
pq := pqueue
=> any
Peeks the next value in the queue, and returns it. If the queue is empty and a default value is supplied, then it is returned. Otherwise an error is raised.
pqueue-push!
usage
(pqueue-push! pq v)
pq := pqueue
Pushes the value v
in the queue.
Proces Utilities
usage
(import :std/misc/process)
Overview
These utilities synchronously spawn a subprocess,
spawn a coprocess function in a thread to interact with the process
(default: std/misc/ports#read-all-as-string
),
check the status of the process upon termination,
and return the result of that coprocess if successful.
run-process
usage
(run-process ...)
Please document me!
run-process/batch
usage
(run-process/batch ...)
Please document me!
Simple Queues
usage
(import :std/misc/queue)
queue
(defsyntax queue ...)
Queue type, for user-defined generics.
make-queue
usage
(make-queue)
=> <queue>
Creates a new queue.
queue?
usage
(queue? obj)
=> boolean
Returns true if the object is a queue.
queue-length
usage
(queue-length q)
q := queue
=> integer
Returns the size of the queue.
queue-empty?
usage
(queue-empty? q)
q := queue
=> boolean
Returns true if the queue is empty.
non-empty-queue?
usage
(non-empty-queue? q)
Returns true if the queue is not empty.
enqueue!
usage
(enqueue! q v)
q := queue
Enqueues (pushes) the value v
to the end of the queue.
enqueue-front!
usage
(enqueue-front! q v)
q := queue
Enqueues the value v
at the front of the queue.
dequeue!
usage
(dequeue! q [default])
q := queue
=> any
Pops the end of the queue and a returns the value. If the queue is empty and a default value is supplied, then it is returned. Otherwise an error is raised.
queue-peek
usage
(queue-peek q [default])
q := queue
=> any
Peeks the end of the queue and a returns the value without popping it from the queue. If the queue is empty and a default value is supplied, then it is returned. Otherwise an error is raised.
queue->list
usage
(queue->list q)
=> list
Returns a list of the value contained in the queue, in order.
Red Black Trees
usage
(import :std/misc/rbtree)
rbtree
usage
(defsyntax rbtree)
Red Black tree (rbtree) type.
rbtree?
usage
(rbtree? obj)
=> boolean
Returns true if the object is an rbtree.
make-rbtree
usage
(make-rbtree cmp)
cmp := lambda (a b); comparison procedure
=> <rbtree>
Creates a new rbtree.
The comparison procedure accepts two keys, a and b, and performs ternary comparison:
- if a < b, then it must return a negative number
- if a = b, then it must return 0
- if a > b, then it must returna positive number
rbtree-ref
usage
(rbtree-ref rbt key [default])
rbt := rbtree
=> any
Returns the value associated with key
in the rbtree, or the default if no association
is present; if the default value is omitted then an error is raised.
rbtree-get
usage
(rbtree-get rbt key)
rbt := rbtree
=> any
Same as (rbtree-ref rbt key #f)
.
rbtree-put!
usage
(rbtree-put! rbt key value)
rbt := rbtree
Destructively updates the rbtree, associating key
with value
.
rbtree-put
usage
(rbtree-put rbt key value)
rbt := rbtree
=> rbtree
Functionally updates the rbtree, associating key
with value
.
rbtree-update!
usage
(rbtree-update! rbt k update default)
rbt := rbtree
update := lambda (x y); update function
Destructively updates the rbtree.
rbtree-update
usage
(rbtree-update rbt k update default)
=> rbtree
Functionally updates the rbtree.
rbtree-remove!
usage
(rbtree-remove! rbt key)
rbt := rbtree
Destructively updates the rbtree, removing the association of key
.
rbtree-remove
usage
(rbtree-remove rbt key)
rbt := rbtree
=> rbtree
Functionally updates the rbtree, removing the association of key
.
rbtree-empty?
usage
(rbtree-empty? rbt)
rbt := rbtree
=> boolean
Returns true if the rbtree is an empty.
rbtree-copy
usage
(rbtree-copy rbt)
rbt := rbtree
=> rbtree
Returns a copy of the rbtree.
rbtree-for-each
usage
(rbtree-for-each proc rbt)
proc := lambda (key value)
rbt := rbtree
Evaluates (proc key val)
for every association key -> value
in the rbtree, in ascending order.
rbtree-for-eachr
usage
(rbtree-for-eachr proc rbt)
proc := lambda (key value)
rbt := rbtree
Evaluates (proc key val)
for every association key -> value
in the rbtree, in descending order.
rbtree-fold
usage
(rbtree-fold proc seed rbt)
proc := lambda (key value seed)
rbt := rbtree
=> any
Folds the rbtree in ascending order.
rbtree-foldr
usage
(rbtree-foldr proc seed rbt)
proc := lambda (key value seed)
rbt := rbtree
=> any
Folds the rbtree in descending order.
rbtree->list
usage
(rbtree->list rbt)
rbt := rbtree
=> list
Returns a list with all the associations in the rbtree, in ascending order.
rbtree->listr
usage
(rbtree->listr rbt)
rbt := rbtree
=> list
Returns a list with all the associations in the rbtree, in descending order.
list->rbtree
usage
(list->rbtree cmp lst)
cmp := lambda (x y); comparison function
lst := alist
=> rbtree
Creates a new rbtree from an associative list.
in-rbtree
usage
(in-rbtree rbt)
rbt := rbtree
=> iterator
Creates an iterator over the rbtree.
in-rbtree-keys
usage
(in-rbtree-keys rbt)
rbt := rbtree
=> iterator
Creates an iterator over the rbtree keys.
in-rbtree-values
usage
(in-rbtree-values rbt)
rbt := rbtree
=> iterator
Creates an iterator over the rbtree values.
string-cmp
usage
(string-cmp a b)
a, b := string
=> fixnum
Comparison function for lexicographic string ordering.
symbol-cmp
usage
(symbol-cmp a b)
a, b := symbol
=> fixnum
Comparison function for lexicographic symbol ordering.
symbol-hash-cmp
usage
(symbol-hash-cmp a b)
a, b := symbol
=> fixnum
Comparison function for symbol ordering based on their hashes; ties are broken by lexicographic ordering.
Sourceable Representation
usage
(import :std/misc/repr)
print-representation
usage
(print-representation obj [port = (current-output-port)] [options = (current-representation-options)])
print-representation
is a function (also available with the short-hand name pr
)
that takes an object, optionally a port and a table of options, and
displays on that port source-code representation of the object
that can be evaluated back into an equivalent object.
Behavior of print-representation
can be specialized for new classes of objects by defining
new methods on :pr
, as in:
(defmethod {:pr my-class}
(lambda (self port options)
...))
pr
usage
(defalias pr print-representation)
Same as print-representation
.
prn
usage
(prn ...)
prn
does the same as pr
then follows with a newline.
repr
usage
(repr obj [options = (current-representation-options)])
repr
does not take a port as argument and instead
returns the representation as a string.
representable
(defclass representable ())
representable
is an abstract mixin class that defines a method for :pr
. By default,
if a class does not provide its own implementation, that method will call print-unrepresentable-object
.
print-unrepresentable-object
usage
(print-unrepresentable-object obj [port = (current-output-port)] [options = (current-representation-options)])
print-unrepresentable-object
is a helper function to use as fallback
for objects that can't otherwise be displayed.
default-representation-options
(def default-representation-options)
default-representation-options
is the default table of options.
No options are currently defined, and the default table is currently empty.
In the future, options may be defined for pretty-printing, etc.
current-representation-options
usage
(current-representation-options [options])
current-representation-options
is a parameter returning the current options,
and initially returns the default-representation-options
.
display-separated
usage
(display-separated lst [port = (current-output-port)]
[prefix: prefix = ""]
[separator: separator = " "]
[suffix: suffix = ""]
[display-element: disp = display])
display-separated
is a helper function that takes a list of objects, an optional port,
and as keywords a prefix:
string (empty by default), a suffix:
string (empty by default),
a separator
string (defaulting to a single space " "
), and
a display-element:
function (the function display
by default),
and displays each element of the list with the given prefix, suffix, separator and display function.
Type Descriptor Utilities.
usage
(import :std/misc/rtd)
object-type
usage
(object-type ...)
Please document me!
type?
usage
(type? ...)
Please document me!
type-id
usage
(type-id ...)
Please document me!
type-name
usage
(type-name ...)
Please document me!
type-super
usage
(type-super ...)
Please document me!
type-descriptor?
usage
(type-descriptor? ...)
Please document me!
type-descriptor-mixin
usage
(type-descriptor-mixin ...)
Please document me!
type-descriptor-fields
usage
(type-descriptor-fields ...)
Please document me!
type-descriptor-plist
usage
(type-descriptor-plist ...)
Please document me!
type-descriptor-ctor
usage
(type-descriptor-ctor ...)
Please document me!
type-descriptor-slots
usage
(type-descriptor-slots ...)
Please document me!
type-descriptor-methods
usage
(type-descriptor-methods ...)
Please document me!
Shared-structure Equality.
usage
(import :std/misc/shared)
equal-shared?
usage
(equal-shared? ...)
Please document me!
Shuffling
usage
(import :std/misc/shuffle)
shuffle
usage
(shuffle ...)
Please document me!
vector-shuffle
usage
(vector-shuffle ...)
Please document me!
vector-shuffle!
usage
(vector-shuffle! ...)
Please document me!
String utilities
usage
(import :std/misc/string)
string-split-prefix
usage
(string-split-prefix ...)
Please document me!
string-trim-prefix
usage
(string-trim-prefix ...)
Please document me!
string-split-suffix
usage
(string-split-suffix ...)
Please document me!
string-trim-suffix
usage
(string-trim-suffix ...)
Please document me!
string-split-eol
usage
(string-split-eol ...)
Please document me!
string-trim-eol
usage
(string-trim-eol ...)
Please document me!
+cr+
(def +cr+)
Please document me!
+lf+
(def +lf+)
Please document me!
+crlf+
(def +crlf+)
Please document me!
string-subst
usage
(string-subst str old new [count: count = #f])
str := string
old := string
new := string
count := fixnum
=> string
In str replace the string old with string new. The procedure accepts only a fixnum or #f for count.
count > 0
limit replacementscount #f
no limitcount <= 0
return input
Synchronized Data Structures.
usage
(import :std/misc/sync)
make-sync-hash
usage
(make-sync-hash ...)
Please document me!
sync-hash?
usage
(sync-hash? ...)
Please document me!
sync-hash-get
usage
(sync-hash-get ...)
Please document me!
sync-hash-ref
usage
(sync-hash-ref ...)
Please document me!
sync-hash-key?
usage
(sync-hash-key? ...)
Please document me!
sync-hash-put!
usage
(sync-hash-put! ...)
Please document me!
sync-hash-remove!
usage
(sync-hash-remove! ...)
Please document me!
sync-hash-do
usage
(sync-hash-do ...)
Please document me!
Text Utilities
usage
(import :std/misc/text)
include-text
usage
(include-text ...)
Please document me!
Thread utilities
usage
(import :std/misc/threads)
primordial-thread-group
usage
(primordial-thread-group ...)
Please document me!
thread-group->thread-list*
usage
(thread-group->thread-list* ...)
Please document me!
all-threads
usage
(all-threads ...)
Please document me!
thread-dead?
usage
(thread-dead? ...)
Please document me!
thread-group-kill!
usage
(thread-group-kill! ...)
Please document me!
thread-raise!
usage
(thread-raise! ...)
Please document me!
thread-abort!
usage
(thread-abort! ...)
Please document me!
thread-abort?
usage
(thread-abort? ...)
Please document me!
thread-async!
usage
(thread-async! ...)
Please document me!
on-all-processors
usage
(on-all-processors ...)
Please document me!
Timeouts
usage
(import :std/misc/timeout)
make-timeout
usage
(make-timeout ...)
Please document me!
UUIDs
usage
(import :std/misc/uuid)
UUID
usage
(UUID ...)
Please document me!
uuid-length
usage
(uuid-length ...)
Please document me!
uuid::t
usage
(uuid::t ...)
Please document me!
make-uuid
usage
(make-uuid ...)
Please document me!
uuid?
usage
(uuid? ...)
Please document me!
uuid=?
usage
(uuid=? ...)
Please document me!
uuid-hash
usage
(uuid-hash ...)
Please document me!
uuid->u8vector
usage
(uuid->u8vector ...)
Please document me!
u8vector->uuid
usage
(u8vector->uuid ...)
Please document me!
uuid->string
usage
(uuid->string ...)
Please document me!
string->uuid
usage
(string->uuid ...)
Please document me!
random-uuid
usage
(random-uuid ...)
Please document me!
Functional utilities
usage
(import :std/misc/func)
Collection of mixed purpose higher-order functions.
always
usage
> (def fn (always 5))
> (list (fn) (fn))
=> (5 5)
> (def fn (always (lambda () "hi")))
> (fn)
=> "hi"
> (def fn (always random-integer 10)
> (list (fn) (fn))
=> (4 3)
Creates a lambda which returns the same value or calls always the same function with the same arguments.
repeat
usage
> (repeat 2 5)
=> (2 2 2 2 2)
> (repeat (lambda () 10) 2)
=> (10 10)
> (repeat random-integer 3 10)
=> (8 3 5)
Repeat value or call function N times and return the result as list.