all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: zimoun <zimon.toutoune@gmail.com>
Cc: Csepp <raingloom@riseup.net>,  help-guix@gnu.org
Subject: Re: how to fix this G-exp?
Date: Mon, 26 Sep 2022 10:58:20 +0200	[thread overview]
Message-ID: <87tu4upl5f.fsf@gnu.org> (raw)
In-Reply-To: <86bkr3n1mp.fsf@gmail.com> (zimoun's message of "Sun, 25 Sep 2022 13:18:22 +0200")

[-- Attachment #1: Type: text/plain, Size: 1693 bytes --]

Hi,

zimoun <zimon.toutoune@gmail.com> skribis:

> On Sat, 24 Sep 2022 at 20:40, Csepp <raingloom@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’.


[-- Attachment #2: the file --]
[-- Type: text/plain, Size: 1235 bytes --]

(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)))))

  reply	other threads:[~2022-09-26  8:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-23 17:26 how to fix this G-exp? zimoun
2022-09-24 18:40 ` Csepp
2022-09-25 11:18   ` zimoun
2022-09-26  8:58     ` Ludovic Courtès [this message]
2022-11-04 16:09       ` zimoun

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tu4upl5f.fsf@gnu.org \
    --to=ludo@gnu.org \
    --cc=help-guix@gnu.org \
    --cc=raingloom@riseup.net \
    --cc=zimon.toutoune@gmail.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.