Skip to content

Instantly share code, notes, and snippets.

@tyru
Created February 24, 2009 02:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyru/69349 to your computer and use it in GitHub Desktop.
Save tyru/69349 to your computer and use it in GitHub Desktop.
(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