From 2ac16f4c8218e57302dfc2415cc6e3f4d9859c82 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Fri, 10 Jul 2015 23:17:48 -0400 Subject: [PATCH 1/2] add sublist-lens --- unstable/lens/sublist.rkt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 unstable/lens/sublist.rkt diff --git a/unstable/lens/sublist.rkt b/unstable/lens/sublist.rkt new file mode 100644 index 0000000..80c87f4 --- /dev/null +++ b/unstable/lens/sublist.rkt @@ -0,0 +1,19 @@ +#lang racket/base + +(provide sublist-lens) + +(require lens/base/main + lens/list/main + ) +(module+ test + (require rackunit)) + +(define (sublist-lens i j) + (lens-thrush (take-lens j) (drop-lens i))) + +(module+ test + (check-equal? (lens-view (sublist-lens 1 4) '(0 1 2 3 4 5)) + '(1 2 3)) + (check-equal? (lens-set (sublist-lens 1 4) '(0 1 2 3 4 5) '(a b c)) + '(0 a b c 4 5)) + ) From 9382b739fe2fa166dcd0e5e1e5d921ea5cf65bb6 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Fri, 10 Jul 2015 23:32:14 -0400 Subject: [PATCH 2/2] document sublist-lens and add it to unstable/lens --- unstable/lens/main.rkt | 8 ++++++-- unstable/lens/main.scrbl | 1 + unstable/lens/sublist.scrbl | 13 +++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 unstable/lens/sublist.scrbl diff --git a/unstable/lens/main.rkt b/unstable/lens/main.rkt index b657015..3ffba54 100644 --- a/unstable/lens/main.rkt +++ b/unstable/lens/main.rkt @@ -4,10 +4,14 @@ "compound.rkt" "list.rkt" "hash.rkt" - "view-set.rkt") + "view-set.rkt" + "sublist.rkt" + ) (provide (all-from-out "syntax.rkt" "compound.rkt" "list.rkt" "hash.rkt" - "view-set.rkt")) + "view-set.rkt" + "sublist.rkt" + )) diff --git a/unstable/lens/main.scrbl b/unstable/lens/main.scrbl index 90299a2..3b525f3 100644 --- a/unstable/lens/main.scrbl +++ b/unstable/lens/main.scrbl @@ -14,3 +14,4 @@ this library being backwards-compatible. @include-section["list.scrbl"] @include-section["hash.scrbl"] @include-section["syntax.scrbl"] +@include-section["sublist.scrbl"] diff --git a/unstable/lens/sublist.scrbl b/unstable/lens/sublist.scrbl new file mode 100644 index 0000000..c78be0b --- /dev/null +++ b/unstable/lens/sublist.scrbl @@ -0,0 +1,13 @@ +#lang scribble/manual + +@(require lens/doc-util/main) + +@title{Sublist lenses} + +@defmodule[unstable/lens/sublist] + +@defproc[(sublist-lens [i exact-nonnegative-integer?] [j exact-nonnegative-integer?]) lens?]{ +@lenses-unstable-examples[ + (lens-view (sublist-lens 1 4) '(0 1 2 3 4 5)) + (lens-set (sublist-lens 1 4) '(0 1 2 3 4 5) '(a b c)) +]}