From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Dion via General Guile related discussions Newsgroups: gmane.lisp.guile.user Subject: Re: How can i make executable guile file to process command line arguments? Date: Thu, 18 Aug 2022 10:26:03 -0400 Message-ID: <87mtc1k4qs.fsf@laura> References: <6e5568cb-2924-010b-84b3-1fbf3482300b@rixotstudio.cz> Reply-To: Olivier Dion Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22611"; mail-complaints-to="usenet@ciao.gmane.io" To: Jacob Hrbek , guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Thu Aug 18 16:27:07 2022 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oOgUF-0005fj-68 for guile-user@m.gmane-mx.org; Thu, 18 Aug 2022 16:27:07 +0200 Original-Received: from localhost ([::1]:43520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oOgUE-0001RY-5k for guile-user@m.gmane-mx.org; Thu, 18 Aug 2022 10:27:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58748) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOgTS-0000g2-8p for guile-user@gnu.org; Thu, 18 Aug 2022 10:26:18 -0400 Original-Received: from smtp.polymtl.ca ([132.207.4.11]:48219) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oOgTP-00046W-Ls for guile-user@gnu.org; Thu, 18 Aug 2022 10:26:17 -0400 Original-Received: from localhost (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 27IEQ3XB011432; Thu, 18 Aug 2022 10:26:08 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 27IEQ3XB011432 In-Reply-To: <6e5568cb-2924-010b-84b3-1fbf3482300b@rixotstudio.cz> X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Thu, 18 Aug 2022 14:26:03 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:18524 Archived-At: On Thu, 18 Aug 2022, Jacob Hrbek 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---