unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: zimoun <zimon.toutoune@gmail.com>
To: help-guix <help-guix@gnu.org>
Subject: how to fix this G-exp?
Date: Fri, 23 Sep 2022 19:26:20 +0200	[thread overview]
Message-ID: <87czbm2e9v.fsf@gmail.com> (raw)

Hi,

I am missing something and I do not find my way, so maybe someone could
explain me what I am doing wrong.

Let start with this example.

--8<---------------cut here---------------start------------->8---
(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)
  42)


(define (an-example)

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

            (define that
              #+(something))

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

            (mkdir-p (dirname file-name))

            (with-output-to-file file-name
              (lambda ()
                (scm->json that)))

            ))))

  (computed-file "example-json"
                 build))

(manifest
 (list (manifest-entry
         (name "bang")
         (version "0")
         (item (an-example)))))
--8<---------------cut here---------------end--------------->8---


Then

    guix build -m /tmp/example.scm

produces something

    cat /gnu/store/zsqg38qkwhjbhfl4hkhsb4288rbnxxic-example-json/example.json
    42


Let remove the scm->json part and focus on what I do not understand:
’something’.

For instance, if instead something returns a list,

--8<---------------cut here---------------start------------->8---
--- /tmp/example.scm	2022-09-23 19:11:34.769456052 +0200
+++ /tmp/example-fail.scm	2022-09-23 19:16:30.018780090 +0200
@@ -10,7 +10,7 @@
 
 
 (define (something)
-  42)
+  (list 42))
 
 
 (define (an-example)
@@ -32,9 +32,6 @@
 
             (mkdir-p (dirname file-name))
 
-            (with-output-to-file file-name
-              (lambda ()
-                (scm->json that)))
 
             ))))
 --8<---------------cut here---------------end--------------->8---

then I get this error,

--8<---------------cut here---------------start------------->8---
Backtrace:
           3 (primitive-load "/gnu/store/vd87i0gf8f48kvcwm2c4796cmsn?")
In ice-9/eval.scm:
    619:8  2 (_ #f)
   626:19  1 (_ #<directory (guile-user) 7fffeffcfc80>)
Exception thrown while printing backtrace:
In procedure frame-local-ref: Argument 2 out of range: 1

ice-9/eval.scm:626:19: Wrong type to apply: 42
--8<---------------cut here---------------end--------------->8---

hum, maybe it is because a slice or something.  Let replace #+ by #+@
abd the backtrace is fixed.  Then, let add an item to the list,

--8<---------------cut here---------------start------------->8---
 (define (something)
-  42)
+  (list 42 43))


             (define that
-              #+(something))
+              #+@(something))
--8<---------------cut here---------------end--------------->8---

then bang

--8<---------------cut here---------------start------------->8---
ice-9/psyntax.scm:2794:12: In procedure syntax-violation:
Syntax error:
/gnu/store/zwizrn4xacyn2ynpnb5i2wgqvjj15rwa-example-json-builder:1:47: source expression failed to match any pattern in form (define that 42 43)
--8<---------------cut here---------------end--------------->8---


I would like that my procedure ’something’ returns a list, so I would
like that ’that’ would also be a list.  Because I would like to feed
scm->json with a list.

I have tried various things (list of list, slice or not, etc.) and I am
missing a point for understanding.  Could someone explain me?


Thanks in advance.


Cheers,
simon


             reply	other threads:[~2022-09-23 17:27 UTC|newest]

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

  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=87czbm2e9v.fsf@gmail.com \
    --to=zimon.toutoune@gmail.com \
    --cc=help-guix@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.
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).