aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2022-07-10 14:57:12 +0200
committerThomas White <taw@physics.org>2022-07-10 14:57:12 +0200
commit3731f442ca40619ce7e62789e6b8c44571866e74 (patch)
treeaced5aa1cb99e26c2a979455b72cca7aab2065ad
parent274ebcd3c7a87524513f845cf533bd5b4d53ee16 (diff)
Add "state-empty?"
-rw-r--r--guile/starlet/state.scm8
-rw-r--r--guile/starlet/utils.scm14
2 files changed, 20 insertions, 2 deletions
diff --git a/guile/starlet/state.scm b/guile/starlet/state.scm
index 0fff383..0047014 100644
--- a/guile/starlet/state.scm
+++ b/guile/starlet/state.scm
@@ -57,7 +57,8 @@
value->number
atomically-overlay-state!
update-state!
- add-update-hook!))
+ add-update-hook!
+ state-empty?))
;; A "state" is an atomically-updating container for an immutable
@@ -452,3 +453,8 @@ pre-existing contents."
(set! selection (flatten-sublists fixture-list))))
(run-hook selection-hook selection))
+
+(define (state-empty? st)
+ (hash-table-empty?
+ (atomic-box-ref
+ (get-ht-box st))))
diff --git a/guile/starlet/utils.scm b/guile/starlet/utils.scm
index 7656827..4a2f0be 100644
--- a/guile/starlet/utils.scm
+++ b/guile/starlet/utils.scm
@@ -22,6 +22,7 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-8)
#:use-module (ice-9 exceptions)
+ #:use-module (ice-9 control)
#:export (print-hash-table
copy-hash-table
in-range
@@ -38,7 +39,8 @@
scale-and-clamp-to-range
percent->dmxval8
percent->dmxval16
- comment))
+ comment
+ hash-table-empty?))
(define (print-hash-table ht)
@@ -166,3 +168,13 @@
(syntax-rules ()
((_ body ...)
#f)))
+
+
+(define (hash-table-empty? ht)
+ (let/ec
+ return
+ (hash-for-each-handle
+ (lambda (key)
+ (return #f))
+ ht)
+ #t))