diff --git a/guix/gexp.scm b/guix/gexp.scm index e229c1fc8f..38114f8863 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -4,7 +4,7 @@ ;;; Copyright © 2018 Jan Nieuwenhuizen ;;; Copyright © 2019, 2020 Mathieu Othacehe ;;; Copyright © 2020 Maxim Cournoyer -;;; Copyright © 2021 Maxime Devos +;;; Copyright © 2021, 2022 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -174,12 +174,14 @@ (define (gexp-like? thing) (map (lambda (reference) (match reference (($ thing output native) - (if (gexp-like? thing) - (gexp->approximate-sexp thing) - ;; Simply returning 'thing' won't work in some - ;; situations; see 'write-gexp' below. - '(*approximate*))) - (_ '(*approximate*)))) + (cond ((gexp-like? thing) + (gexp->approximate-sexp thing)) + ((not (record? thing)) ; a S-exp + thing) + (#true + ;; Simply returning 'thing' won't work in some + ;; situations; see 'write-gexp' below. + '(*approximate*)))))) (gexp-references gexp)))) (define (write-gexp gexp port) diff --git a/tests/gexp.scm b/tests/gexp.scm index 33c0e4bf8c..61ed5bc02d 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm @@ -1,6 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014-2022 Ludovic Courtès -;;; Copyright © 2021 Maxime Devos +;;; Copyright © 2021-2022 Maxime Devos ;;; ;;; This file is part of GNU Guix. ;;; @@ -121,6 +121,19 @@ (define defmod 'define-module) ;fool Geiser (let ((inside (file-append coreutils "/bin/hello"))) (gexp->approximate-sexp #~(display '#$inside)))) +;; See . +(test-equal "unquoted sexp (not a gexp!)" + '(list #(foo) (foo) () "foo" foo #xf00) + (let ((inside/vector #(foo)) + (inside/list '(foo)) + (inside/empty '()) + (inside/string "foo") + (inside/symbol 'foo) + (inside/number #xf00)) + (gexp->approximate-sexp + #~(list #$inside/vector #$inside/list #$inside/empty #$inside/string + #$inside/symbol #$inside/number)))) + (test-equal "no refs" '(display "hello!") (let ((exp (gexp (display "hello!"))))