add list? to ISL+, Racket; Closes PR14103
This commit is contained in:
parent
390e052592
commit
63c27e218d
|
@ -65,6 +65,7 @@
|
||||||
(begin)
|
(begin)
|
||||||
(all-from beginner: lang/private/intermediate-funs procedures))
|
(all-from beginner: lang/private/intermediate-funs procedures))
|
||||||
|
|
||||||
|
#;
|
||||||
(provide
|
(provide
|
||||||
(rename-out
|
(rename-out
|
||||||
[beginner-list? list?]))
|
[beginner-list? list?]))
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
"../posn.rkt"
|
"../posn.rkt"
|
||||||
(for-syntax scheme/base))
|
(for-syntax scheme/base))
|
||||||
|
|
||||||
|
(define advanced-list? list?)
|
||||||
|
|
||||||
;; Documents the procedures:
|
;; Documents the procedures:
|
||||||
(require "provide-and-scribble.rkt")
|
(require "provide-and-scribble.rkt")
|
||||||
|
|
||||||
|
@ -94,7 +96,8 @@
|
||||||
(display 'hello)]
|
(display 'hello)]
|
||||||
}
|
}
|
||||||
@defproc[(write [x any]) void]{
|
@defproc[(write [x any]) void]{
|
||||||
Prints the argument to stdout (in a traditional style that is somewhere between @racket[print] and @racket[display]).
|
Prints the argument to stdout (in a traditional style that is somewhere
|
||||||
|
between @racket[print] and @racket[display]).
|
||||||
@interaction[#:eval (asl)
|
@interaction[#:eval (asl)
|
||||||
(write 10)
|
(write 10)
|
||||||
(write "hello")
|
(write "hello")
|
||||||
|
@ -118,10 +121,10 @@
|
||||||
Reads input from the user.})
|
Reads input from the user.})
|
||||||
|
|
||||||
("Lists"
|
("Lists"
|
||||||
@defproc[(list? [x any]) boolean]{
|
; @defproc[((advanced-list? list?) [x any]) boolean]{
|
||||||
Determines whether some value is a list.
|
; Determines whether some value is a list.
|
||||||
In ASL, @racket[list?] also deals with cyclic lists.
|
; In ASL, @racket[list?] also deals with cyclic lists.
|
||||||
}
|
; }
|
||||||
@defproc[((advanced-list* list*) [x any] ... [l (listof any)]) (listof any)]{
|
@defproc[((advanced-list* list*) [x any] ... [l (listof any)]) (listof any)]{
|
||||||
Constructs a list by adding multiple items to a list.
|
Constructs a list by adding multiple items to a list.
|
||||||
In ASL, @racket[list*] also deals with cyclic lists.
|
In ASL, @racket[list*] also deals with cyclic lists.
|
||||||
|
|
|
@ -52,7 +52,13 @@
|
||||||
In ISL and up: @racket[append] also works when applied to one list or none.
|
In ISL and up: @racket[append] also works when applied to one list or none.
|
||||||
@interaction[#:eval (isl)
|
@interaction[#:eval (isl)
|
||||||
(append (cons 1 (cons 2 empty)) (cons "a" (cons "b" empty)))
|
(append (cons 1 (cons 2 empty)) (cons "a" (cons "b" empty)))
|
||||||
(append)]})
|
(append)]}
|
||||||
|
@defproc[((beginner-list? list?) [x any]) boolean?]{
|
||||||
|
Checks whether the given value is a list.
|
||||||
|
@interaction[#:eval (isl)
|
||||||
|
(list? 42)
|
||||||
|
(list? (cons 1 (cons 2 empty)))]}
|
||||||
|
)
|
||||||
|
|
||||||
("Higher-Order Functions"
|
("Higher-Order Functions"
|
||||||
@defproc[(map [f (X ... -> Z)] [l (listof X)] ...) (listof Z)]{
|
@defproc[(map [f (X ... -> Z)] [l (listof X)] ...) (listof Z)]{
|
||||||
|
|
|
@ -265,11 +265,13 @@ namespace.
|
||||||
(define (tequal? x y epsilon)
|
(define (tequal? x y epsilon)
|
||||||
(let ([union-equal!? (make-union-equal!?)]
|
(let ([union-equal!? (make-union-equal!?)]
|
||||||
[fail (lambda (fmt arg)
|
[fail (lambda (fmt arg)
|
||||||
(raise (make-exn:fail:contract (if (or (eq? arg x)
|
(raise
|
||||||
(eq? arg y))
|
(make-exn:fail:contract
|
||||||
(format fmt arg)
|
(if (or (eq? arg x)
|
||||||
(format "~a (originally comparing ~e and ~e)" (format fmt arg) x y))
|
(eq? arg y))
|
||||||
(current-continuation-marks))))])
|
(format fmt arg)
|
||||||
|
(format "~a (originally comparing ~e and ~e)" (format fmt arg) x y))
|
||||||
|
(current-continuation-marks))))])
|
||||||
(let ? ([a x][b y])
|
(let ? ([a x][b y])
|
||||||
(cond
|
(cond
|
||||||
[(number? a)
|
[(number? a)
|
||||||
|
@ -285,11 +287,13 @@ namespace.
|
||||||
(define (teach-equal? x y)
|
(define (teach-equal? x y)
|
||||||
|
|
||||||
(let ([fail (lambda (fmt arg)
|
(let ([fail (lambda (fmt arg)
|
||||||
(raise (make-exn:fail:contract (if (or (eq? arg x)
|
(raise
|
||||||
(eq? arg y))
|
(make-exn:fail:contract
|
||||||
(format fmt arg)
|
(if (or (eq? arg x)
|
||||||
(format "~a (originally comparing ~e and ~e)" (format fmt arg) x y))
|
(eq? arg y))
|
||||||
(current-continuation-marks))))]
|
(format fmt arg)
|
||||||
|
(format "~a (originally comparing ~e and ~e)" (format fmt arg) x y))
|
||||||
|
(current-continuation-marks))))]
|
||||||
[union-equal!? (make-union-equal!?)])
|
[union-equal!? (make-union-equal!?)])
|
||||||
|
|
||||||
(let recur ([a x] [b y])
|
(let recur ([a x] [b y])
|
||||||
|
@ -349,7 +353,8 @@ namespace.
|
||||||
(define-teach intermediate build-string
|
(define-teach intermediate build-string
|
||||||
(lambda (n f)
|
(lambda (n f)
|
||||||
(unless (and (procedure? f) (procedure-arity-includes? f 1))
|
(unless (and (procedure? f) (procedure-arity-includes? f 1))
|
||||||
(hocheck 'build-string "second argument must be a function that accepts one argument, given ~e" f))
|
(hocheck 'build-string
|
||||||
|
"second argument must be a function that accepts one argument, given ~e" f))
|
||||||
(unless (and (number? n) (integer? n) (>= n 0))
|
(unless (and (number? n) (integer? n) (>= n 0))
|
||||||
(hocheck 'build-string "first argument must be a natural number, given ~e" n))
|
(hocheck 'build-string "first argument must be a natural number, given ~e" n))
|
||||||
(build-string n (lambda (i)
|
(build-string n (lambda (i)
|
||||||
|
@ -466,7 +471,9 @@ namespace.
|
||||||
(unless (list? s) (err tag "expected a ~a, but received: ~e" 1-LETTER* s))
|
(unless (list? s) (err tag "expected a ~a, but received: ~e" 1-LETTER* s))
|
||||||
(for-each
|
(for-each
|
||||||
(lambda (c)
|
(lambda (c)
|
||||||
(unless (string? c) (err tag "expected a ~a, but received: ~e\n which contains the non-1-letter string: ~e" 1-LETTER* s c)))
|
(unless (string? c)
|
||||||
|
(err tag "expected a ~a, but received: ~e\n which contains the non-1-letter string: ~e"
|
||||||
|
1-LETTER* s c)))
|
||||||
s)
|
s)
|
||||||
(andmap (compose (curry = 1) string-length) s))
|
(andmap (compose (curry = 1) string-length) s))
|
||||||
|
|
||||||
|
@ -485,11 +492,13 @@ namespace.
|
||||||
[(tag check-result format-msg actual)
|
[(tag check-result format-msg actual)
|
||||||
(unless check-result
|
(unless check-result
|
||||||
(displayln `(cerr ,actual))
|
(displayln `(cerr ,actual))
|
||||||
(err tag (string-append "expected " (a-or-an format-msg) " " format-msg ", but received ~e") actual))]
|
(err tag (string-append "expected " (a-or-an format-msg) " " format-msg ", but received ~e")
|
||||||
|
actual))]
|
||||||
[(tag check-result format-msg actual snd)
|
[(tag check-result format-msg actual snd)
|
||||||
(unless check-result
|
(unless check-result
|
||||||
(err tag (string-append "expected " (a-or-an format-msg) " " format-msg " for the ~a argument, but received ~e")
|
(define a (a-or-an format-msg))
|
||||||
snd actual))]))
|
(define f (string-append "expected " a " " format-msg " for the ~a argument, but received ~e"))
|
||||||
|
(err tag f snd actual))]))
|
||||||
|
|
||||||
;; -----------------------------------------------------------------------------
|
;; -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user