Miscellaneous Utilities
Jan Dvořák <mordae@anilinux.org>
1 Syntax Extensions
(require misc1/syntax) | package: misc1 |
syntax
(producing ((name value) ...) body ...)
Example: | ||||||||
|
syntax
(using ((name value) ...) body ...)
Example: | |||||||
|
syntax
(when* ((name value) ...) body ...)
Example: | |||||||
|
syntax
(recursive (name ...) body ...)
Examples: | ||||||||||||
|
syntax
(loop body ...)
syntax
(while continue? body ...)
syntax
(until halt? body ...)
syntax
(loop-while-cond (test body ...) ...)
Example: | ||||||
|
syntax
(loop-until-cond (test body ...) ...)
Example: | ||||||||
|
syntax
(with-semaphore sema body ...)
Example: | |||||
|
syntax
(spawn-thread body ...)
Example: | |||||
|
syntax
(with-output-bytes body ...)
Example: | ||||
|
syntax
(with-input-bytes bstr body ...)
Example: | ||||
|
syntax
(with-output-string body ...)
Example: | ||||
|
syntax
(with-input-string str body ...)
Example: | ||||
|
syntax
(after body ... (cleanup cleanup-body ...))
syntax
(when-defined name body ...)
Examples: | |||||||
|
2 Match Expanders
(require misc1/match) | package: misc1 |
syntax
(hash-lookup (key value) ...)
Example: | |||||||
|
3 Dictionaries
(require misc1/dict) | package: misc1 |
The optional default keyword argument allows to define a substitute for mising keys’ values. If a procedure is specified, it’s return value is used.
Examples: | ||||||
|
procedure
(dict-merge base other ...) → dict?
base : dict? other : dict?
Example: | ||
|
procedure
(dict-merge! base other ...) → void?
base : dict? other : dict?
syntax
(let-dict (((name ...) value) ...) body ...)
Example: | |||||
|
4 Lists
(require misc1/list) | package: misc1 |
procedure
(list->values lst) → any
lst : list?
Example: | |||||
|
Example: | |||||
|
procedure
(split-every lst idx) → (listof list?)
lst : list? idx : exact-positive-integer?
Examples: | ||||||
|
syntax
(let-list (((name ...) value) ...) body ...)
Example: | |||||
|
5 Exceptions
(require misc1/throw) | package: misc1 |
Raise the resulting exception.
Examples: | |||||||||
|
6 Asynchronous Tasks
(require misc1/async) | package: misc1 |
This module provides a simple way to run a piece of code in a background thread, getting it’s result back via Racket’s integrated event system.
procedure
(async-task proc) → evt?
proc : (-> any)
Examples: | ||||||||||||
|
syntax
(async body ...)
Example: | ||
|
7 Fast Channels
(require misc1/fast-channel) | package: misc1 |
Fast channels are an alternative to racket/async-channel that makes use of semaphores instead of a background thread, yielding a much greater throughput.
procedure
Example: | |||
|
procedure
(fast-channel? v) → boolean?
v : any/c
Example: | ||
|
procedure
(fast-channel-put channel value ...) → void?
channel : fast-channel? value : any/c
There is no limit on number of items placed into a channel and the caller is never blocked.
Examples: | |||||||||
|
procedure
(fast-channel-get channel) → any
channel : fast-channel?
Examples: | ||||
|
procedure
(fast-channel-try-get channel) → any
channel : fast-channel?
Please note that it is possible to send multiple values, but this function fails with just one. Make sure you expect proper return arity.
Examples: | |||||||
|
procedure
(fast-channel-peek channel) → any
channel : fast-channel?
Examples: | |||||
|
procedure
(fast-channel-try-peek channel) → any
channel : fast-channel?
Examples: | ||||||
|
procedure
(fast-channel-peek-evt channel) → evt?
channel : fast-channel?
Examples: | |||||||
|
8 Events
Extended events, some building on the new replace-evt procedure when available.
(require misc1/evt) | package: misc1 |
Example: | ||||||||
|
procedure
(recurring-evt base-evt [handler]) → evt?
base-evt : evt? handler : procedure? = void
Example: | |||||||||||||
|
procedure
(alarm-in-evt msecs) → evt?
msecs : real?
procedure
(constant-evt arg ...) → evt?
arg : any/c
Example: | |||||
|
Examples: | |||||||||||||
|
procedure
(trigger-evt? v) → boolean?
v : any/c
procedure
(make-trigger-evt) → evt?
Examples: | |||||
|
procedure
evt : trigger-evt? v : any/c
Examples: | |||||||
|
procedure
evt : trigger-evt?
Examples: | |||||
|
procedure
(epoch-evt? v) → boolean?
v : any/c
procedure
(make-epoch-evt) → evt?
Example: | |||
|
procedure
(epoch-evt-advance! evt v ...) → void?
evt : epoch-evt? v : any/c
Examples: | |||||||
|
9 Advanced Locking
Advanced locking tools, such as read-write locks and lock tables.
(require misc1/locking) | package: misc1 |
procedure
(make-rwlock [wlock]) → rwlock?
wlock : semaphore? = (make-semaphore 1)
Example: | |||
|
Example: | ||
|
syntax
(with-read-lock lock body ...)
Example: | ||||
|
syntax
(with-write-lock lock body ...)
Example: | ||||
|
procedure
(call-with-read-lock lock proc) → any
lock : rwlock? proc : (-> any)
procedure
(call-with-write-lock lock proc) → any
lock : rwlock? proc : (-> any)