From 50c98645cadfbae9b0936a3dd7be286ff1101eec Mon Sep 17 00:00:00 2001 From: Ben Greenman Date: Mon, 2 May 2016 22:40:44 -0400 Subject: [PATCH] [list] docs, and hide map: for now --- test/list-fail.rkt | 16 ++++---- test/list-pass.rkt | 66 +++++++++++++++---------------- trivial/list.rkt | 4 +- trivial/list/no-colon.rkt | 2 +- trivial/main.rkt | 2 + trivial/private/list.rkt | 2 +- trivial/scribblings/trivial.scrbl | 48 +++++++++++++++++++--- 7 files changed, 90 insertions(+), 50 deletions(-) diff --git a/test/list-fail.rkt b/test/list-fail.rkt index 4d9a7d0..bf37753 100644 --- a/test/list-fail.rkt +++ b/test/list-fail.rkt @@ -25,19 +25,19 @@ ; (let-list: ([v2 (list v1)]) ; (list-ref: (list-ref: v2 0) 1))) - (list-ref: (map: (lambda (x) x) (list #t "ha")) 20) + ;(list-ref: (map: (lambda (x) x) (list #t "ha")) 20) (list-ref: (list 0) -5) - (list-ref: - (map: add1 (map: add1 (map: add1 (list 0 0 0)))) - 3) + ;(list-ref: + ; (map: add1 (map: add1 (map: add1 (list 0 0 0)))) + ; 3) - (list-ref: (map: symbol->string (list 'a 'b)) 5) + ;(list-ref: (map: symbol->string (list 'a 'b)) 5) - (list-ref: - (map: add1 (map: add1 (map: add1 (list 0 0 0)))) - 3) + ;(list-ref: + ; (map: add1 (map: add1 (map: add1 (list 0 0 0)))) + ; 3) (let-list: ([v (list 0 0 0)] [v2 (list 1 2)]) diff --git a/test/list-pass.rkt b/test/list-pass.rkt index 2395102..b3e6898 100644 --- a/test/list-pass.rkt +++ b/test/list-pass.rkt @@ -104,45 +104,45 @@ ;) ;(test-suite "map:" - (test-case "list/length map" - (check-equal? (map: add1 (list 1)) (list 2))) + ; (test-case "list/length map" + ; (check-equal? (map: add1 (list 1)) (list 2))) - (test-case "list/length map via let" - (check-equal? - (let-list: ([v (list (list 1) (list 2 2) - (list 3 3 3) (list 4 4 4 4))]) - (map: (lambda ([x : (Listof Any)]) (length: x)) v)) ;; dammit map - (list 1 2 3 4))) + ; (test-case "list/length map via let" + ; (check-equal? + ; (let-list: ([v (list (list 1) (list 2 2) + ; (list 3 3 3) (list 4 4 4 4))]) + ; (map: (lambda ([x : (Listof Any)]) (length: x)) v)) ;; dammit map + ; (list 1 2 3 4))) - (test-case "map^3" - (check-equal? - (map: add1 (map: add1 (map: add1 (list 0 0 0)))) - (list 3 3 3))) + ; (test-case "map^3" + ; (check-equal? + ; (map: add1 (map: add1 (map: add1 (list 0 0 0)))) + ; (list 3 3 3))) - (test-case "plain map" - (check-equal? - ((lambda ([v : (Listof (Listof Any))]) - (map: (lambda ([x : (Listof Any)]) (length: x)) v)) - (list (list 1) (list 2 2) (list 3 3 3) (list 4 4 4 4))) - (list 1 2 3 4))) + ; (test-case "plain map" + ; (check-equal? + ; ((lambda ([v : (Listof (Listof Any))]) + ; (map: (lambda ([x : (Listof Any)]) (length: x)) v)) + ; (list (list 1) (list 2 2) (list 3 3 3) (list 4 4 4 4))) + ; (list 1 2 3 4))) - (test-case "large list" - (let-list: ([v* (make-list 200 #f)]) - (check-true (for/and ([v (in-list (map: not v*))]) v)))) + ; (test-case "large list" + ; (let-list: ([v* (make-list 200 #f)]) + ; (check-true (for/and ([v (in-list (map: not v*))]) v)))) - (test-case "higher-order map pass" - (check-equal? - ((lambda ([f : (-> (-> Symbol String) (Listof Symbol) (Listof String))]) - (f symbol->string '(x yy z))) - map:) - (list "x" "yy" "z"))) + ; (test-case "higher-order map pass" + ; (check-equal? + ; ((lambda ([f : (-> (-> Symbol String) (Listof Symbol) (Listof String))]) + ; (f symbol->string '(x yy z))) + ; map:) + ; (list "x" "yy" "z"))) - (test-case "higher-order map fail" - (check-exn exn:fail:contract? - (lambda () - ((lambda ([f : (-> (-> Integer Integer) (Listof Integer) (Listof Integer))]) - (list-ref: (f add1 (list 0 0)) 3)) - map:)))) + ; (test-case "higher-order map fail" + ; (check-exn exn:fail:contract? + ; (lambda () + ; ((lambda ([f : (-> (-> Integer Integer) (Listof Integer) (Listof Integer))]) + ; (list-ref: (f add1 (list 0 0)) 3)) + ; map:)))) ;) ;(test-suite "append:" diff --git a/trivial/list.rkt b/trivial/list.rkt index 13a3151..6e9f58f 100644 --- a/trivial/list.rkt +++ b/trivial/list.rkt @@ -17,7 +17,7 @@ list-tail: append: reverse: - map: + ;map: ) ;; ----------------------------------------------------------------------------- @@ -39,5 +39,5 @@ list-tail: append: reverse: - map: + ;map: )) diff --git a/trivial/list/no-colon.rkt b/trivial/list/no-colon.rkt index bdc8a15..7d40ef6 100644 --- a/trivial/list/no-colon.rkt +++ b/trivial/list/no-colon.rkt @@ -13,7 +13,7 @@ (list-tail: list-tail) (append: append) (reverse: reverse) - (map: map) + ;(map: map) )) (require trivial/list) diff --git a/trivial/main.rkt b/trivial/main.rkt index 51de75b..9ec2560 100644 --- a/trivial/main.rkt +++ b/trivial/main.rkt @@ -4,6 +4,7 @@ (all-from-out trivial/define) (all-from-out trivial/format) (all-from-out trivial/function) + (all-from-out trivial/list) (all-from-out trivial/math) (all-from-out trivial/regexp) (all-from-out trivial/vector)) @@ -13,6 +14,7 @@ trivial/define trivial/format trivial/function + trivial/list trivial/math trivial/regexp trivial/vector) diff --git a/trivial/private/list.rkt b/trivial/private/list.rkt index 5b27461..f0fdbea 100644 --- a/trivial/private/list.rkt +++ b/trivial/private/list.rkt @@ -14,7 +14,7 @@ list-tail: append: reverse: - map: + ;map: ;andmap: ;ormap: ;for-each: diff --git a/trivial/scribblings/trivial.scrbl b/trivial/scribblings/trivial.scrbl index 5ffaf7d..ce3810f 100644 --- a/trivial/scribblings/trivial.scrbl +++ b/trivial/scribblings/trivial.scrbl @@ -174,14 +174,16 @@ When the arity of a function @racket[f] is known, we replace calls These vector operations store and update a vector's length information. @deftogether[( - @defform[(vector: e* ...)]{} - @defform[(make-vector: i e)]{} - @defform[(build-vector: i e)]{} + @defform[(vector e* ...)]{} + @defform[(make-vector i e)]{} + @defform[(build-vector i e)]{} +)]{} +@deftogether[( @defform[(vector-length: v)]{} @defform[(vector-ref: v i)]{} @defform[(vector-set!: v i k)]{} - @defform[(vector-map f v* ...)]{} - @defform[(vector-map! f v* ...)]{} + @defform[(vector-map f v)]{} + @defform[(vector-map! f v)]{} @defform[(vector-append: v1 v2)]{} @defform[(vector->list: v)]{} @defform[(vector->immutable-vector: v)]{} @@ -198,6 +200,42 @@ These vector operations store and update a vector's length information. ] + + +@section{Sized Lists} +@defmodule[trivial/list] + +Length-aware list operations. +Note that @racket[map:] is missing here --- we need to integrate with the version + from @racket[trivial/function]. + +@deftogether[( + @defform[(null)]{} + @defform[(list e* ...)]{} + @defform[(make-list i e)]{} + @defform[(build-list i e)]{} +)]{} +@deftogether[( + @defform[(pair?: l)]{} + @defform[(null?: l)]{} + @defform[(cons: x l)]{} + @defform[(car: l)]{} + @defform[(cdr: l)]{} + @defform[(list?: l)]{} + @defform[(length: l)]{} + @defform[(reverse: l)]{} + @defform[(list-ref: l i)]{} + @defform[(list-tail: l i)]{} + @;@defform[(map f l* ...)]{} + @defform[(append: l1 l2)]{} +)]{} + +@examples[#:eval trivial-eval + (car: (append: '(A) '(B))) + (car: (cdr: (cdr: (cons: 1 (cons: 2 '()))))) +] + + @section{Binding forms} @defmodule[trivial/define]