From: Philip McGrath <philip@philipmcgrath.com>
To: 52749@debbugs.gnu.org
Subject: bug#52749: G-expressions don't consistently preserve #nil
Date: Wed, 22 Dec 2021 23:25:35 -0500 [thread overview]
Message-ID: <23d2ac1d-737d-787c-5535-c816566461dd@philipmcgrath.com> (raw)
G-expressions currently do not consistently preserve the distinction
between #nil and '(), which causes trouble for programs that rely on
that distinction. In particular, the issue affects programs that use
(guix build json), because that library uses #nil to represent the JSON
value `null', whereas it uses '() to represent an empty JSON array.
The following program exposes the error:
--8<---------------cut here---------------start------------->8---
(use-modules (guix build json)
(guix gexp)
(guix monads)
(guix store)
(guix derivations)
(rnrs conditions)
(ice-9 textual-ports))
(define (check-equal? actual expected message)
(define who 'check-equal?)
(unless (equal? actual expected)
(raise-exception
(condition
(make-assertion-violation)
(make-who-condition 'check-equal?)
(make-irritants-condition (list actual))
(make-message-condition
(format #f "~a: ~a\n ~a: ~s\n ~a: ~s\n ~a: ~s"
who "test failed"
"message" message
"expected" expected
"actual" actual))))))
(define (sexp->json-string sx)
(call-with-output-string
(lambda (out)
(write-json sx out))))
(define (gexp->json-string gx)
(run-with-store (open-connection)
(mlet* %store-monad ((drv (gexp->derivation "example.json"
(with-imported-modules `((guix build json))
#~(begin
(use-modules (guix build json))
(call-with-output-file #$output
(lambda (out)
(write-json #$gx out)))))))
(_built (built-derivations (list drv))))
(return (call-with-input-file (derivation->output-path drv)
get-string-all)))))
(check-equal? (sexp->json-string '())
"[]"
"sexp: empty array")
(check-equal? (gexp->json-string #~'())
"[]"
"gexp: empty array")
(check-equal? (sexp->json-string #nil)
"null"
"sexp: null")
(check-equal? (gexp->json-string #~#nil)
"null"
"gexp: null")
(check-equal? (sexp->json-string '(@ ("k" . #nil)))
"{\"k\":null}"
"sexp: null in object")
;; This one fails!
(check-equal? (gexp->json-string #~'(@ ("k" . #nil)))
"{\"k\":null}"
"gexp: null in object")
--8<---------------cut here---------------end--------------->8---
-Philip
next reply other threads:[~2021-12-23 4:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-23 4:25 Philip McGrath [this message]
2021-12-23 6:59 ` bug#52749: G-expressions don't consistently preserve #nil Maxime Devos
2021-12-25 11:13 ` Maxime Devos
2021-12-27 18:38 ` Philip McGrath
2021-12-27 20:24 ` Maxime Devos
2022-01-03 10:28 ` Maxime Devos
2022-01-03 10:49 ` Maxime Devos
2021-12-23 17:58 ` Maxime Devos
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=23d2ac1d-737d-787c-5535-c816566461dd@philipmcgrath.com \
--to=philip@philipmcgrath.com \
--cc=52749@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).