From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:470:142:3::10]:49097) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hv4yC-0001WA-5M for guix-patches@gnu.org; Tue, 06 Aug 2019 15:18:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hv4yA-00043f-E1 for guix-patches@gnu.org; Tue, 06 Aug 2019 15:18:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:57205) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hv4y9-000421-S9 for guix-patches@gnu.org; Tue, 06 Aug 2019 15:18:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hv4y9-0003dh-Mo for guix-patches@gnu.org; Tue, 06 Aug 2019 15:18:01 -0400 Subject: [bug#36948] [PATCH 1/2] import: utils: Add hash-ref*. References: <87k1bq864w.fsf@cbaines.net> In-Reply-To: <87k1bq864w.fsf@cbaines.net> Resent-Message-ID: From: Christopher Baines Date: Tue, 6 Aug 2019 20:17:27 +0100 Message-Id: <20190806191728.22923-1-mail@cbaines.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: 36948@debbugs.gnu.org With the change to guile-json version 3, JSON objects are represented as hash tables, rather than alists. The cpan importer uses assoc-ref* on a hash table, so add an equivalent function for hash tables. * guix/import/utils.scm (hash-ref*): New procedure. --- guix/import/utils.scm | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/guix/import/utils.scm b/guix/import/utils.scm index 2a3b7341fb..ed6c3ce6af 100644 --- a/guix/import/utils.scm +++ b/guix/import/utils.scm @@ -47,6 +47,7 @@ flatten assoc-ref* + hash-ref* url-fetch guix-hash-url @@ -116,6 +117,15 @@ recursively apply the procedure to the sub-list." (assoc-ref alist key) (apply assoc-ref* (assoc-ref alist key) rest))) +(define (hash-ref* hash-table key . rest) + "Return the value for KEY from HASH-TABLE. For each additional key specified, +recursively apply the procedure to the sub-hash-table." + (if (hash-table? hash-table) + (if (null? rest) + (hash-ref hash-table key) + (apply hash-ref* (hash-ref hash-table key) rest)) + #f)) ; For consistency with assoc-ref* + (define (url-fetch url file-name) "Save the contents of URL to FILE-NAME. Return #f on failure." (parameterize ((current-output-port (current-error-port))) -- 2.22.0