Hi, zimoun <zimon.touto...@gmail.com> skribis:
> On Sat, 24 Sep 2022 at 20:40, Csepp <raingl...@riseup.net> 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: #~(begin … (define that '#+(something)) …) 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 ‘with-extensions’.) 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. HTH! Ludo’.
(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)) #~(begin (use-modules (guix build utils) (json)) (define that ;; 'something' returns a list of integers; we need to quote ;; that list: it's data, not code, that we are inserting here. '#+(something)) (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" build)) (manifest (list (manifest-entry (name "bang") (version "0") (item (an-example)))))