Fix unbalanced paren in core.sls, add missing mpsc-length, export try/catch from sugar
ober
2ba19b55176e13c083128a6a98b0fa00e1649a9c
--- a/lib/jerboa/core.sls +++ b/lib/jerboa/core.sls @@ -383,7 +383,7 @@ (syntax-violation 'defstruct (format "keyword ~a is not supported in Jerboa defstruct (Chez R6RS limitation)" key) #'kw)) - #'(defstruct (name parent) (field ...)))])) + #'(defstruct (name parent) (field ...)))]))) ;;;; ---- DEFCLASS ---- ;; NOTE: defclass in Jerboa maps to defstruct (single inheritance via Chez records). --- a/lib/std/actor/mpsc.sls +++ b/lib/std/actor/mpsc.sls @@ -13,6 +13,7 @@ mpsc-dequeue! ;; consumer: remove from head (blocks if empty) mpsc-try-dequeue! ;; consumer: remove or return (values #f #f) immediately mpsc-empty? ;; approximate — safe only from consumer thread + mpsc-length ;; approximate count — safe from consumer thread mpsc-close! ;; signal no more messages; wakes blocked consumers mpsc-closed?) (import (chezscheme)) @@ -111,6 +112,14 @@ (with-mutex (mpsc-queue-head-mutex q) (condition-broadcast (mpsc-queue-not-empty q)))) + ;; Approximate length — walks the linked list from head. + ;; Safe to call from the consumer thread. + (define (mpsc-length q) + (let loop ([node (mpsc-node-next (mpsc-queue-head q))] [n 0]) + (if node + (loop (mpsc-node-next node) (+ n 1)) + n))) + ;; Public predicate — wraps the record field accessor (define (mpsc-closed? q) (mpsc-queue-closed? q)) --- a/lib/std/sugar.sls +++ b/lib/std/sugar.sls @@ -3,9 +3,8 @@ (library (std sugar) (export - ;; NOTE: try/catch/finally, while/until, hash-literal/hash-eq-literal, - ;; let-hash, defrule/defrules are defined in (jerboa core) and - ;; re-exported from there. Import (jerboa core) to use them. + ;; Re-exported from (jerboa core): + try catch finally unwind-protect chain chain-and with-id assert!