Created
February 24, 2009 02:30
-
-
Save tyru/69349 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use srfi-1) | |
(use gauche.test) | |
;; return values of pair keywords and single keywords. | |
(define (pairs&singles lis) | |
(define (loop lis pairs singles) | |
(if (null? (cdr lis)) | |
(if (and (pair? lis) (keyword? (car lis))) | |
(values (filter (lambda (elt) (not (eq? (car lis) elt))) | |
pairs) | |
(cons (car lis) singles)) | |
(values pairs singles)) | |
(cond | |
[(and (keyword? (car lis)) | |
((complement keyword?) (cadr lis))) ; pair (:key val ...) | |
(loop (cddr lis) | |
pairs | |
singles)] | |
[(and (keyword? (car lis)) | |
(keyword? (cadr lis))) ; single (:key :key ...) | |
(loop (cdr lis) | |
(filter (lambda (elt) (not (eq? (car lis) elt))) | |
pairs) | |
(cons (car lis) singles))] | |
[else (error "not keyword list" lis)]) | |
)) | |
(loop lis lis '())) | |
(define (ctrl/keyword . args) | |
(receive (args singles) (pairs&singles args) | |
(let-keywords args [(value #f) | |
; (proc (lambda (elt) elt)) | |
] | |
(when (find (cut eq :show <>) singles) | |
(print value)) | |
))) | |
(define (main args) | |
(ctrl/keyword :show) | |
(ctrl/keyword :value "hoge" :show) | |
0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment