[list] docs, and hide map: for now
This commit is contained in:
parent
f2c6c1e1c0
commit
50c98645ca
|
@ -25,19 +25,19 @@
|
||||||
; (let-list: ([v2 (list v1)])
|
; (let-list: ([v2 (list v1)])
|
||||||
; (list-ref: (list-ref: v2 0) 1)))
|
; (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: (list 0) -5)
|
||||||
|
|
||||||
(list-ref:
|
;(list-ref:
|
||||||
(map: add1 (map: add1 (map: add1 (list 0 0 0))))
|
; (map: add1 (map: add1 (map: add1 (list 0 0 0))))
|
||||||
3)
|
; 3)
|
||||||
|
|
||||||
(list-ref: (map: symbol->string (list 'a 'b)) 5)
|
;(list-ref: (map: symbol->string (list 'a 'b)) 5)
|
||||||
|
|
||||||
(list-ref:
|
;(list-ref:
|
||||||
(map: add1 (map: add1 (map: add1 (list 0 0 0))))
|
; (map: add1 (map: add1 (map: add1 (list 0 0 0))))
|
||||||
3)
|
; 3)
|
||||||
|
|
||||||
(let-list: ([v (list 0 0 0)]
|
(let-list: ([v (list 0 0 0)]
|
||||||
[v2 (list 1 2)])
|
[v2 (list 1 2)])
|
||||||
|
|
|
@ -104,45 +104,45 @@
|
||||||
;)
|
;)
|
||||||
|
|
||||||
;(test-suite "map:"
|
;(test-suite "map:"
|
||||||
(test-case "list/length map"
|
; (test-case "list/length map"
|
||||||
(check-equal? (map: add1 (list 1)) (list 2)))
|
; (check-equal? (map: add1 (list 1)) (list 2)))
|
||||||
|
|
||||||
(test-case "list/length map via let"
|
; (test-case "list/length map via let"
|
||||||
(check-equal?
|
; (check-equal?
|
||||||
(let-list: ([v (list (list 1) (list 2 2)
|
; (let-list: ([v (list (list 1) (list 2 2)
|
||||||
(list 3 3 3) (list 4 4 4 4))])
|
; (list 3 3 3) (list 4 4 4 4))])
|
||||||
(map: (lambda ([x : (Listof Any)]) (length: x)) v)) ;; dammit map
|
; (map: (lambda ([x : (Listof Any)]) (length: x)) v)) ;; dammit map
|
||||||
(list 1 2 3 4)))
|
; (list 1 2 3 4)))
|
||||||
|
|
||||||
(test-case "map^3"
|
; (test-case "map^3"
|
||||||
(check-equal?
|
; (check-equal?
|
||||||
(map: add1 (map: add1 (map: add1 (list 0 0 0))))
|
; (map: add1 (map: add1 (map: add1 (list 0 0 0))))
|
||||||
(list 3 3 3)))
|
; (list 3 3 3)))
|
||||||
|
|
||||||
(test-case "plain map"
|
; (test-case "plain map"
|
||||||
(check-equal?
|
; (check-equal?
|
||||||
((lambda ([v : (Listof (Listof Any))])
|
; ((lambda ([v : (Listof (Listof Any))])
|
||||||
(map: (lambda ([x : (Listof Any)]) (length: x)) v))
|
; (map: (lambda ([x : (Listof Any)]) (length: x)) v))
|
||||||
(list (list 1) (list 2 2) (list 3 3 3) (list 4 4 4 4)))
|
; (list (list 1) (list 2 2) (list 3 3 3) (list 4 4 4 4)))
|
||||||
(list 1 2 3 4)))
|
; (list 1 2 3 4)))
|
||||||
|
|
||||||
(test-case "large list"
|
; (test-case "large list"
|
||||||
(let-list: ([v* (make-list 200 #f)])
|
; (let-list: ([v* (make-list 200 #f)])
|
||||||
(check-true (for/and ([v (in-list (map: not v*))]) v))))
|
; (check-true (for/and ([v (in-list (map: not v*))]) v))))
|
||||||
|
|
||||||
(test-case "higher-order map pass"
|
; (test-case "higher-order map pass"
|
||||||
(check-equal?
|
; (check-equal?
|
||||||
((lambda ([f : (-> (-> Symbol String) (Listof Symbol) (Listof String))])
|
; ((lambda ([f : (-> (-> Symbol String) (Listof Symbol) (Listof String))])
|
||||||
(f symbol->string '(x yy z)))
|
; (f symbol->string '(x yy z)))
|
||||||
map:)
|
; map:)
|
||||||
(list "x" "yy" "z")))
|
; (list "x" "yy" "z")))
|
||||||
|
|
||||||
(test-case "higher-order map fail"
|
; (test-case "higher-order map fail"
|
||||||
(check-exn exn:fail:contract?
|
; (check-exn exn:fail:contract?
|
||||||
(lambda ()
|
; (lambda ()
|
||||||
((lambda ([f : (-> (-> Integer Integer) (Listof Integer) (Listof Integer))])
|
; ((lambda ([f : (-> (-> Integer Integer) (Listof Integer) (Listof Integer))])
|
||||||
(list-ref: (f add1 (list 0 0)) 3))
|
; (list-ref: (f add1 (list 0 0)) 3))
|
||||||
map:))))
|
; map:))))
|
||||||
;)
|
;)
|
||||||
|
|
||||||
;(test-suite "append:"
|
;(test-suite "append:"
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
list-tail:
|
list-tail:
|
||||||
append:
|
append:
|
||||||
reverse:
|
reverse:
|
||||||
map:
|
;map:
|
||||||
)
|
)
|
||||||
|
|
||||||
;; -----------------------------------------------------------------------------
|
;; -----------------------------------------------------------------------------
|
||||||
|
@ -39,5 +39,5 @@
|
||||||
list-tail:
|
list-tail:
|
||||||
append:
|
append:
|
||||||
reverse:
|
reverse:
|
||||||
map:
|
;map:
|
||||||
))
|
))
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
(list-tail: list-tail)
|
(list-tail: list-tail)
|
||||||
(append: append)
|
(append: append)
|
||||||
(reverse: reverse)
|
(reverse: reverse)
|
||||||
(map: map)
|
;(map: map)
|
||||||
))
|
))
|
||||||
(require trivial/list)
|
(require trivial/list)
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
(all-from-out trivial/define)
|
(all-from-out trivial/define)
|
||||||
(all-from-out trivial/format)
|
(all-from-out trivial/format)
|
||||||
(all-from-out trivial/function)
|
(all-from-out trivial/function)
|
||||||
|
(all-from-out trivial/list)
|
||||||
(all-from-out trivial/math)
|
(all-from-out trivial/math)
|
||||||
(all-from-out trivial/regexp)
|
(all-from-out trivial/regexp)
|
||||||
(all-from-out trivial/vector))
|
(all-from-out trivial/vector))
|
||||||
|
@ -13,6 +14,7 @@
|
||||||
trivial/define
|
trivial/define
|
||||||
trivial/format
|
trivial/format
|
||||||
trivial/function
|
trivial/function
|
||||||
|
trivial/list
|
||||||
trivial/math
|
trivial/math
|
||||||
trivial/regexp
|
trivial/regexp
|
||||||
trivial/vector)
|
trivial/vector)
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
list-tail:
|
list-tail:
|
||||||
append:
|
append:
|
||||||
reverse:
|
reverse:
|
||||||
map:
|
;map:
|
||||||
;andmap:
|
;andmap:
|
||||||
;ormap:
|
;ormap:
|
||||||
;for-each:
|
;for-each:
|
||||||
|
|
|
@ -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.
|
These vector operations store and update a vector's length information.
|
||||||
|
|
||||||
@deftogether[(
|
@deftogether[(
|
||||||
@defform[(vector: e* ...)]{}
|
@defform[(vector e* ...)]{}
|
||||||
@defform[(make-vector: i e)]{}
|
@defform[(make-vector i e)]{}
|
||||||
@defform[(build-vector: i e)]{}
|
@defform[(build-vector i e)]{}
|
||||||
|
)]{}
|
||||||
|
@deftogether[(
|
||||||
@defform[(vector-length: v)]{}
|
@defform[(vector-length: v)]{}
|
||||||
@defform[(vector-ref: v i)]{}
|
@defform[(vector-ref: v i)]{}
|
||||||
@defform[(vector-set!: v i k)]{}
|
@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-append: v1 v2)]{}
|
||||||
@defform[(vector->list: v)]{}
|
@defform[(vector->list: v)]{}
|
||||||
@defform[(vector->immutable-vector: 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}
|
@section{Binding forms}
|
||||||
@defmodule[trivial/define]
|
@defmodule[trivial/define]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user