unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
* Error with guile function format
@ 2021-03-12 16:53 edk
  2021-03-12 17:27 ` JOULAUD François
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: edk @ 2021-03-12 16:53 UTC (permalink / raw)
  To: help-guix

Dear Guixers,

In a channel-that-should-not-be-named, there is the following snippet

           (apply invoke "7z" "e" (assoc-ref %build-inputs "patch-data")
                  (map (cut format "quake3-latest-pk3s/baseq3/pak~a.pk3" <>)
                       (iota 8 1)))

Which, as far as my limited knowledge of Guile goes, is correct.

Yet the build fail with the following error message:

In ice-9/format.scm:
     43:8  0 (format "quake3-latest-pk3s/baseq3/pak~a.pk3" 1)

ice-9/format.scm:43:8: In procedure format:
format: expected a string for format string 1


The first argument to format is a string, so I don't understand the
fuss.

Any idea would be welcome :)

Thanks !

Edouard.


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

* Re: Error with guile function format
  2021-03-12 16:53 Error with guile function format edk
@ 2021-03-12 17:27 ` JOULAUD François
  2021-03-12 17:40 ` divoplade
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: JOULAUD François @ 2021-03-12 17:27 UTC (permalink / raw)
  To: edk@beaver-labs.com; +Cc: help-guix@gnu.org

Hello,

On Fri, Mar 12, 2021 at 05:53:27PM +0100, edk@beaver-labs.com wrote:
> Yet the build fail with the following error message:
> 
> In ice-9/format.scm:
>      43:8  0 (format "quake3-latest-pk3s/baseq3/pak~a.pk3" 1)
> 
> ice-9/format.scm:43:8: In procedure format:
> format: expected a string for format string 1

> The first argument to format is a string, so I don't understand the

First argument to format should be a port[1]
or #f to return the output as a string.
In your case something like:

--8<---------------cut here---------------start------------->8---
   (format #f "mystring ~a" 1)
--8<---------------cut here---------------end--------------->8---

so your snippet should be more like:

--8<---------------cut here---------------start------------->8---
                    (map (cut format #f "quake3-latest-pk3s/baseq3/pak~a.pk3" <>)
                         (iota 8 1))
--8<---------------cut here---------------end--------------->8---


[1]: https://www.gnu.org/software/guile/manual/html_node/Formatted-Output.html#index-format-1

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

* Re: Error with guile function format
  2021-03-12 16:53 Error with guile function format edk
  2021-03-12 17:27 ` JOULAUD François
@ 2021-03-12 17:40 ` divoplade
  2021-03-12 18:23 ` Ricardo Wurmus
  2021-03-12 23:33 ` Edouard Klein
  3 siblings, 0 replies; 5+ messages in thread
From: divoplade @ 2021-03-12 17:40 UTC (permalink / raw)
  To: edk, help-guix

Le vendredi 12 mars 2021 à 17:53 +0100, edk@beaver-labs.com a écrit :
>            (apply invoke "7z" "e" (assoc-ref %build-inputs "patch-
> data")
>                   (map (cut format "quake3-latest-
> pk3s/baseq3/pak~a.pk3" <>)
>                        (iota 8 1)))

Hello Edouard,

The first argument to format is the port where to write the formatted
text to, or #f to return as a string. So you want to pass #f as the
first argument to format, unless you use srfi-28, in which case you
need to add (use-modules (srfi srfi-28))

https://www.gnu.org/software/guile/manual/guile.html#SRFI_002d28

Hope it helps you!



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

* Re: Error with guile function format
  2021-03-12 16:53 Error with guile function format edk
  2021-03-12 17:27 ` JOULAUD François
  2021-03-12 17:40 ` divoplade
@ 2021-03-12 18:23 ` Ricardo Wurmus
  2021-03-12 23:33 ` Edouard Klein
  3 siblings, 0 replies; 5+ messages in thread
From: Ricardo Wurmus @ 2021-03-12 18:23 UTC (permalink / raw)
  To: edk; +Cc: help-guix

Hi,

> (cut format "quake3-latest-pk3s/baseq3/pak~a.pk3" <>)

this is not correct.

“format” expects as its first argument a port or #true/#false, then it
takes the format string followed by values for each placeholder.

If you want to generate strings you should do

    (cut format #false "quake3-latest-pk3s/baseq3/pak~a.pk3" <>)

-- 
Ricardo


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

* Re: Error with guile function format
  2021-03-12 16:53 Error with guile function format edk
                   ` (2 preceding siblings ...)
  2021-03-12 18:23 ` Ricardo Wurmus
@ 2021-03-12 23:33 ` Edouard Klein
  3 siblings, 0 replies; 5+ messages in thread
From: Edouard Klein @ 2021-03-12 23:33 UTC (permalink / raw)
  To: help-guix

Dear François, Ricardo and divoplade,

This was indeed the issue, and the correct fix. Thank you for your
explanations. I'm not familiar with the notion of ports, coming from
languages that don't have them, but I see now how useful they are !
They're like the standard input/output of the shell, with redirections,
but for any function inside the program. Awesome :)

Thank you very much !

I've submitted a patch upstream (and also played quake 3 for the first
time in ~15 years :) oh the memories)

Cheers,

Edouard.


edk@beaver-labs.com writes:

> Dear Guixers,
>
> In a channel-that-should-not-be-named, there is the following snippet
>
>            (apply invoke "7z" "e" (assoc-ref %build-inputs "patch-data")
>                   (map (cut format "quake3-latest-pk3s/baseq3/pak~a.pk3" <>)
>                        (iota 8 1)))
>
> Which, as far as my limited knowledge of Guile goes, is correct.
>
> Yet the build fail with the following error message:
>
> In ice-9/format.scm:
>      43:8  0 (format "quake3-latest-pk3s/baseq3/pak~a.pk3" 1)
>
> ice-9/format.scm:43:8: In procedure format:
> format: expected a string for format string 1
>
>
> The first argument to format is a string, so I don't understand the
> fuss.
>
> Any idea would be welcome :)
>
> Thanks !
>
> Edouard.



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

end of thread, other threads:[~2021-03-12 23:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12 16:53 Error with guile function format edk
2021-03-12 17:27 ` JOULAUD François
2021-03-12 17:40 ` divoplade
2021-03-12 18:23 ` Ricardo Wurmus
2021-03-12 23:33 ` Edouard Klein

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