From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48065) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dpif3-0002Er-1v for guix-patches@gnu.org; Wed, 06 Sep 2017 18:19:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dpif2-0000U8-14 for guix-patches@gnu.org; Wed, 06 Sep 2017 18:19:05 -0400 Received: from debbugs.gnu.org ([208.118.235.43]:44863) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dpif1-0000Tl-TY for guix-patches@gnu.org; Wed, 06 Sep 2017 18:19:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dpif1-0005lv-Nd for guix-patches@gnu.org; Wed, 06 Sep 2017 18:19:03 -0400 Subject: [bug#28377] [PATCH 08/10] uuid: 'uuid' macro supports more UUID types. Resent-Message-ID: From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Thu, 7 Sep 2017 00:17:54 +0200 Message-Id: <20170906221756.17024-8-ludo@gnu.org> In-Reply-To: <20170906221756.17024-1-ludo@gnu.org> References: <20170906221756.17024-1-ludo@gnu.org> List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: 28377@debbugs.gnu.org * gnu/system/uuid.scm (string->uuid): Turn 'type' into an optional argument. (uuid): Add clauses to allow for an optional 'type' parameter. --- gnu/system/uuid.scm | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/gnu/system/uuid.scm b/gnu/system/uuid.scm index 60626ebb1..1dd6a1133 100644 --- a/gnu/system/uuid.scm +++ b/gnu/system/uuid.scm @@ -206,7 +206,7 @@ ISO9660 UUID representation." ('iso9660 => iso9660-uuid->string) ('fat32 'fat => fat32-uuid->string))) -(define* (string->uuid str #:key (type 'dce)) +(define* (string->uuid str #:optional (type 'dce)) "Parse STR as a UUID of the given TYPE. On success, return the corresponding bytevector; otherwise return #f." (match (vhash-assq type %uuid-parsers) @@ -233,17 +233,23 @@ corresponding bytevector; otherwise return #f." (define-syntax uuid (lambda (s) "Return the UUID object corresponding to the given UUID representation." - ;; TODO: Extend to types other than DCE. - (syntax-case s () - ((_ str) - (string? (syntax->datum #'str)) + (syntax-case s (quote) + ((_ str (quote type)) + (and (string? (syntax->datum #'str)) + (identifier? #'type)) ;; A literal string: do the conversion at expansion time. - (let ((bv (string->uuid (syntax->datum #'str)))) + (let ((bv (string->uuid (syntax->datum #'str) + (syntax->datum #'type)))) (unless bv (syntax-violation 'uuid "invalid UUID" s)) - #`(make-uuid 'dce #,(datum->syntax #'str bv)))) + #`(make-uuid 'type #,(datum->syntax s bv)))) ((_ str) - #'(make-uuid 'dce (string->uuid str)))))) + (string? (syntax->datum #'str)) + #'(uuid str 'dce)) + ((_ str) + #'(make-uuid 'dce (string->uuid str 'dce))) + ((_ str type) + #'(make-uuid type (string->uuid str type)))))) (define uuid->string ;; Convert the given bytevector or UUID object, to the corresponding UUID -- 2.14.1