unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Olivier Dion via General Guile related discussions <guile-user@gnu.org>
To: Jacob Hrbek <kreyren@rixotstudio.cz>, guile-user@gnu.org
Subject: Re: How can i make executable guile file to process command line arguments?
Date: Thu, 18 Aug 2022 10:26:03 -0400	[thread overview]
Message-ID: <87mtc1k4qs.fsf@laura> (raw)
In-Reply-To: <6e5568cb-2924-010b-84b3-1fbf3482300b@rixotstudio.cz>

On Thu, 18 Aug 2022, Jacob Hrbek <kreyren@rixotstudio.cz> wrote:
> I have this file which i use to interact with a version controlled 
> repository similar to a Makefile.
>
> How can i make it work with e.g. `./file.scm echo wheee` -> Will execute 
> the `(define (echo msg) ...)` and output `wheee` in the terminal?

You can't directly call your command.  This is because the shebang is
fixed and thus you will always call the same procedure.  But you could
dispatch your commands in your entrypoint.

How about something like this:
--8<---------------cut here---------------start------------->8---
#!/usr/bin/env -S guile --no-auto-compile -e main -s
-*-Scheme-*-
!#

(use-modules
  (ice-9 match))

(define (echo msg)
  (display msg)
  (newline))

(define (usage prog)
  (format (current-output-port)
          "Usage: ~a COMMAND ARGS..."
          prog))

(define (main args)
  (exit
    (match (cdr args)
      (("echo" msg . rest) (echo msg) #t)
      (_ (usage (car args)) #f))))
--8<---------------cut here---------------end--------------->8---



  reply	other threads:[~2022-08-18 14:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-18 14:01 How can i make executable guile file to process command line arguments? Jacob Hrbek
2022-08-18 14:26 ` Olivier Dion via General Guile related discussions [this message]
2022-08-18 17:58 ` Zelphir Kaltstahl

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://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to=87mtc1k4qs.fsf@laura \
    --to=guile-user@gnu.org \
    --cc=kreyren@rixotstudio.cz \
    --cc=olivier.dion@polymtl.ca \
    /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).