at JPR's request: modified memq to return boolean and added memq? to teaching languages

the symmetry to member/member? suggested he is correct
This commit is contained in:
Matthias Felleisen 2012-12-30 14:16:44 -05:00
parent 05ce8bce80
commit ede0e3c625
2 changed files with 20 additions and 4 deletions

View File

@ -491,12 +491,16 @@
Evaluates the number of items on a list.
@interaction[#:eval (bsl) x (length x)]
}
@defproc[(memq [x any/c][l list?]) (or/c false list?)]{
Determines whether some value is on some list if so, it produces the
suffix of the list that starts with x if not, it produces false. (It
compares values with the eq? predicate.)
@defproc[((beginner-memq memq) [x any/c][l list?]) boolean?]{
Determines whether some value @racket[x] is on some list @racket[l],
using @racket[eq?] to compare @racket[x] with items on @racket[l].
@interaction[#:eval (bsl) x (memq (list (list 1 2 3)) x)]
}
@defproc[((beginner-memq? memq?) [x any/c][l list?]) boolean?]{
Determines whether some value @racket[x] is on some list @racket[l],
using @racket[eq?] to compare @racket[x] with items on @racket[l].
@interaction[#:eval (bsl) x (memq? (list (list 1 2 3)) x)]
}
@defproc[(memv [x any/c][l list?]) (or/c false list)]{
Determines whether some value is on the list if so, it produces the
suffix of the list that starts with x if not, it produces false. (It

View File

@ -139,6 +139,16 @@ namespace.
(current-continuation-marks))))
(sqr a)))
(define-teach beginner memq
(lambda (a b)
(check-second 'memq a b)
(not (boolean? (memq a b)))))
(define-teach beginner memq?
(lambda (a b)
(check-second 'memq? a b)
(not (boolean? (memq a b)))))
(define-teach beginner member
(lambda (a b)
(check-second 'member a b)
@ -402,6 +412,8 @@ namespace.
beginner-list?
beginner-member
beginner-member?
beginner-memq
beginner-memq?
beginner-remove
beginner-cons
beginner-car