add for/set
This commit is contained in:
parent
0fe701a837
commit
ab7f9acee2
|
@ -7,7 +7,9 @@
|
||||||
set-member? set-add set-remove
|
set-member? set-add set-remove
|
||||||
set-union set-intersect set-subtract
|
set-union set-intersect set-subtract
|
||||||
set-map set-for-each
|
set-map set-for-each
|
||||||
(rename-out [*in-set in-set]))
|
(rename-out [*in-set in-set])
|
||||||
|
for/set for/seteq for/seteqv
|
||||||
|
for*/set for*/seteq for*/seteqv)
|
||||||
|
|
||||||
(define-struct set (ht)
|
(define-struct set (ht)
|
||||||
#:omit-define-syntaxes
|
#:omit-define-syntaxes
|
||||||
|
@ -206,3 +208,17 @@
|
||||||
#t
|
#t
|
||||||
;; loop args
|
;; loop args
|
||||||
((hash-iterate-next ht pos)))]])))
|
((hash-iterate-next ht pos)))]])))
|
||||||
|
|
||||||
|
(define-syntax-rule (define-for for/fold/derived for/set set)
|
||||||
|
(define-syntax (for/set stx)
|
||||||
|
(syntax-case stx ()
|
||||||
|
[(_ bindings . body)
|
||||||
|
(quasisyntax/loc stx
|
||||||
|
(for/fold/derived #,stx ([s (set)]) bindings (set-add s (let () . body))))])))
|
||||||
|
|
||||||
|
(define-for for/fold/derived for/set set)
|
||||||
|
(define-for for*/fold/derived for*/set set)
|
||||||
|
(define-for for/fold/derived for/seteq seteq)
|
||||||
|
(define-for for*/fold/derived for*/seteq seteq)
|
||||||
|
(define-for for/fold/derived for/seteqv seteqv)
|
||||||
|
(define-for for*/fold/derived for*/seteqv seteqv)
|
||||||
|
|
|
@ -109,6 +109,7 @@ Applies the procedure @scheme[proc] to each element in
|
||||||
@scheme[set] in an unspecified order, accumulating the results
|
@scheme[set] in an unspecified order, accumulating the results
|
||||||
into a list.}
|
into a list.}
|
||||||
|
|
||||||
|
|
||||||
@defproc[(set-for-each [set set?]
|
@defproc[(set-for-each [set set?]
|
||||||
[proc (any/c . -> . any)])
|
[proc (any/c . -> . any)])
|
||||||
void?]{
|
void?]{
|
||||||
|
@ -116,7 +117,21 @@ into a list.}
|
||||||
Applies @scheme[proc] to each element in @scheme[set] (for the
|
Applies @scheme[proc] to each element in @scheme[set] (for the
|
||||||
side-effects of @scheme[proc]) in an unspecified order.}
|
side-effects of @scheme[proc]) in an unspecified order.}
|
||||||
|
|
||||||
|
|
||||||
@defproc[(in-set [set set?]) sequence?]{
|
@defproc[(in-set [set set?]) sequence?]{
|
||||||
|
|
||||||
Explicitly converts a set to a sequence for use with @scheme[for] and
|
Explicitly converts a set to a sequence for use with @scheme[for] and
|
||||||
other forms.}
|
other forms.}
|
||||||
|
|
||||||
|
@deftogether[(
|
||||||
|
@defform[(for/set (for-clause ...) body ...+)]
|
||||||
|
@defform[(for/seteq (for-clause ...) body ...+)]
|
||||||
|
@defform[(for/seteqv (for-clause ...) body ...+)]
|
||||||
|
@defform[(for*/set (for-clause ...) body ...+)]
|
||||||
|
@defform[(for*/seteq (for-clause ...) body ...+)]
|
||||||
|
@defform[(for*/seteqv (for-clause ...) body ...+)]
|
||||||
|
)]{
|
||||||
|
|
||||||
|
Analogous to @scheme[for/list] and @scheme[for*/list], but to
|
||||||
|
construct a set instead of a list.}
|
||||||
|
|
||||||
|
|
|
@ -102,4 +102,8 @@
|
||||||
|
|
||||||
;; ----------------------------------------
|
;; ----------------------------------------
|
||||||
|
|
||||||
|
(test (set 1 2 3) 'for/set (for/set ([i '(0 1 2)]) (add1 i)))
|
||||||
|
|
||||||
|
;; ----------------------------------------
|
||||||
|
|
||||||
(report-errs)
|
(report-errs)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user