From d540730a3cc94d5911d8d0469b7bf16c048e7571 Mon Sep 17 00:00:00 2001
From: Jack Firth <jackhfirth@gmail.com>
Date: Fri, 4 Dec 2015 14:40:32 -0800
Subject: [PATCH] Document lens-cond error case and improve error message

---
 unstable/lens/if.rkt   | 9 +++++++--
 unstable/lens/if.scrbl | 4 +++-
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/unstable/lens/if.rkt b/unstable/lens/if.rkt
index ce1fab7..7bd2090 100644
--- a/unstable/lens/if.rkt
+++ b/unstable/lens/if.rkt
@@ -38,11 +38,16 @@
           (λ (tgt)
             (cond [(pred tgt) (lens-view lens tgt)]
                   ...
-                  [else (error 'lens-cond "expected ~a, given: ~v" '(or/c pred-expr ...) tgt)]))
+                  [else (raise-lens-cond-error tgt 'pred-expr ...)]))
           (λ (tgt nvw)
             (cond [(pred tgt) (lens-set lens tgt nvw)]
                   ...
-                  [else (error 'lens-cond "expected ~a, given: ~v" '(or/c pred-expr ...) tgt)]))))]))
+                  [else (raise-lens-cond-error tgt 'pred-expr ...)]))))]))
+
+(define (raise-lens-cond-error tgt . pred-expr-syms)
+  (raise-arguments-error 'lens-cond "no matching clause for target"
+                         "target" tgt
+                         "expected" `(or/c ,@pred-expr-syms)))
 
 (define-syntax lens-match
   (syntax-parser
diff --git a/unstable/lens/if.scrbl b/unstable/lens/if.scrbl
index e9b391d..a2d8986 100644
--- a/unstable/lens/if.scrbl
+++ b/unstable/lens/if.scrbl
@@ -26,7 +26,8 @@ Creates a lens that uses @racket[lens1] when the target satisfies
            (lens-cond [pred-expr lens-expr] ...)]]{
 Like @racket[lens-if], but based on @racket[cond] instead of
 @racket[if]. It creates a lens that uses the first lens if the target matches the first
-predicate, the second lens if the target matches the second predicate, and so on.
+predicate, the second lens if the target matches the second predicate, and so on. If the
+target matches none of the predicates, an error is raised.
 @lens-unstable-examples[
   (define cond-lens (lens-cond [list? first-lens]
                                [vector? (vector-ref-lens 0)]
@@ -37,6 +38,7 @@ predicate, the second lens if the target matches the second predicate, and so on
   (lens-set cond-lens '(1 2 3) 'a)
   (lens-set cond-lens '#(1 2 3) 'a)
   (lens-set cond-lens "123" #\a)
+  (lens-view cond-lens 'none-of-the-above)
 ]}
 
 @defform[(lens-match [pat lens-expr] ...)]{