guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How can i make executable guile file to process command line argumen


From: Olivier Dion
Subject: Re: How can i make executable guile file to process command line arguments?
Date: Thu, 18 Aug 2022 10:26:03 -0400

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 via email to

[Prev in Thread] Current Thread [Next in Thread]