From: Christopher Allan Webber Date: Fri, 22 Apr 2016 15:10:27 +0000 (-0500) Subject: actors: `message-ref' now errors if no dflt provided and key not found X-Git-Tag: v0.2.0~60 X-Git-Url: https://jxself.org/git/?p=8sync.git;a=commitdiff_plain;h=55ece091fc8fb28faf8765350bc2b2d8681f190a actors: `message-ref' now errors if no dflt provided and key not found Thanks to David Thompson for guidance on the best way to construct %nothing-provided. * 8sync/systems/actors.scm (message-ref): Adjust to error if no dflt provided and key isn't found. (%nothing-provided): New unique, immutable value for checking if dflt provided to message-ref. --- diff --git a/8sync/systems/actors.scm b/8sync/systems/actors.scm index bd164be..0257b1f 100644 --- a/8sync/systems/actors.scm +++ b/8sync/systems/actors.scm @@ -461,13 +461,22 @@ Instead, actors should call create-actor." ;; change), and using existing tooling (though adding new tooling ;; would be negligible in implementation effort.) -(define* (message-ref message key #:optional dflt) +;; This cons cell is immutable and unique (for eq? tests) +(define %nothing-provided (cons 'nothing 'provided)) + +(define* (message-ref message key #:optional (dflt %nothing-provided)) "Extract KEY from body of MESSAGE. -Optionally set default with [DFLT]" +Optionally set default with [DFLT] +If key not found and DFLT not provided, throw an error." (let ((result (assoc key (message-body message)))) (if result (cdr result) - dflt))) + (if (eq? dflt %nothing-provided) + (throw 'message-body-lacks-key + "Message body does not contain key and no default provided" + #:key key + #:message message) + dflt)))) (define (kwarg-list-to-alist args)