unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* how to fix this G-exp?
@ 2022-09-23 17:26 zimoun
  2022-09-24 18:40 ` Csepp
  0 siblings, 1 reply; 5+ messages in thread
From: zimoun @ 2022-09-23 17:26 UTC (permalink / raw)
  To: help-guix

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-04 16:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2022-11-04 16:09       ` zimoun

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