# handling command-line arguments there is the procedure [program-arguments](https://www.gnu.org/software/guile/manual/html_node/Runtime-Environment.html#index-program_002darguments) that gives a list of the arguments given to the executed file or script. the first argument by convention is the name of the executed script file. for command-line interfaces with option parsing, i recommend [args-fold](https://www.gnu.org/software/guile/manual/html_node/SRFI_002d37.html#index-args_002dfold) (or, even better: [(sph cli)](/computer/software/sph-lib/cli.html), which is based on args-fold), it is powerful and fun to use. for how to use args-fold, see the example below. there is also [getopt-long](https://www.gnu.org/software/guile/manual/html_node/getopt_002dlong-Reference.html#getopt_002dlong-Reference) with fewer capabilities. # program-arguments example the following binds the list of script arguments to variables in a file named `test` ~~~ #!/usr/bin/guile !# (apply (lambda* (path #:optional target) #t) (cdr (program-arguments))) ~~~ ~~~ chmod +x test ./test mypath mytarget ~~~ # args-fold usage example ~~~ (use-modules (srfi srfi-37)) ; since this prepends, the result will be in reverse order. (define (unnamed-processor a result) (cons a result)) (define (unrecognized-processor opt name a result) (display (string-append "unsupported option: " (if (char? name) (list->string (list name)) name) "\n")) (exit)) (define (help-processor opt name arg result) (display "usage: xy...\n") (exit 0)) (define (dry-run-processor opt name arg result) (cons (cons name #t) result)) (define arguments (cdr (program-arguments))) (define result (list)) (define af-options ; option :: names is-required-arg is-optional-arg processor (list (option (list #\h "help") #f #f help-processor) (option (list "dry-run") #f #f dry-run-processor))) (define parsed-options (reverse (args-fold arguments af-options unrecognized-processor unnamed-processor result))) (write parsed-options) (newline) ~~~