[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to fix this G-exp?

From: Ludovic Courtès
Subject: Re: how to fix this G-exp?
Date: Mon, 26 Sep 2022 10:58:20 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.1 (gnu/linux)


zimoun <> skribis:

> On Sat, 24 Sep 2022 at 20:40, Csepp <> wrote:
>> As you can see, that is an unqouted list.  The fix should be pretty
>> simple: just add an extra quote.  Haven't tested it, but one of these
>> should work:
>> ```
>> (define (something) ''(42))
>> ;; or
>> (quote #+(something))
>> ```
> The extra quote does not work.

I think Csepp was on the right track though.

Attached is a version where I added that quote:

      (define that

AFAICS, that was the only fix that needed to be made.  (I also removed
(json) from the imported modules; it’s already taken care of by

Pro tip: to debug code staging issues like this, where you end up
staging code that doesn’t behave as you would expect, it’s useful to
check what the staged code looks like, like so:

--8<---------------cut here---------------start------------->8---
$ cat $(guix gc -R $(guix build -m /tmp/zimoun.scm -d)|grep example-json-build)
(begin (use-modules (guix build utils) (json)) (define that (quote (42 43 44))) 
(define file-name (string-append ((@ (guile) getenv) "out") "/example.json")) 
(mkdir-p (dirname file-name)) (with-output-to-file file-name (lambda () 
(scm->json (list->vector that)))))
--8<---------------cut here---------------end--------------->8---

That ‘example-json-builder’ file contains the staged version of your
code.  We can see '(42 43 44) there; if we remove the quote mentioned
above, we get:

  (define that (42 43 44))

which leads to a wrong-type-to-apply error.



(use-modules (srfi srfi-1)
             (ice-9 match)
             (guix packages)
             (gnu packages))

(define (package+propagated-inputs package)
  (match (package-transitive-propagated-inputs package)
    (((labels packages) ...)
     (cons package packages))))

(define (something)
  (list 42 43 44))

(define (an-example)
  (define build
    (with-extensions (package+propagated-inputs
                      (specification->package "guile-json"))
      (with-imported-modules '((guix build utils))
            (use-modules (guix build utils)

            (define that
              ;; 'something' returns a list of integers; we need to quote
              ;; that list: it's data, not code, that we are inserting here.

            (define file-name
              (string-append #$output "/example.json"))

            (mkdir-p (dirname file-name))
            (with-output-to-file file-name
              (lambda ()
                (scm->json (list->vector that))))))))

  (computed-file "example-json"

 (list (manifest-entry
         (name "bang")
         (version "0")
         (item (an-example)))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]