Move list-set and list-update to unstable/list.
This commit is contained in:
parent
dc3d06c7ae
commit
6e2e84664d
|
@ -360,14 +360,4 @@
|
|||
(provide/cond-contract (struct Rep ([seq exact-nonnegative-integer?]
|
||||
[free-vars (hash/c symbol? variance?)]
|
||||
[free-idxs (hash/c symbol? variance?)]
|
||||
[stx (or/c #f syntax?)]))
|
||||
[replace-syntax (Rep? syntax? . -> . Rep?)])
|
||||
|
||||
(define (replace-field val new-val idx)
|
||||
(define-values (type skipped) (struct-info val))
|
||||
(define maker (struct-type-make-constructor type))
|
||||
(define flds (struct->list val))
|
||||
(apply maker (list-set flds idx new-val)))
|
||||
|
||||
(define (replace-syntax rep stx)
|
||||
(replace-field rep stx 3))
|
||||
[stx (or/c #f syntax?)])))
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
env? update-type/lexical env-map env-props replace-props)
|
||||
racket/contract racket/match
|
||||
unstable/struct
|
||||
unstable/list
|
||||
"tc-metafunctions.rkt"
|
||||
(for-syntax racket/base))
|
||||
|
||||
|
|
|
@ -9,9 +9,6 @@ at least theoretically.
|
|||
racket/require-syntax racket/provide-syntax
|
||||
racket/struct-info "timing.rkt")
|
||||
|
||||
;; to move to unstable
|
||||
(provide list-update list-set)
|
||||
|
||||
(provide
|
||||
;; optimization
|
||||
optimize?
|
||||
|
@ -157,16 +154,6 @@ at least theoretically.
|
|||
[(_ hd ([i c] ...) . opts)
|
||||
(define-struct hd (i ...) . opts)])))
|
||||
|
||||
(define (list-update l i f)
|
||||
(cond [(null? l) (error 'list-update "list not long enough" l i f)]
|
||||
[(zero? i) (cons (f (car l)) (cdr l))]
|
||||
[else (cons (car l) (list-update (cdr l) (sub1 i) f))]))
|
||||
|
||||
(define (list-set l k v)
|
||||
(if (zero? k)
|
||||
(cons v (cdr l))
|
||||
(cons (car l) (list-set (cdr l) (sub1 k) v))))
|
||||
|
||||
|
||||
(provide make-struct-info-self-ctor)
|
||||
;Copied from racket/private/define-struct
|
||||
|
|
|
@ -182,3 +182,23 @@
|
|||
(provide/contract
|
||||
[group-by (->* (procedure? list?) (#:key procedure?)
|
||||
list?)])
|
||||
|
||||
;; endobson added:
|
||||
|
||||
(define (list-update l i f)
|
||||
(cond
|
||||
[(zero? i) (cons (f (car l)) (cdr l))]
|
||||
[else (cons (car l) (list-update (cdr l) (sub1 i) f))]))
|
||||
|
||||
(define (list-set l k v)
|
||||
(list-update l k (lambda (_) v)))
|
||||
|
||||
(provide/contract
|
||||
[list-update (->i [(list list?)
|
||||
(index (list) (and/c (>=/c 0) (</c (length list))))
|
||||
(updater (-> any/c any/c))]
|
||||
[_ list?])]
|
||||
[list-set (->i [(list list?)
|
||||
(index (list) (and/c (>=/c 0) (</c (length list))))
|
||||
(value any/c)]
|
||||
[_ list?])])
|
||||
|
|
|
@ -175,4 +175,38 @@ determined by @racket[=?].
|
|||
}
|
||||
|
||||
|
||||
@addition{Eric Dobson}
|
||||
|
||||
|
||||
@defproc[(list-update [lst list?]
|
||||
[index (and/c (>=/c 0) (</c (length lst)))]
|
||||
[updater (-> any/c any/c)])
|
||||
list?]{
|
||||
|
||||
Returns a list that is the same as @racket[lst] except at the specified index.
|
||||
The element at the specified index is @racket[(updater (list-ref lst index))].
|
||||
|
||||
@examples[#:eval the-eval
|
||||
(list-update '(zero one two) 1 symbol->string)
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@defproc[(list-set [lst list?]
|
||||
[index (and/c (>=/c 0) (</c (length lst)))]
|
||||
[value any/c])
|
||||
list?]{
|
||||
|
||||
Returns a list that is the same as @racket[lst] except at the specified index.
|
||||
The element at the specified index is @racket[value].
|
||||
|
||||
@examples[#:eval the-eval
|
||||
(list-set '(zero one two) 2 "two")
|
||||
]
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@close-eval[the-eval]
|
||||
|
|
Loading…
Reference in New Issue
Block a user