Previous: srfi args-fold spec, Up: srfi args-fold [Index]
Short options without arguments:
(import (rnrs) (srfi :37)) (define (unrecognised-option-proc option name arg seed) (error 'test "unknown option" option name arg)) (define (make-seed) (make-vector 3 '())) (define (make-option-processor index) (lambda (option name arg seed) (vector-set! seed index (cons name (vector-ref seed index))) seed)) (define (make-operand-processor index) (lambda (operand seed) (vector-set! seed index (cons operand (vector-ref seed index))) seed)) (args-fold '("-a" "-b" "ciao") (list (option '(#\a) #f #f (make-option-processor 1)) (option '(#\b) #f #f (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(("ciao") (#\a) (#\b)) (args-fold '("salut" "-a" "hello" "-b" "ciao") (list (option '(#\a) #f #f (make-option-processor 1)) (option '(#\b) #f #f (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(("ciao" "hello" "salut") (#\a) (#\b)) (args-fold '("-ab") (list (option '(#\a) #f #f (make-option-processor 1)) (option '(#\b) #f #f (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ '#(() (#\a) (#\b))
Short options with required arguments:
(import (rnrs) (srfi :37)) (define (unrecognised-option-proc option name arg seed) (error 'test "unknown option" option name arg)) (define (make-seed) (make-vector 3 '())) (define (make-option-processor index) (lambda (option name arg seed) (vector-set! seed index (cons arg (vector-ref seed index))) seed)) (define (make-operand-processor index) (lambda (operand seed) (vector-set! seed index (cons operand (vector-ref seed index))) seed)) (args-fold '("-a" "hello" "-b" "ciao") (list (option '(#\a) #t #f (make-option-processor 1)) (option '(#\b) #t #f (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(() ("hello") ("ciao")) (args-fold '("-ahello" "-bciao") (list (option '(#\a) #t #f (make-option-processor 1)) (option '(#\b) #t #f (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(() ("hello") ("ciao")) (args-fold '("salut" "-a" "hello" "-b" "ciao") (list (option '(#\a) #t #f (make-option-processor 1)) (option '(#\b) #t #f (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(("salut") ("hello") ("ciao")) (args-fold '("-ahello" "-bciao") (list (option '(#\a) #t #f (make-option-processor 1)) (option '(#\b) #t #f (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(() ("hello") ("ciao"))
Short options with optional arguments:
(import (rnrs) (srfi :37)) (define (unrecognised-option-proc option name arg seed) (error 'test "unknown option" option name arg)) (define (make-seed) (make-vector 3 '())) (define (make-option-processor index) (lambda (option name arg seed) (vector-set! seed index (cons arg (vector-ref seed index))) seed)) (define (make-operand-processor index) (lambda (operand seed) (vector-set! seed index (cons operand (vector-ref seed index))) seed)) (args-fold '("-ahello" "-b") (list (option '(#\a) #f #t (make-option-processor 1)) (option '(#\b) #f #t (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(() ("hello") (#f))
Long options without arguments:
(import (rnrs) (srfi :37)) (define (unrecognised-option-proc option name arg seed) (error 'test "unknown option" option name arg)) (define (make-seed) (make-vector 3 '())) (define (make-option-processor index) (lambda (option name arg seed) (vector-set! seed index (cons name (vector-ref seed index))) seed)) (define (make-operand-processor index) (lambda (operand seed) (vector-set! seed index (cons operand (vector-ref seed index))) seed)) (args-fold '("--alpha" "--beta" "ciao") (list (option '("alpha") #f #f (make-option-processor 1)) (option '("beta") #f #f (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(("ciao") ("alpha") ("beta")) (args-fold '("salut" "--alpha" "hello" "--beta" "ciao") (list (option '("alpha") #f #f (make-option-processor 1)) (option '("beta") #f #f (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(("ciao" "hello" "salut") ("alpha") ("beta"))
Long options with required arguments:
(import (rnrs) (srfi :37)) (define (unrecognised-option-proc option name arg seed) (error 'test "unknown option" option name arg)) (define (make-seed) (make-vector 3 '())) (define (make-option-processor index) (lambda (option name arg seed) (vector-set! seed index (cons arg (vector-ref seed index))) seed)) (define (make-operand-processor index) (lambda (operand seed) (vector-set! seed index (cons operand (vector-ref seed index))) seed)) (args-fold '("--alpha" "hello" "--beta" "ciao") (list (option '("alpha") #t #f (make-option-processor 1)) (option '("beta") #t #f (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(() ("hello") ("ciao")) (args-fold '("salut" "--alpha" "hello" "--beta" "ciao") (list (option '("alpha") #t #f (make-option-processor 1)) (option '("beta") #t #f (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(("salut") ("hello") ("ciao"))
Long options with optional arguments:
(import (rnrs) (srfi :37)) (define (unrecognised-option-proc option name arg seed) (error 'test "unknown option" option name arg)) (define (make-seed) (make-vector 3 '())) (define (make-option-processor index) (lambda (option name arg seed) (vector-set! seed index (cons arg (vector-ref seed index))) seed)) (define (make-operand-processor index) (lambda (operand seed) (vector-set! seed index (cons operand (vector-ref seed index))) seed)) (args-fold '("--alpha=hello" "--beta") (list (option '("alpha") #f #t (make-option-processor 1)) (option '("beta") #f #t (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(() ("hello") (#f)) (args-fold '("--alpha=hello" "--beta=ciao") (list (option '("alpha") #f #t (make-option-processor 1)) (option '("beta") #f #t (make-option-processor 2))) unrecognised-option-proc (make-operand-processor 0) (make-seed)) ⇒ #(() ("hello") ("ciao"))
Previous: srfi args-fold spec, Up: srfi args-fold [Index]