[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#41253] [PATCH v3] guix repl: Add script execution.
From: |
Ludovic Courtès |
Subject: |
[bug#41253] [PATCH v3] guix repl: Add script execution. |
Date: |
Fri, 05 Jun 2020 18:36:21 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
Hello Konrad,
Konrad Hinsen <konrad.hinsen@fastmail.net> skribis:
>> It cannot be used as a shebang, can it?
>
> It can. And that might be worth documenting. Here's an example:
>
> ===== File foo.scm =========================================
> #!/usr/bin/env -S guix repl
> !#
> (use-modules (ice-9 format))
>
> (format #t "foo called with arguments: ~s\n"(command-line))
> ===== End of file foo.scm ==================================
>
> hinsen@guix ~$ ~/foo.scm a b c
> ;;; note: source file /home/hinsen/temp/foo.scm
> ;;; newer than compiled
> /home/hinsen/.cache/guile/ccache/3.0-LE-8-4.2/home/hinsen/temp/foo.scm.go
> foo called with arguments: ("/home/hinsen/temp/foo.scm" "a" "b" "c")
Nice!
> The ugly part is that the script needs to be called with '–' as its
> first argument if any of the following arguments start with dashes:
>
> hinsen@guix ~$ ~/foo.scm -- --help
> ;;; note: source file /home/hinsen/temp/foo.scm
> ;;; newer than compiled
> /home/hinsen/.cache/guile/ccache/3.0-LE-8-4.2/home/hinsen/temp/foo.scm.go
> foo called with arguments: ("/home/hinsen/temp/foo.scm" "--help")
>
> That could be fixed at the price of a command line interface for "guix
> repl" that deviates a bit from Guix conventions. For example,
> is there's a file name argument, pass all arguments following it to the
> script, eliminating the need for –.
Yes, that makes sense to me.
> I'll try that in a v4, and also take into account all your remaining
> remarks. Just one note on the examples:
>
>>> +@example
>>> +$ guix repl -- my-script.scm --input=foo.txt
>>> +@end example
>>
>> I’d remove “$” from the examples.
>
> There are many examples in guix.texi with $, and also many without. Plus
> some with # as the command line prompt.
Yeah, the manual is kinda inconsistent, and I’m self-inconsistent to
tell the truth. :-)
I’ve come to the conclusion that snippets that contain only input should
be written without a prompt, for easier copy/pasting.
(I’ve seen Python documentation where JS magic allows people to toggle
prompt display, I find it nice.)
> A technical question: is there any way to suppress the error message
> about the source being newer than the cached version? This is really
> annoying when running scripts.
>
>> hinsen@guix ~$ ~/foo.scm a b c
>> ;;; note: source file /home/hinsen/temp/foo.scm
>> ;;; newer than compiled
>> /home/hinsen/.cache/guile/ccache/3.0-LE-8-4.2/home/hinsen/temp/foo.scm.go
>> foo called with arguments: ("/home/hinsen/temp/foo.scm" "a" "b" "c")
I guess ~/.cache/…/*.go exists because you first ran “guile foo.scm”,
no? In that case, you can simply remove that .go file.
The ‘guix’ command turns off auto-compilation so ‘guix repl’ scripts
would always be interpreted, for better or worse.
Thanks,
Ludo’.