⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 r4rstest.scm

📁 Scheme跨平台编译器
💻 SCM
📖 第 1 页 / 共 3 页
字号:
(test #f char>=? #\A #\B)(test #f char>=? #\a #\b)(test #t char>=? #\9 #\0)(test #t char>=? #\A #\A)(test #f char-ci=? #\A #\B)(test #f char-ci=? #\a #\B)(test #f char-ci=? #\A #\b)(test #f char-ci=? #\a #\b)(test #f char-ci=? #\9 #\0)(test #t char-ci=? #\A #\A)(test #t char-ci=? #\A #\a)(test #t char-ci<? #\A #\B)(test #t char-ci<? #\a #\B)(test #t char-ci<? #\A #\b)(test #t char-ci<? #\a #\b)(test #f char-ci<? #\9 #\0)(test #f char-ci<? #\A #\A)(test #f char-ci<? #\A #\a)(test #f char-ci>? #\A #\B)(test #f char-ci>? #\a #\B)(test #f char-ci>? #\A #\b)(test #f char-ci>? #\a #\b)(test #t char-ci>? #\9 #\0)(test #f char-ci>? #\A #\A)(test #f char-ci>? #\A #\a)(test #t char-ci<=? #\A #\B)(test #t char-ci<=? #\a #\B)(test #t char-ci<=? #\A #\b)(test #t char-ci<=? #\a #\b)(test #f char-ci<=? #\9 #\0)(test #t char-ci<=? #\A #\A)(test #t char-ci<=? #\A #\a)(test #f char-ci>=? #\A #\B)(test #f char-ci>=? #\a #\B)(test #f char-ci>=? #\A #\b)(test #f char-ci>=? #\a #\b)(test #t char-ci>=? #\9 #\0)(test #t char-ci>=? #\A #\A)(test #t char-ci>=? #\A #\a)(test #t char-alphabetic? #\a)(test #t char-alphabetic? #\A)(test #t char-alphabetic? #\z)(test #t char-alphabetic? #\Z)(test #f char-alphabetic? #\0)(test #f char-alphabetic? #\9)(test #f char-alphabetic? #\space)(test #f char-alphabetic? #\;)(test #f char-numeric? #\a)(test #f char-numeric? #\A)(test #f char-numeric? #\z)(test #f char-numeric? #\Z)(test #t char-numeric? #\0)(test #t char-numeric? #\9)(test #f char-numeric? #\space)(test #f char-numeric? #\;)(test #f char-whitespace? #\a)(test #f char-whitespace? #\A)(test #f char-whitespace? #\z)(test #f char-whitespace? #\Z)(test #f char-whitespace? #\0)(test #f char-whitespace? #\9)(test #t char-whitespace? #\space)(test #f char-whitespace? #\;)(test #f char-upper-case? #\0)(test #f char-upper-case? #\9)(test #f char-upper-case? #\space)(test #f char-upper-case? #\;)(test #f char-lower-case? #\0)(test #f char-lower-case? #\9)(test #f char-lower-case? #\space)(test #f char-lower-case? #\;)(test #\. integer->char (char->integer #\.))(test #\A integer->char (char->integer #\A))(test #\a integer->char (char->integer #\a))(test #\A char-upcase #\A)(test #\A char-upcase #\a)(test #\a char-downcase #\A)(test #\a char-downcase #\a)(SECTION 6 7)(test #t string? "The word \"recursion\\\" has many meanings.");(test #t string? "")(define f (make-string 3 #\*))(test "?**" 'string-set! (begin (string-set! f 0 #\?) f))(test "abc" string #\a #\b #\c)(test "" string)(test 3 string-length "abc")(test #\a string-ref "abc" 0)(test #\c string-ref "abc" 2)(test 0 string-length "")(test "" substring "ab" 0 0)(test "" substring "ab" 1 1)(test "" substring "ab" 2 2)(test "a" substring "ab" 0 1)(test "b" substring "ab" 1 2)(test "ab" substring "ab" 0 2)(test "foobar" string-append "foo" "bar")(test "foo" string-append "foo")(test "foo" string-append "foo" "")(test "foo" string-append "" "foo")(test "" string-append)(test "" make-string 0)(test #t string=? "" "")(test #f string<? "" "")(test #f string>? "" "")(test #t string<=? "" "")(test #t string>=? "" "")(test #t string-ci=? "" "")(test #f string-ci<? "" "")(test #f string-ci>? "" "")(test #t string-ci<=? "" "")(test #t string-ci>=? "" "")(test #f string=? "A" "B")(test #f string=? "a" "b")(test #f string=? "9" "0")(test #t string=? "A" "A")(test #t string<? "A" "B")(test #t string<? "a" "b")(test #f string<? "9" "0")(test #f string<? "A" "A")(test #f string>? "A" "B")(test #f string>? "a" "b")(test #t string>? "9" "0")(test #f string>? "A" "A")(test #t string<=? "A" "B")(test #t string<=? "a" "b")(test #f string<=? "9" "0")(test #t string<=? "A" "A")(test #f string>=? "A" "B")(test #f string>=? "a" "b")(test #t string>=? "9" "0")(test #t string>=? "A" "A")(test #f string-ci=? "A" "B")(test #f string-ci=? "a" "B")(test #f string-ci=? "A" "b")(test #f string-ci=? "a" "b")(test #f string-ci=? "9" "0")(test #t string-ci=? "A" "A")(test #t string-ci=? "A" "a")(test #t string-ci<? "A" "B")(test #t string-ci<? "a" "B")(test #t string-ci<? "A" "b")(test #t string-ci<? "a" "b")(test #f string-ci<? "9" "0")(test #f string-ci<? "A" "A")(test #f string-ci<? "A" "a")(test #f string-ci>? "A" "B")(test #f string-ci>? "a" "B")(test #f string-ci>? "A" "b")(test #f string-ci>? "a" "b")(test #t string-ci>? "9" "0")(test #f string-ci>? "A" "A")(test #f string-ci>? "A" "a")(test #t string-ci<=? "A" "B")(test #t string-ci<=? "a" "B")(test #t string-ci<=? "A" "b")(test #t string-ci<=? "a" "b")(test #f string-ci<=? "9" "0")(test #t string-ci<=? "A" "A")(test #t string-ci<=? "A" "a")(test #f string-ci>=? "A" "B")(test #f string-ci>=? "a" "B")(test #f string-ci>=? "A" "b")(test #f string-ci>=? "a" "b")(test #t string-ci>=? "9" "0")(test #t string-ci>=? "A" "A")(test #t string-ci>=? "A" "a")(SECTION 6 8)(test #t vector? '#(0 (2 2 2 2) "Anna"));(test #t vector? '#())(test '#(a b c) vector 'a 'b 'c)(test '#() vector)(test 3 vector-length '#(0 (2 2 2 2) "Anna"))(test 0 vector-length '#())(test 8 vector-ref '#(1 1 2 3 5 8 13 21) 5)(test '#(0 ("Sue" "Sue") "Anna") 'vector-set	(let ((vec (vector 0 '(2 2 2 2) "Anna")))	  (vector-set! vec 1 '("Sue" "Sue"))	  vec))(test '#(hi hi) make-vector 2 'hi)(test '#() make-vector 0)(test '#() make-vector 0 'a)(SECTION 6 9)(test #t procedure? car);(test #f procedure? 'car)(test #t procedure? (lambda (x) (* x x)))(test #f procedure? '(lambda (x) (* x x)))(test #t call-with-current-continuation procedure?)(test 7 apply + (list 3 4))(test 7 apply (lambda (a b) (+ a b)) (list 3 4))(test 17 apply + 10 (list 3 4))(test '() apply list '())(define compose (lambda (f g) (lambda args (f (apply g args)))))(test 30 (compose sqt *) 12 75)(test '(b e h) map cadr '((a b) (d e) (g h)))(test '(5 7 9) map + '(1 2 3) '(4 5 6))(test '(1 2 3) map + '(1 2 3))(test '(1 2 3) map * '(1 2 3))(test '(-1 -2 -3) map - '(1 2 3))(test '#(0 1 4 9 16) 'for-each      (let ((v (make-vector 5)))	(for-each (lambda (i) (vector-set! v i (* i i)))		  '(0 1 2 3 4))	v))(test -3 call-with-current-continuation      (lambda (exit)	(for-each (lambda (x) (if (negative? x) (exit x)))		  '(54 0 37 -3 245 19))	#t))(define list-length (lambda (obj)  (call-with-current-continuation   (lambda (return)    (letrec ((r (lambda (obj) (cond ((null? obj) 0)				((pair? obj) (+ (r (cdr obj)) 1))				(else (return #f))))))	(r obj))))))(test 4 list-length '(1 2 3 4))(test #f list-length '(a b . c))(test '() map cadr '());;; This tests full conformance of call-with-current-continuation.  It;;; is a separate test because some schemes do not support call/cc;;; other than escape procedures.  I am indebted to;;; raja@copper.ucs.indiana.edu (Raja Sooriamurthi) for fixing this;;; code.  The function leaf-eq? compares the leaves of 2 arbitrary;;; trees constructed of conses.(define (next-leaf-generator obj eot)  (letrec ((return #f)	   (cont (lambda (x)		   (recur obj)		   (set! cont (lambda (x) (return eot)))		   (cont #f)))	   (recur (lambda (obj)		      (if (pair? obj)			  (for-each recur obj)			  (call-with-current-continuation			   (lambda (c)			     (set! cont c)			     (return obj)))))))    (lambda () (call-with-current-continuation		(lambda (ret) (set! return ret) (cont #f))))))(define (leaf-eq? x y)  (let* ((eot (list 'eot))	 (xf (next-leaf-generator x eot))	 (yf (next-leaf-generator y eot)))    (letrec ((loop (lambda (x y)		     (cond ((not (eq? x y)) #f)			   ((eq? eot x) #t)			   (else (loop (xf) (yf)))))))      (loop (xf) (yf)))))(define (test-cont)  (newline)  (display ";testing continuations; ")  (newline)  (SECTION 6 9)  (test #t leaf-eq? '(a (b (c))) '((a) b c))  (test #f leaf-eq? '(a (b (c))) '((a) b c d))  (report-errs));;; Test Optional R4RS DELAY syntax and FORCE procedure(define (test-delay)  (newline)  (display ";testing DELAY and FORCE; ")  (newline)  (SECTION 6 9)  (test 3 'delay (force (delay (+ 1 2))))  (test '(3 3) 'delay (let ((p (delay (+ 1 2))))			(list (force p) (force p))))  (test 2 'delay (letrec ((a-stream			   (letrec ((next (lambda (n)					    (cons n (delay (next (+ n 1)))))))			     (next 0)))			  (head car)			  (tail (lambda (stream) (force (cdr stream)))))		   (head (tail (tail a-stream)))))  (letrec ((count 0)	   (p (delay (begin (set! count (+ count 1))			    (if (> count x)				count				(force p)))))	   (x 5))    (test 6 force p)    (set! x 10)    (test 6 force p))  (test 3 'force	(letrec ((p (delay (if c 3 (begin (set! c #t) (+ (force p) 1)))))		 (c #f))	  (force p)))  (report-errs))(SECTION 6 10 1)(test #t input-port? (current-input-port))(test #t output-port? (current-output-port))(test #t call-with-input-file "r4rstest.scm" input-port?)(define this-file (open-input-file "r4rstest.scm"))(test #t input-port? this-file)(SECTION 6 10 2)(test #\; peek-char this-file)(test #\; read-char this-file)(test '(define cur-section '()) read this-file)(test #\( peek-char this-file)(test '(define errs '()) read this-file)(close-input-port this-file)(close-input-port this-file)(define (check-test-file name)  (define test-file (open-input-file name))  (test #t 'input-port?	(call-with-input-file	    name	  (lambda (test-file)	    (test load-test-obj read test-file)	    (test #t eof-object? (peek-char test-file))	    (test #t eof-object? (read-char test-file))	    (input-port? test-file))))  (test #\; read-char test-file)  (test #\; read-char test-file)  (test #\; read-char test-file)  (test write-test-obj read test-file)  (test load-test-obj read test-file)  (close-input-port test-file))(SECTION 6 10 3)(define write-test-obj  '(#t #f a () 9739 -3 . #((test) "te \" \" st" "" test #() b c)))(define load-test-obj  (list 'define 'foo (list 'quote write-test-obj)))(test #t call-with-output-file      "tmp1"      (lambda (test-file)	(write-char #\; test-file)	(display #\; test-file)	(display ";" test-file)	(write write-test-obj test-file)	(newline test-file)	(write load-test-obj test-file)	(output-port? test-file)))(check-test-file "tmp1")(define test-file (open-output-file "tmp2"))(write-char #\; test-file)(display #\; test-file)(display ";" test-file)(write write-test-obj test-file)(newline test-file)(write load-test-obj test-file)(test #t output-port? test-file)(close-output-port test-file)(check-test-file "tmp2")(define (test-sc4)  (newline)  (display ";testing scheme 4 functions; ")  (newline)  (SECTION 6 7)  (test '(#\P #\space #\l) string->list "P l")  (test '() string->list "")  (test "1\\\"" list->string '(#\1 #\\ #\"))  (test "" list->string '())  (SECTION 6 8)  (test '(dah dah didah) vector->list '#(dah dah didah))  (test '() vector->list '#())  (test '#(dididit dah) list->vector '(dididit dah))  (test '#() list->vector '())  (SECTION 6 10 4)  (load "tmp1")  (test write-test-obj 'load foo)  (report-errs))(report-errs)(let ((have-inexacts?       (and (string->number "0.0") (inexact? (string->number "0.0"))))      (have-bignums?       (let ((n (string->number "281474976710655325431")))	 (and n (exact? n)))))  (cond (have-inexacts?	 (test-inexact)	 (test-inexact-printing)))  (if have-bignums? (test-bignum))  (if (and have-inexacts? have-bignums?)      (test-numeric-predicates)))(newline)(display "To fully test continuations, Scheme 4, and DELAY/FORCE do:")(newline)(display "(test-cont) (test-sc4) (test-delay)")(newline)(test-cont)(test-sc4)(test-delay)"last item in file"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -