From: Chris Hanson Date: Tue, 28 Feb 2017 06:13:19 +0000 (-0800) Subject: Implement keyword-option-parser. X-Git-Tag: mit-scheme-pucked-9.2.12~198^2~13 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=170608b72c0751e4c0f632ac351fcd465c908b94;p=mit-scheme.git Implement keyword-option-parser. --- diff --git a/src/runtime/list.scm b/src/runtime/list.scm index 32fcdd3e6..8a8c75b71 100644 --- a/src/runtime/list.scm +++ b/src/runtime/list.scm @@ -1428,6 +1428,25 @@ USA. (cons (cdr (car alist)) (loop (cdr alist)))) '()))) + +(define (keyword-option-parser keyword-option-specs) + (guarantee-list-of keyword-option-spec? keyword-option-specs + 'keyword-option-parser) + (lambda (options caller) + (guarantee keyword-list? options caller) + (apply values + (map (lambda (spec) + (let ((value (get-keyword-value options (car spec)))) + (if (default-object? value) + (caddr spec) + (guarantee (cadr spec) value caller)))) + keyword-option-specs)))) + +(define (keyword-option-spec? object) + (and (list? object) + (fix:= 3 (length object)) + (interned-symbol? (car object)) + (unary-procedure? (cadr object)))) ;;;; Last pair diff --git a/src/runtime/runtime.pkg b/src/runtime/runtime.pkg index 64c2daf38..3f100ce9c 100644 --- a/src/runtime/runtime.pkg +++ b/src/runtime/runtime.pkg @@ -2995,6 +2995,7 @@ USA. keep-matching-items! keyword-list->alist keyword-list? + keyword-option-parser last ;SRFI-1 last-pair length