From 41a64cbbd8af87ba48da3f4206ed0ea8cda2c2c7 Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Wed, 25 Jan 2012 16:08:48 -0700 Subject: [PATCH] Dealing properly with rest args in svn-style commands --- collects/planet/private/command.rkt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/collects/planet/private/command.rkt b/collects/planet/private/command.rkt index 4484de79bf..75661741f7 100644 --- a/collects/planet/private/command.rkt +++ b/collects/planet/private/command.rkt @@ -58,7 +58,7 @@ body ... #:handlers (λ (_ . formals) final-expr) - (pimap symbol->string 'formals) + (ensure-list (pimap symbol->string 'formals)) (λ (help-string) (for-each (λ (l) (display l) (newline)) (wrap-to-count long-description 80)) (newline) @@ -98,13 +98,18 @@ [extra (build-string (- n l) (λ (n) #\space))]) (string-append str extra))) +(define (ensure-list x) + (if (or (null? x) (pair? x)) + x + (list x))) + ;; pimap : (A -> B) improper-listof A -> improper-listof B (define (pimap f pil) (cond [(null? pil) '()] [(pair? pil) (cons (pimap f (car pil)) (pimap f (cdr pil)))] - [else (list (f pil))])) + [else (f pil)])) ;; wrap-to-count : string nat -> (listof string) ;; breaks str into substrings such that no substring