|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-module (test-suite r7rs) |
|
|
|
|
|
define-syntax-rule quote read-disable |
|
import)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(install-r7rs!) |
|
(define-syntax-rule (undo-install-r7rs!) |
|
(begin |
|
(read-disable 'r7rs-symbols) |
|
(read-disable 'r6rs-hex-escapes) |
|
(read-disable 'hungry-eol-escapes))) |
|
|
|
(import (scheme base) (scheme char) (scheme lazy) |
|
(scheme inexact) (scheme complex) (scheme time) |
|
(scheme file) (scheme read) (scheme write) |
|
(scheme eval) (scheme process-context) (scheme case-lambda) |
|
(only (scheme r5rs) null-environment interaction-environment)) |
|
|
|
|
|
|
|
(define-syntax-rule (test-begin . _) |
|
(define-syntax-rule (test-end . _) |
|
|
|
(define (%test-equal? expr expected) |
|
(if (and (number? expr) (number? expected) |
|
(inexact? expr) (inexact? expected)) |
|
(if (and (real? expr) (real? expected)) |
|
(<= (- expected 1.0e-5) expr (+ expected 1.0e-5)) |
|
(and (%test-equal? (real-part expr) (real-part expected)) |
|
(%test-equal? (imag-part expr) (imag-part expected)))) |
|
(equal? expr expected))) |
|
|
|
(define-syntax-rule (test expected expr) |
|
(pass-if (%test-equal? expr expected))) |
|
|
|
|
|
(define-syntax-rule (failing-test url expected expr) |
|
(expect-fail url (%test-equal? expr expected))) |
|
(define-syntax-rule (failing-test-with-exception url expected expr) |
|
(expect-fail url (guard (exn (else |
|
(%test-equal? expr expected)))) |
|
|
|
(define-syntax-rule (test-values expected expr) |
|
(pass-if-equal (call-with-values (lambda () expected) list) |
|
(call-with-values (lambda () expr) list))) |
|
|
|
(define-syntax-rule (test-error expr) |
|
(pass-if (guard (exn (else |
|
expr |
|
|
|
|
|
(define-syntax-rule (test-assert str expr) |
|
(pass-if str expr)) |
|
|
|
|
|
|
|
(test-begin "R7RS") |
|
|
|
(test-begin "4.1 Primitive expression types") |
|
|
|
(let () |
|
(define x 28) |
|
(test 28 x)) |
|
|
|
(test 'a (quote a)) |
|
|
|
(test '(+ 1 2) (quote (+ 1 2))) |
|
|
|
(test 'a 'a) |
|
|
|
(test '() '()) |
|
(test '(+ 1 2) '(+ 1 2)) |
|
(test '(quote a) '(quote a)) |
|
(test '(quote a) ''a) |
|
|
|
(test "abc" '"abc") |
|
(test "abc" "abc") |
|
(test 145932 '145932) |
|
(test 145932 145932) |
|
(test |
|
(test |
|
|
|
(test 7 (+ 3 4)) |
|
(test 12 ((if |
|
|
|
(test 8 ((lambda (x) (+ x x)) 4)) |
|
(define reverse-subtract |
|
(lambda (x y) (- y x))) |
|
(test 3 (reverse-subtract 7 10)) |
|
(define add4 |
|
(let ((x 4)) |
|
(lambda (y) (+ x y)))) |
|
(test 10 (add4 6)) |
|
|
|
(test '(3 4 5 6) ((lambda x x) 3 4 5 6)) |
|
(test '(5 6) ((lambda (x y . z) z) |
|
3 4 5 6)) |
|
|
|
(test 'yes (if (> 3 2) 'yes 'no)) |
|
(test 'no (if (> 2 3) 'yes 'no)) |
|
(test 1 (if (> 3 2) |
|
(- 3 2) |
|
(+ 3 2))) |
|
(let () |
|
(define x 2) |
|
(test 3 (+ x 1))) |
|
|
|
(test-end) |
|
|
|
(test-begin "4.2 Derived expression types") |
|
|
|
(test 'greater |
|
(cond ((> 3 2) 'greater) |
|
((< 3 2) 'less))) |
|
|
|
(test 'equal |
|
(cond ((> 3 3) 'greater) |
|
((< 3 3) 'less) |
|
(else 'equal))) |
|
|
|
(test 2 |
|
(cond ((assv 'b '((a 1) (b 2))) => cadr) |
|
(else |
|
|
|
(test 'composite |
|
(case (* 2 3) |
|
((2 3 5 7) 'prime) |
|
((1 4 6 8 9) 'composite))) |
|
|
|
(test 'c |
|
(case (car '(c d)) |
|
((a e i o u) 'vowel) |
|
((w y) 'semivowel) |
|
(else => (lambda (x) x)))) |
|
|
|
(test '((other . z) (semivowel . y) (other . x) |
|
(semivowel . w) (vowel . u)) |
|
(map (lambda (x) |
|
(case x |
|
((a e i o u) => (lambda (w) (cons 'vowel w))) |
|
((w y) (cons 'semivowel x)) |
|
(else => (lambda (w) (cons 'other w))))) |
|
'(z y x w u))) |
|
|
|
(test |
|
(test |
|
(test '(f g) (and 1 2 'c '(f g))) |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test '(b c) (or (memq 'b '(a b c)) |
|
(/ 3 0))) |
|
|
|
(test 6 (let ((x 2) (y 3)) |
|
(* x y))) |
|
|
|
(test 35 (let ((x 2) (y 3)) |
|
(let ((x 7) |
|
(z (+ x y))) |
|
(* z x)))) |
|
|
|
(test 70 (let ((x 2) (y 3)) |
|
(let* ((x 7) |
|
(z (+ x y))) |
|
(* z x)))) |
|
|
|
(test |
|
(letrec ((even? |
|
(lambda (n) |
|
(if (zero? n) |
|
|
|
(odd? (- n 1))))) |
|
(odd? |
|
(lambda (n) |
|
(if (zero? n) |
|
|
|
(even? (- n 1)))))) |
|
(even? 88))) |
|
|
|
(test 5 |
|
(letrec* ((p |
|
(lambda (x) |
|
(+ 1 (q (- x 1))))) |
|
(q |
|
(lambda (y) |
|
(if (zero? y) |
|
0 |
|
(+ 1 (p (- y 1)))))) |
|
(x (p 5)) |
|
(y x)) |
|
y)) |
|
|
|
|
|
|
|
|
|
(define (means ton) |
|
(letrec* |
|
((mean |
|
(lambda (f g) |
|
(f (/ (sum g ton) n)))) |
|
(sum |
|
(lambda (g ton) |
|
(if (null? ton) |
|
(+) |
|
(if (number? ton) |
|
(g ton) |
|
(+ (sum g (car ton)) |
|
(sum g (cdr ton))))))) |
|
(n (sum (lambda (x) 1) ton))) |
|
(values (mean values values) |
|
(mean exp log) |
|
(mean / /)))) |
|
(let*-values (((a b c) (means '(8 5 99 1 22)))) |
|
(test 27 a) |
|
(test 9.728 b) |
|
(test 1800/497 c)) |
|
|
|
(let*-values (((root rem) (exact-integer-sqrt 32))) |
|
(test 35 (* root rem))) |
|
|
|
(test '(1073741824 0) |
|
(let*-values (((root rem) (exact-integer-sqrt (expt 2 60)))) |
|
(list root rem))) |
|
|
|
(test '(1518500249 3000631951) |
|
(let*-values (((root rem) (exact-integer-sqrt (expt 2 61)))) |
|
(list root rem))) |
|
|
|
(test '(815238614083298888 443242361398135744) |
|
(let*-values (((root rem) (exact-integer-sqrt (expt 2 119)))) |
|
(list root rem))) |
|
|
|
(test '(1152921504606846976 0) |
|
(let*-values (((root rem) (exact-integer-sqrt (expt 2 120)))) |
|
(list root rem))) |
|
|
|
(test '(1630477228166597776 1772969445592542976) |
|
(let*-values (((root rem) (exact-integer-sqrt (expt 2 121)))) |
|
(list root rem))) |
|
|
|
(test '(31622776601683793319 62545769258890964239) |
|
(let*-values (((root rem) (exact-integer-sqrt (expt 10 39)))) |
|
(list root rem))) |
|
|
|
(let*-values (((root rem) (exact-integer-sqrt (expt 2 140)))) |
|
(test 0 rem) |
|
(test (expt 2 140) (square root))) |
|
|
|
(test '(x y x y) (let ((a 'a) (b 'b) (x 'x) (y 'y)) |
|
(let*-values (((a b) (values x y)) |
|
((x y) (values a b))) |
|
(list a b x y)))) |
|
|
|
(test 'ok (let-values () 'ok)) |
|
|
|
(test 1 (let ((x 1)) |
|
(let*-values () |
|
(define x 2) |
|
|
|
x)) |
|
|
|
(let () |
|
(define x 0) |
|
(set! x 5) |
|
(test 6 (+ x 1))) |
|
|
|
(test ' |
|
(i 0 (+ i 1))) |
|
((= i 5) vec) |
|
(vector-set! vec i i))) |
|
|
|
(test 25 (let ((x '(1 3 5 7 9))) |
|
(do ((x x (cdr x)) |
|
(sum 0 (+ sum (car x)))) |
|
((null? x) sum)))) |
|
|
|
(test '((6 1 3) (-5 -2)) |
|
(let loop ((numbers '(3 -2 1 6 -5)) |
|
(nonneg '()) |
|
(neg '())) |
|
(cond ((null? numbers) (list nonneg neg)) |
|
((>= (car numbers) 0) |
|
(loop (cdr numbers) |
|
(cons (car numbers) nonneg) |
|
neg)) |
|
((< (car numbers) 0) |
|
(loop (cdr numbers) |
|
nonneg |
|
(cons (car numbers) neg)))))) |
|
|
|
(test 3 (force (delay (+ 1 2)))) |
|
|
|
(test '(3 3) |
|
(let ((p (delay (+ 1 2)))) |
|
(list (force p) (force p)))) |
|
|
|
(define integers |
|
(letrec ((next |
|
(lambda (n) |
|
(delay (cons n (next (+ n 1))))))) |
|
(next 0))) |
|
(define head |
|
(lambda (stream) (car (force stream)))) |
|
(define tail |
|
(lambda (stream) (cdr (force stream)))) |
|
|
|
(test 2 (head (tail (tail integers)))) |
|
|
|
(define (stream-filter p? s) |
|
(delay-force |
|
(if (null? (force s)) |
|
(delay '()) |
|
(let ((h (car (force s))) |
|
(t (cdr (force s)))) |
|
(if (p? h) |
|
(delay (cons h (stream-filter p? t))) |
|
(stream-filter p? t)))))) |
|
|
|
(test 5 (head (tail (tail (stream-filter odd? integers))))) |
|
|
|
(let () |
|
(define x 5) |
|
(define count 0) |
|
(define p |
|
(delay (begin (set! count (+ count 1)) |
|
(if (> count x) |
|
count |
|
(force p))))) |
|
(test 6 (force p)) |
|
(test 6 (begin (set! x 10) (force p)))) |
|
|
|
(test |
|
(test |
|
(test |
|
(let ((x (delay (+ 2 2)))) |
|
(force x) |
|
(promise? x))) |
|
(test |
|
(let ((x (make-promise (+ 2 2)))) |
|
(force x) |
|
(promise? x))) |
|
|
|
(define radix |
|
(make-parameter |
|
10 |
|
(lambda (x) |
|
(if (and (integer? x) (<= 2 x 16)) |
|
x |
|
(error "invalid radix"))))) |
|
(define (f n) (number->string n (radix))) |
|
(test "12" (f 12)) |
|
(test "1100" (parameterize ((radix 2)) |
|
(f 12))) |
|
(test "12" (f 12)) |
|
|
|
(test '(list 3 4) `(list ,(+ 1 2) 4)) |
|
(let ((name 'a)) (test '(list a (quote a)) `(list ,name ',name))) |
|
(test '(a 3 4 5 6 b) `(a ,(+ 1 2) ,@(map abs '(4 -5 6)) b)) |
|
(test ' |
|
` |
|
(test '(a `(b ,(+ 1 2) ,(foo 4 d) e) f) |
|
`(a `(b ,(+ 1 2) ,(foo ,(+ 1 3) d) e) f) ) |
|
(let ((name1 'x) |
|
(name2 'y)) |
|
(test '(a `(b ,x ,'y d) e) `(a `(b ,,name1 ,',name2 d) e))) |
|
(test '(list 3 4) (quasiquote (list (unquote (+ 1 2)) 4)) ) |
|
(test `(list ,(+ 1 2) 4) (quasiquote (list (unquote (+ 1 2)) 4))) |
|
|
|
(define plus |
|
(case-lambda |
|
(() 0) |
|
((x) x) |
|
((x y) (+ x y)) |
|
((x y z) (+ (+ x y) z)) |
|
(args (apply + args)))) |
|
|
|
(test 0 (plus)) |
|
(test 1 (plus 1)) |
|
(test 3 (plus 1 2)) |
|
(test 6 (plus 1 2 3)) |
|
(test 10 (plus 1 2 3 4)) |
|
|
|
(define mult |
|
(case-lambda |
|
(() 1) |
|
((x) x) |
|
((x y) (* x y)) |
|
((x y . z) (apply mult (* x y) z)))) |
|
|
|
(test 1 (mult)) |
|
(test 1 (mult 1)) |
|
(test 2 (mult 1 2)) |
|
(test 6 (mult 1 2 3)) |
|
(test 24 (mult 1 2 3 4)) |
|
|
|
(test-end) |
|
|
|
(test-begin "4.3 Macros") |
|
|
|
(test 'now (let-syntax |
|
((when (syntax-rules () |
|
((when test stmt1 stmt2 ...) |
|
(if test |
|
(begin stmt1 |
|
stmt2 ...)))))) |
|
(let ((if |
|
(when if (set! if 'now)) |
|
if))) |
|
|
|
(test 'outer (let ((x 'outer)) |
|
(let-syntax ((m (syntax-rules () ((m) x)))) |
|
(let ((x 'inner)) |
|
(m))))) |
|
|
|
(test 7 (letrec-syntax |
|
((my-or (syntax-rules () |
|
((my-or) |
|
((my-or e) e) |
|
((my-or e1 e2 ...) |
|
(let ((temp e1)) |
|
(if temp |
|
temp |
|
(my-or e2 ...))))))) |
|
(let ((x |
|
(y 7) |
|
(temp 8) |
|
(let odd?) |
|
(if even?)) |
|
(my-or x |
|
(let temp) |
|
(if y) |
|
y)))) |
|
|
|
(define-syntax be-like-begin1 |
|
(syntax-rules () |
|
((be-like-begin1 name) |
|
(define-syntax name |
|
(syntax-rules () |
|
((name expr (... ...)) |
|
(begin expr (... ...)))))))) |
|
(be-like-begin1 sequence1) |
|
(test 3 (sequence1 0 1 2 3)) |
|
|
|
(define-syntax be-like-begin2 |
|
(syntax-rules () |
|
((be-like-begin2 name) |
|
(define-syntax name |
|
(... (syntax-rules () |
|
((name expr ...) |
|
(begin expr ...)))))))) |
|
(be-like-begin2 sequence2) |
|
(test 4 (sequence2 1 2 3 4)) |
|
|
|
(define-syntax be-like-begin3 |
|
(syntax-rules () |
|
((be-like-begin3 name) |
|
(define-syntax name |
|
(syntax-rules dots () |
|
((name expr dots) |
|
(begin expr dots))))))) |
|
(be-like-begin3 sequence3) |
|
(test 5 (sequence3 2 3 4 5)) |
|
|
|
|
|
(define-syntax elli-esc-1 |
|
(syntax-rules () |
|
((_) |
|
'(... ...)) |
|
((_ x) |
|
'(... (x ...))) |
|
((_ x y) |
|
'(... (... x y))))) |
|
|
|
(test '... (elli-esc-1)) |
|
(test '(100 ...) (elli-esc-1 100)) |
|
(test '(... 100 200) (elli-esc-1 100 200)) |
|
|
|
|
|
(define-syntax part-2 |
|
(syntax-rules () |
|
((_ a b (m n) ... x y) |
|
(vector (list a b) (list m ...) (list n ...) (list x y))) |
|
((_ . rest) 'error))) |
|
(test ' |
|
(part-2 10 (+ 21 22) (31 32) (41 42) (51 52) (+ 61 2) 77)) |
|
|
|
(define-syntax part-2x |
|
(syntax-rules () |
|
((_ (a b (m n) ... x y . rest)) |
|
(vector (list a b) (list m ...) (list n ...) (list x y) |
|
(cons "rest:" 'rest))) |
|
((_ . rest) 'error))) |
|
(test ' |
|
(part-2x (10 (+ 21 22) (31 32) (41 42) (51 52) (+ 61 2) 77))) |
|
(test ' |
|
(part-2x (10 (+ 21 22) (31 32) (41 42) (51 52) (+ 61 2) 77 . "tail"))) |
|
|
|
|
|
(define-syntax underscore |
|
(syntax-rules () |
|
((foo _) '_))) |
|
(test '_ (underscore foo)) |
|
|
|
(let () |
|
(define-syntax underscore2 |
|
(syntax-rules () |
|
((underscore2 (a _) ...) 42))) |
|
(test 42 (underscore2 (1 2)))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax jabberwocky |
|
(syntax-rules () |
|
((_ hatter) |
|
(begin |
|
(define march-hare 42) |
|
(define-syntax hatter |
|
(syntax-rules () |
|
((_) march-hare))))))) |
|
(jabberwocky mad-hatter) |
|
(test 42 (mad-hatter)) |
|
|
|
(test 'ok (let ((=> |
|
|
|
(let () |
|
(define x 1) |
|
(let-syntax () |
|
(define x 2) |
|
|
|
(test 1 x)) |
|
|
|
(let () |
|
(define-syntax foo |
|
(syntax-rules () |
|
((foo bar y) |
|
(define-syntax bar |
|
(syntax-rules () |
|
((bar x) 'y)))))) |
|
(foo bar x) |
|
(test 'x (bar 1))) |
|
|
|
(begin |
|
(define-syntax ffoo |
|
(syntax-rules () |
|
((ffoo ff) |
|
(begin |
|
(define (ff x) |
|
(gg x)) |
|
(define (gg x) |
|
(* x x)))))) |
|
(ffoo ff) |
|
(test 100 (ff 10))) |
|
|
|
(let-syntax ((vector-lit |
|
(syntax-rules () |
|
((vector-lit) |
|
' |
|
(test ' |
|
|
|
(let () |
|
|
|
(define-syntax foo399 |
|
(syntax-rules () ((foo399) (bar399)))) |
|
(define (quux399) |
|
(foo399)) |
|
(define (bar399) |
|
42) |
|
(test 42 (quux399))) |
|
|
|
(let-syntax |
|
((m (syntax-rules () |
|
((m x) (let-syntax |
|
((n (syntax-rules (k) |
|
((n x) 'bound-identifier=?) |
|
((n y) 'free-identifier=?)))) |
|
(n z)))))) |
|
(test 'bound-identifier=? (m k))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(test 'error |
|
(guard (exn (else 'error)) |
|
(eval |
|
'(define-syntax bad-elli-1 |
|
(syntax-rules () |
|
((_ ... x) |
|
'(... x)))) |
|
(interaction-environment)))) |
|
|
|
(test 'error |
|
(guard (exn (else 'error)) |
|
(eval |
|
'(define-syntax bad-elli-2 |
|
(syntax-rules () |
|
((_ (... x)) |
|
'(... x)))) |
|
(interaction-environment)))) |
|
| |
|
|
|
(test-end) |
|
|
|
(test-begin "5 Program structure") |
|
|
|
(define add3 |
|
(lambda (x) (+ x 3))) |
|
(test 6 (add3 3)) |
|
(define first car) |
|
(test 1 (first '(1 2))) |
|
|
|
(test 45 (let ((x 5)) |
|
(define foo (lambda (y) (bar x y))) |
|
(define bar (lambda (a b) (+ (* a b) a))) |
|
(foo (+ x 3)))) |
|
|
|
(test 'ok |
|
(let () |
|
(define-values () (values)) |
|
'ok)) |
|
(test 1 |
|
(let () |
|
(define-values (x) (values 1)) |
|
x)) |
|
(test 3 |
|
(let () |
|
(define-values x (values 1 2)) |
|
(apply + x))) |
|
(test 3 |
|
(let () |
|
(define-values (x y) (values 1 2)) |
|
(+ x y))) |
|
(test 6 |
|
(let () |
|
(define-values (x y z) (values 1 2 3)) |
|
(+ x y z))) |
|
(test 10 |
|
(let () |
|
(define-values (x y . z) (values 1 2 3 4)) |
|
(+ x y (car z) (cadr z)))) |
|
|
|
(test '(2 1) (let ((x 1) (y 2)) |
|
(define-syntax swap! |
|
(syntax-rules () |
|
((swap! a b) |
|
(let ((tmp a)) |
|
(set! a b) |
|
(set! b tmp))))) |
|
(swap! x y) |
|
(list x y))) |
|
|
|
|
|
|
|
(define-record-type <pare> |
|
(kons x y) |
|
pare? |
|
(x kar set-kar!) |
|
(y kdr)) |
|
|
|
(test |
|
(test |
|
(test 1 (kar (kons 1 2))) |
|
(test 2 (kdr (kons 1 2))) |
|
(test 3 (let ((k (kons 1 2))) |
|
(set-kar! k 3) |
|
(kar k))) |
|
|
|
(test-end) |
|
|
|
|
|
|
|
|
|
(test-begin "6.1 Equivalence Predicates") |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(lambda () 2))) |
|
(test |
|
|
|
(define gen-counter |
|
(lambda () |
|
(let ((n 0)) |
|
(lambda () (set! n (+ n 1)) n)))) |
|
(test |
|
(let ((g (gen-counter))) |
|
(eqv? g g))) |
|
(test |
|
(define gen-loser |
|
(lambda () |
|
(let ((n 0)) |
|
(lambda () (set! n (+ n 1)) 27)))) |
|
(test |
|
(eqv? g g))) |
|
|
|
(test |
|
(letrec ((f (lambda () (if (eqv? f g) 'f 'both))) |
|
(g (lambda () (if (eqv? f g) 'g 'both)))) |
|
(eqv? f g))) |
|
|
|
(test |
|
(let ((x '(a))) |
|
(eqv? x x))) |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(let ((x '(a))) |
|
(eq? x x))) |
|
(test |
|
(let ((x ' |
|
(eq? x x))) |
|
(test |
|
(let ((p (lambda (x) x))) |
|
(eq? p p))) |
|
|
|
(test |
|
(test |
|
(test |
|
'(a (b) c))) |
|
(test |
|
(test |
|
(test |
|
(make-vector 5 'a))) |
|
|
|
(test-end) |
|
|
|
(test-begin "6.2 Numbers") |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test '( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(let ((a (- (expt 2 1000) 1)) |
|
(b (inexact (expt 2 1000))) |
|
(c (+ (expt 2 1000) 1))) |
|
(test |
|
(= a c) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define single-float-epsilon |
|
(do ((eps 1.0 (* eps 2.0))) |
|
((= eps (+ eps 1.0)) eps))) |
|
|
|
(let* ((a (/ 10.0 single-float-epsilon)) |
|
(j (exact a))) |
|
(test |
|
(not (<= (+ j 1) a)) |
|
|
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test 3 (max 3)) |
|
(test 4 (max 3 4)) |
|
(test 4.0 (max 3.9 4)) |
|
(test 5.0 (max 5 3.9 4)) |
|
(test +inf.0 (max 100 +inf.0)) |
|
(test 3 (min 3)) |
|
(test 3 (min 3 4)) |
|
(test 3.0 (min 3 3.1)) |
|
(test -inf.0 (min -inf.0 -100)) |
|
|
|
(test 7 (+ 3 4)) |
|
(test 3 (+ 3)) |
|
(test 0 (+)) |
|
(test 4 (* 4)) |
|
(test 1 (*)) |
|
|
|
(test -1 (- 3 4)) |
|
(test -6 (- 3 4 5)) |
|
(test -3 (- 3)) |
|
(test 3/20 (/ 3 4 5)) |
|
(test 1/3 (/ 3)) |
|
|
|
(test 7 (abs -7)) |
|
(test 7 (abs 7)) |
|
|
|
(test-values (values 2 1) (floor/ 5 2)) |
|
(test-values (values -3 1) (floor/ -5 2)) |
|
(test-values (values -3 -1) (floor/ 5 -2)) |
|
(test-values (values 2 -1) (floor/ -5 -2)) |
|
(test-values (values 2 1) (truncate/ 5 2)) |
|
(test-values (values -2 -1) (truncate/ -5 2)) |
|
(test-values (values -2 1) (truncate/ 5 -2)) |
|
(test-values (values 2 -1) (truncate/ -5 -2)) |
|
(test-values (values 2.0 -1.0) (truncate/ -5.0 -2)) |
|
|
|
(test 1 (modulo 13 4)) |
|
(test 1 (remainder 13 4)) |
|
|
|
(test 3 (modulo -13 4)) |
|
(test -1 (remainder -13 4)) |
|
|
|
(test -3 (modulo 13 -4)) |
|
(test 1 (remainder 13 -4)) |
|
|
|
(test -1 (modulo -13 -4)) |
|
(test -1 (remainder -13 -4)) |
|
|
|
(test -1.0 (remainder -13 -4.0)) |
|
|
|
(test 4 (gcd 32 -36)) |
|
(test 0 (gcd)) |
|
(test 288 (lcm 32 -36)) |
|
(test 288.0 (lcm 32.0 -36)) |
|
(test 1 (lcm)) |
|
|
|
(test 3 (numerator (/ 6 4))) |
|
(test 2 (denominator (/ 6 4))) |
|
(test 2.0 (denominator (inexact (/ 6 4)))) |
|
(test 11.0 (numerator 5.5)) |
|
(test 2.0 (denominator 5.5)) |
|
(test 5.0 (numerator 5.0)) |
|
(test 1.0 (denominator 5.0)) |
|
|
|
(test -5.0 (floor -4.3)) |
|
(test -4.0 (ceiling -4.3)) |
|
(test -4.0 (truncate -4.3)) |
|
(test -4.0 (round -4.3)) |
|
|
|
(test 3.0 (floor 3.5)) |
|
(test 4.0 (ceiling 3.5)) |
|
(test 3.0 (truncate 3.5)) |
|
(test 4.0 (round 3.5)) |
|
|
|
(test 4 (round 7/2)) |
|
(test 7 (round 7)) |
|
|
|
(test 1/3 (rationalize (exact .3) 1/10)) |
|
(test |
|
|
|
(test 1.0 (inexact (exp 0))) |
|
(test 20.0855369231877 (exp 3)) |
|
|
|
(test 0.0 (inexact (log 1))) |
|
(test 1.0 (log (exp 1))) |
|
(test 42.0 (log (exp 42))) |
|
(test 2.0 (log 100 10)) |
|
(test 12.0 (log 4096 2)) |
|
|
|
(test 0.0 (inexact (sin 0))) |
|
(test 1.0 (sin 1.5707963267949)) |
|
(test 1.0 (inexact (cos 0))) |
|
(test -1.0 (cos 3.14159265358979)) |
|
(test 0.0 (inexact (tan 0))) |
|
(test 1.5574077246549 (tan 1)) |
|
|
|
(test 0.0 (inexact (asin 0))) |
|
(test 1.5707963267949 (asin 1)) |
|
(test 0.0 (inexact (acos 1))) |
|
(test 3.14159265358979 (acos -1)) |
|
|
|
|
|
|
|
|
|
(test 0.0 (atan 0.0 1.0)) |
|
(test -0.0 (atan -0.0 1.0)) |
|
(test 0.785398163397448 (atan 1.0 1.0)) |
|
(test 1.5707963267949 (atan 1.0 0.0)) |
|
(test 2.35619449019234 (atan 1.0 -1.0)) |
|
(test 3.14159265358979 (atan 0.0 -1.0)) |
|
(test -3.14159265358979 (atan -0.0 -1.0)) |
|
(test -2.35619449019234 (atan -1.0 -1.0)) |
|
(test -1.5707963267949 (atan -1.0 0.0)) |
|
(test -0.785398163397448 (atan -1.0 1.0)) |
|
|
|
|
|
(test 1764 (square 42)) |
|
(test 4 (square 2)) |
|
|
|
(test 3.0 (inexact (sqrt 9))) |
|
(test 1.4142135623731 (sqrt 2)) |
|
(test 0.0+1.0i (inexact (sqrt -1))) |
|
|
|
(test '(2 0) (call-with-values (lambda () (exact-integer-sqrt 4)) list)) |
|
(test '(2 1) (call-with-values (lambda () (exact-integer-sqrt 5)) list)) |
|
|
|
(test 27 (expt 3 3)) |
|
(test 1 (expt 0 0)) |
|
(test 0 (expt 0 1)) |
|
(test 1.0 (expt 0.0 0)) |
|
(test 0.0 (expt 0 1.0)) |
|
|
|
(test 1+2i (make-rectangular 1 2)) |
|
|
|
(test 0.54030230586814+0.841470984807897i (make-polar 1 1)) |
|
|
|
(cond-expand |
|
(exact-complex |
|
(test 1 (real-part 1+2i)) |
|
(test 2 (imag-part 1+2i))) |
|
(else |
|
|
|
(test 2.23606797749979 (magnitude 1+2i)) |
|
|
|
(test 1.10714871779409 (angle 1+2i)) |
|
|
|
(test 1.0 (inexact 1)) |
|
(test |
|
(test 1 (exact 1.0)) |
|
(test |
|
|
|
(test 100 (string->number "100")) |
|
(test 256 (string->number "100" 16)) |
|
(test 100.0 (string->number "1e2")) |
|
|
|
(test-end) |
|
|
|
(test-begin "6.3 Booleans") |
|
|
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test-end) |
|
|
|
(test-begin "6.4 Lists") |
|
|
|
(let* ((x (list 'a 'b 'c)) |
|
(y x)) |
|
(test '(a b c) (values y)) |
|
(test |
|
(set-cdr! x 4) |
|
(test '(a . 4) (values x)) |
|
(test |
|
(test |
|
(set-cdr! x x) |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test '(a) (cons 'a '())) |
|
(test '((a) b c d) (cons '(a) '(b c d))) |
|
(test '("a" b c) (cons "a" '(b c))) |
|
(test '(a . 3) (cons 'a 3)) |
|
(test '((a b) . c) (cons '(a b) 'c)) |
|
|
|
(test 'a (car '(a b c))) |
|
(test '(a) (car '((a) b c d))) |
|
(test 1 (car '(1 . 2))) |
|
|
|
(test '(b c d) (cdr '((a) b c d))) |
|
(test 2 (cdr '(1 . 2))) |
|
(define (g) '(constant-list)) |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test '(3 3) (make-list 2 3)) |
|
|
|
(test '(a 7 c) (list 'a (+ 3 4) 'c)) |
|
(test '() (list)) |
|
|
|
(test 3 (length '(a b c))) |
|
(test 3 (length '(a (b) (c d e)))) |
|
(test 0 (length '())) |
|
|
|
(test '(x y) (append '(x) '(y))) |
|
(test '(a b c d) (append '(a) '(b c d))) |
|
(test '(a (b) (c)) (append '(a (b)) '((c)))) |
|
|
|
(test '(a b c . d) (append '(a b) '(c . d))) |
|
(test 'a (append '() 'a)) |
|
|
|
(test '(c b a) (reverse '(a b c))) |
|
(test '((e (f)) d (b c) a) (reverse '(a (b c) d (e (f))))) |
|
|
|
(test '(d e) (list-tail '(a b c d e) 3)) |
|
|
|
(test 'c (list-ref '(a b c d) 2)) |
|
(test 'c (list-ref '(a b c d) |
|
(exact (round 1.8)))) |
|
|
|
(test '(0 ("Sue" "Sue") "Anna") |
|
(let ((lst (list 0 '(2 2 2 2) "Anna"))) |
|
(list-set! lst 1 '("Sue" "Sue")) |
|
lst)) |
|
|
|
(test '(a b c) (memq 'a '(a b c))) |
|
(test '(b c) (memq 'b '(a b c))) |
|
(test |
|
(test |
|
(test '((a) c) (member (list 'a) '(b (a) c))) |
|
(test '("b" "c") (member "B" '("a" "b" "c") string-ci=?)) |
|
(test '(101 102) (memv 101 '(100 101 102))) |
|
|
|
(let () |
|
(define e '((a 1) (b 2) (c 3))) |
|
(test '(a 1) (assq 'a e)) |
|
(test '(b 2) (assq 'b e)) |
|
(test |
|
|
|
(test |
|
(test '((a)) (assoc (list 'a) '(((a)) ((b)) ((c))))) |
|
(test '(2 4) (assoc 2.0 '((1 1) (2 4) (3 9)) =)) |
|
(test '(5 7) (assv 5 '((2 3) (5 7) (11 13)))) |
|
|
|
(test '(1 2 3) (list-copy '(1 2 3))) |
|
(test "foo" (list-copy "foo")) |
|
(test '() (list-copy '())) |
|
(test '(3 . 4) (list-copy '(3 . 4))) |
|
(test '(6 7 8 . 9) (list-copy '(6 7 8 . 9))) |
|
(let* ((l1 '((a b) (c d) e)) |
|
(l2 (list-copy l1))) |
|
(test l2 '((a b) (c d) e)) |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test-end) |
|
|
|
(test-begin "6.5 Symbols") |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test "flying-fish" |
|
(symbol->string 'flying-fish)) |
|
(test "Martin" (symbol->string 'Martin)) |
|
(test "Malvina" (symbol->string (string->symbol "Malvina"))) |
|
|
|
(test 'mISSISSIppi (string->symbol "mISSISSIppi")) |
|
(test |
|
(test |
|
(test |
|
(symbol->string (string->symbol "K. Harper, M.D.")))) |
|
|
|
(test-end) |
|
|
|
(test-begin "6.6 Characters") |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test 0 (digit-value |
|
(test 3 (digit-value |
|
(test 9 (digit-value |
|
(test 4 (digit-value |
|
(test 0 (digit-value |
|
(test |
|
(test |
|
|
|
(test 97 (char->integer |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test-end) |
|
|
|
(test-begin "6.7 Strings") |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test 3 (string-length (make-string 3))) |
|
(test "---" (make-string 3 |
|
|
|
(test "" (string)) |
|
(test "---" (string |
|
(test "kitten" (string |
|
|
|
(test 0 (string-length "")) |
|
(test 1 (string-length "a")) |
|
(test 3 (string-length "abc")) |
|
|
|
(test |
|
(test |
|
(test |
|
|
|
(test "a-c" (let ((str (string |
|
|
|
(test (string |
|
(let ((s (string |
|
(string-set! s 1 |
|
s)) |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
|
|
|
|
(cond-expand |
|
((or ikarus larceny) |
|
(else |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
|
|
(test "ABC" (string-upcase "abc")) |
|
(test "ABC" (string-upcase "ABC")) |
|
(test "abc" (string-downcase "abc")) |
|
(test "abc" (string-downcase "ABC")) |
|
(test "abc" (string-foldcase "abc")) |
|
(test "abc" (string-foldcase "ABC")) |
|
|
|
|
|
(test "ΑΒΓ" (string-upcase "αβγ")) |
|
(test "ΑΒΓ" (string-upcase "ΑΒΓ")) |
|
(test "αβγ" (string-downcase "αβγ")) |
|
(test "αβγ" (string-downcase "ΑΒΓ")) |
|
(test "αβγ" (string-foldcase "αβγ")) |
|
(test "αβγ" (string-foldcase "ΑΒΓ")) |
|
|
|
|
|
(test "SSA" (string-upcase "ßa")) |
|
(test "ßa" (string-downcase "ßa")) |
|
(test "ssa" (string-downcase "SSA")) |
|
(test "maß" (string-downcase "Maß")) |
|
(test "mass" (string-foldcase "Maß")) |
|
(test "İ" (string-upcase "İ")) |
|
(test "i\x0307 |
|
(test "i\x0307 |
|
(test "J̌" (string-upcase "ǰ")) |
|
(test "ſ" (string-downcase "ſ")) |
|
(test "s" (string-foldcase "ſ")) |
|
|
|
|
|
(test "ΓΛΏΣΣΑ" (string-upcase "γλώσσα")) |
|
(test "γλώσσα" (string-downcase "ΓΛΏΣΣΑ")) |
|
(test "γλώσσα" (string-foldcase "ΓΛΏΣΣΑ")) |
|
(test "ΜΈΛΟΣ" (string-upcase "μέλος")) |
|
(test |
|
|
|
(failing-test "https://bugs.gnu.org/38235" |
|
"μέλοσ" (string-foldcase "ΜΈΛΟΣ")) |
|
(test |
|
'("μέλος ενός" "μέλοσ ενόσ")) |
|
|
|
|
|
(test "" (substring "" 0 0)) |
|
(test "" (substring "a" 0 0)) |
|
(test "" (substring "abc" 1 1)) |
|
(test "ab" (substring "abc" 0 2)) |
|
(test "bc" (substring "abc" 1 3)) |
|
|
|
(test "" (string-append "")) |
|
(test "" (string-append "" "")) |
|
(test "abc" (string-append "" "abc")) |
|
(test "abc" (string-append "abc" "")) |
|
(test "abcde" (string-append "abc" "de")) |
|
(test "abcdef" (string-append "abc" "de" "f")) |
|
|
|
(test '() (string->list "")) |
|
(test '( |
|
(test '( |
|
(test '( |
|
(test '( |
|
(test '( |
|
|
|
(test "" (list->string '())) |
|
(test "abc" (list->string '( |
|
|
|
(test "" (string-copy "")) |
|
(test "" (string-copy "" 0)) |
|
(test "" (string-copy "" 0 0)) |
|
(test "abc" (string-copy "abc")) |
|
(test "abc" (string-copy "abc" 0)) |
|
(test "bc" (string-copy "abc" 1)) |
|
(test "b" (string-copy "abc" 1 2)) |
|
(test "bc" (string-copy "abc" 1 3)) |
|
|
|
(test "-----" |
|
(let ((str (make-string 5 |
|
(test "xx---" |
|
(let ((str (make-string 5 |
|
(test "xx-xx" |
|
(let ((str (make-string 5 |
|
|
|
(test "a12de" |
|
(let ((str (string-copy "abcde"))) (string-copy! str 1 "12345" 0 2) str)) |
|
(test "-----" |
|
(let ((str (make-string 5 |
|
(test "---xx" |
|
(let ((str (make-string 5 |
|
(test "xx---" |
|
(let ((str (make-string 5 |
|
(test "xx-xx" |
|
(let ((str (make-string 5 |
|
|
|
|
|
(test "aabde" |
|
(let ((str (string-copy "abcde"))) (string-copy! str 1 str 0 2) str)) |
|
(test "abcab" |
|
(let ((str (string-copy "abcde"))) (string-copy! str 3 str 0 2) str)) |
|
|
|
(test-end) |
|
|
|
(test-begin "6.8 Vectors") |
|
|
|
|
|
|
|
(test |
|
|
|
(test 0 (vector-length (make-vector 0))) |
|
(test 1000 (vector-length (make-vector 1000))) |
|
|
|
|
|
|
|
(test ' |
|
|
|
(test 8 (vector-ref ' |
|
(test 13 (vector-ref ' |
|
(let ((i (round (* 2 (acos -1))))) |
|
(if (inexact? i) |
|
(exact i) |
|
i)))) |
|
|
|
(test ' |
|
(vector-set! vec 1 '("Sue" "Sue")) |
|
vec)) |
|
|
|
(test '(dah dah didah) (vector->list ' |
|
(test '(dah didah) (vector->list ' |
|
(test '(dah) (vector->list ' |
|
(test ' |
|
|
|
(test ' |
|
(test ' |
|
(test ' |
|
(test ' |
|
|
|
(test "" (vector->string ' |
|
(test "123" (vector->string ' |
|
(test "23" (vector->string ' |
|
(test "2" (vector->string ' |
|
|
|
(test ' |
|
(test ' |
|
(test ' |
|
(test ' |
|
|
|
(test ' |
|
(test ' |
|
(test ' |
|
(test ' |
|
(test ' |
|
(test ' |
|
|
|
(test ' |
|
(let ((vec (vector 1 2 3 4 5))) (vector-fill! vec 'smash 2 4) vec)) |
|
(test ' |
|
(let ((vec (vector 1 2 3 4 5))) (vector-fill! vec 'x) vec)) |
|
(test ' |
|
(let ((vec (vector 1 2 3 4 5))) (vector-fill! vec 'x 2) vec)) |
|
(test ' |
|
(let ((vec (vector 1 2 3 4 5))) (vector-fill! vec 'x 2 3) vec)) |
|
|
|
(test ' |
|
(let ((vec (vector 1 2 3 4 5))) (vector-copy! vec 1 ' |
|
(test ' |
|
(let ((vec (vector 1 2 3 4 5))) (vector-copy! vec 0 ' |
|
(test ' |
|
(let ((vec (vector 1 2 3 4 5))) (vector-copy! vec 0 ' |
|
(test ' |
|
(let ((vec (vector 1 2 3 4 5))) (vector-copy! vec 2 ' |
|
(test ' |
|
(let ((vec (vector 1 2 3 4 5))) (vector-copy! vec 2 ' |
|
|
|
|
|
(test ' |
|
(let ((vec (vector 1 2 3 4 5))) (vector-copy! vec 1 vec 0 2) vec)) |
|
(test ' |
|
(let ((vec (vector 1 2 3 4 5))) (vector-copy! vec 3 vec 0 2) vec)) |
|
|
|
(test-end) |
|
|
|
(test-begin "6.9 Bytevectors") |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test 0 (bytevector-length (make-bytevector 0))) |
|
(test 1024 (bytevector-length (make-bytevector 1024))) |
|
(test 1024 (bytevector-length (make-bytevector 1024 255))) |
|
|
|
(test 3 (bytevector-length (bytevector 0 1 2))) |
|
|
|
(test 0 (bytevector-u8-ref (bytevector 0 1 2) 0)) |
|
(test 1 (bytevector-u8-ref (bytevector 0 1 2) 1)) |
|
(test 2 (bytevector-u8-ref (bytevector 0 1 2) 2)) |
|
|
|
(test |
|
(let ((bv (bytevector 0 1 2))) (bytevector-u8-set! bv 1 255) bv)) |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(let ((bv (bytevector 1 2 3 4 5))) |
|
(bytevector-copy! bv 1 |
|
bv)) |
|
(test |
|
(let ((bv (bytevector 1 2 3 4 5))) |
|
(bytevector-copy! bv 0 |
|
bv)) |
|
(test |
|
(let ((bv (bytevector 1 2 3 4 5))) |
|
(bytevector-copy! bv 0 |
|
bv)) |
|
(test |
|
(let ((bv (bytevector 1 2 3 4 5))) |
|
(bytevector-copy! bv 2 |
|
bv)) |
|
(test |
|
(let ((bv (bytevector 1 2 3 4 5))) |
|
(bytevector-copy! bv 2 |
|
bv)) |
|
|
|
|
|
(test |
|
(let ((bv (bytevector 1 2 3 4 5))) |
|
(bytevector-copy! bv 1 bv 0 2) |
|
bv)) |
|
(test |
|
(let ((bv (bytevector 1 2 3 4 5))) |
|
(bytevector-copy! bv 3 bv 0 2) |
|
bv)) |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test "ABC" (utf8->string |
|
(test "ABC" (utf8->string |
|
(test "ABC" (utf8->string |
|
(test "λ" (utf8->string |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test-end) |
|
|
|
(test-begin "6.10 Control Features") |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test 7 (apply + (list 3 4))) |
|
(test 7 (apply + 3 4 (list))) |
|
(cond-expand |
|
(sagittarius |
|
|
|
(else |
|
(test-error (apply +)))) |
|
(test-error (apply + 3)) |
|
(test-error (apply + 3 4)) |
|
(test-error (apply + '(2 3 . 4))) |
|
|
|
|
|
(define compose |
|
(lambda (f g) |
|
(lambda args |
|
(f (apply g args))))) |
|
(test '(30 0) |
|
(call-with-values (lambda () ((compose exact-integer-sqrt *) 12 75)) |
|
list)) |
|
|
|
(test '(b e h) (map cadr '((a b) (d e) (g h)))) |
|
|
|
(test '(1 4 27 256 3125) (map (lambda (n) (expt n n)) '(1 2 3 4 5))) |
|
|
|
(test '(5 7 9) (map + '(1 2 3) '(4 5 6 7))) |
|
|
|
(test |
|
(let ((res (let ((count 0)) |
|
(map (lambda (ignored) |
|
(set! count (+ count 1)) |
|
count) |
|
'(a b))))) |
|
(or (equal? res '(1 2)) |
|
(equal? res '(2 1))))) |
|
|
|
(test '(10 200 3000 40 500 6000) |
|
(let ((ls1 (list 10 100 1000)) |
|
(ls2 (list 1 2 3 4 5 6))) |
|
(set-cdr! (cddr ls1) ls1) |
|
(map * ls1 ls2))) |
|
|
|
(test "abdegh" (string-map char-foldcase "AbdEgH")) |
|
|
|
(test "IBM" (string-map |
|
(lambda (c) |
|
(integer->char (+ 1 (char->integer c)))) |
|
"HAL")) |
|
|
|
(test "StUdLyCaPs" |
|
(string-map |
|
(lambda (c k) (if (eqv? k |
|
"studlycaps xxx" |
|
"ululululul")) |
|
|
|
(test ' |
|
|
|
(test ' |
|
(vector-map (lambda (n) (expt n n)) |
|
' |
|
|
|
(test ' |
|
|
|
(test |
|
(let ((res (let ((count 0)) |
|
(vector-map |
|
(lambda (ignored) |
|
(set! count (+ count 1)) |
|
count) |
|
' |
|
(or (equal? res ' |
|
(equal? res ' |
|
|
|
(test ' |
|
(let ((v (make-vector 5))) |
|
(for-each (lambda (i) |
|
(vector-set! v i (* i i))) |
|
'(0 1 2 3 4)) |
|
v)) |
|
|
|
(test 9750 |
|
(let ((ls1 (list 10 100 1000)) |
|
(ls2 (list 1 2 3 4 5 6)) |
|
(count 0)) |
|
(set-cdr! (cddr ls1) ls1) |
|
(for-each (lambda (x y) (set! count (+ count (* x y)))) ls2 ls1) |
|
count)) |
|
|
|
(test '(101 100 99 98 97) |
|
(let ((v '())) |
|
(string-for-each |
|
(lambda (c) (set! v (cons (char->integer c) v))) |
|
"abcde") |
|
v)) |
|
|
|
(test '(4 3 2 1) |
|
(let ((v '())) |
|
(string-for-each |
|
(lambda (b c) (set! v (cons (- (char->integer b) (char->integer c)) v))) |
|
"bdfh" |
|
"abcde") |
|
v)) |
|
|
|
(test '(0 1 4 9 16) (let ((v (make-list 5))) |
|
(vector-for-each |
|
(lambda (i) (list-set! v i (* i i))) |
|
' |
|
v)) |
|
|
|
(test -3 (call-with-current-continuation |
|
(lambda (exit) |
|
(for-each (lambda (x) |
|
(if (negative? x) |
|
(exit x))) |
|
'(54 0 37 -3 245 19)) |
|
|
|
(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 |
|
(r obj)))))) |
|
|
|
(test 4 (list-length '(1 2 3 4))) |
|
|
|
(test |
|
|
|
(test 5 |
|
(call-with-values (lambda () (values 4 5)) |
|
(lambda (a b) b))) |
|
|
|
(test -1 (call-with-values * -)) |
|
|
|
(test '(connect talk1 disconnect |
|
connect talk2 disconnect) |
|
(let ((path '()) |
|
(c |
|
(let ((add (lambda (s) |
|
(set! path (cons s path))))) |
|
(dynamic-wind |
|
(lambda () (add 'connect)) |
|
(lambda () |
|
(add (call-with-current-continuation |
|
(lambda (c0) |
|
(set! c c0) |
|
'talk1)))) |
|
(lambda () (add 'disconnect))) |
|
(if (< (length path) 4) |
|
(c 'talk2) |
|
(reverse path))))) |
|
|
|
(test-end) |
|
|
|
(test-begin "6.11 Exceptions") |
|
|
|
(test 65 |
|
(with-exception-handler |
|
(lambda (con) 42) |
|
(lambda () |
|
(+ (raise-continuable "should be a number") |
|
23)))) |
|
|
|
(test |
|
(error-object? (guard (exn (else exn)) (error "BOOM!" 1 2 3)))) |
|
(test "BOOM!" |
|
(error-object-message (guard (exn (else exn)) (error "BOOM!" 1 2 3)))) |
|
(test '(1 2 3) |
|
(error-object-irritants (guard (exn (else exn)) (error "BOOM!" 1 2 3)))) |
|
|
|
(test |
|
(file-error? (guard (exn (else exn)) (error "BOOM!")))) |
|
(failing-test |
|
"https://bugs.gnu.org/38237" |
|
|
|
(file-error? (guard (exn (else exn)) (open-input-file " no such file ")))) |
|
|
|
(test |
|
(read-error? (guard (exn (else exn)) (error "BOOM!")))) |
|
(test |
|
(read-error? (guard (exn (else exn)) (read (open-input-string ")"))))) |
|
|
|
(define something-went-wrong |
|
(define (test-exception-handler-1 v) |
|
(call-with-current-continuation |
|
(lambda (k) |
|
(with-exception-handler |
|
(lambda (x) |
|
(set! something-went-wrong (list "condition: " x)) |
|
(k 'exception)) |
|
(lambda () |
|
(+ 1 (if (> v 0) (+ v 100) (raise 'an-error)))))))) |
|
(test 106 (test-exception-handler-1 5)) |
|
(test |
|
(test 'exception (test-exception-handler-1 -1)) |
|
(test '("condition: " an-error) something-went-wrong) |
|
|
|
(set! something-went-wrong |
|
(define (test-exception-handler-2 v) |
|
(guard (ex (else 'caught-another-exception)) |
|
(with-exception-handler |
|
(lambda (x) |
|
(set! something-went-wrong |
|
(list "exception:" x)) |
|
(lambda () |
|
(+ 1 (if (> v 0) (+ v 100) (raise 'an-error))))))) |
|
(test 106 (test-exception-handler-2 5)) |
|
(test |
|
(test 'caught-another-exception (test-exception-handler-2 -1)) |
|
(test |
|
|
|
|
|
|
|
(let* ((out (open-output-string)) |
|
(value (with-exception-handler |
|
(lambda (con) |
|
(cond |
|
((not (list? con)) |
|
(raise con)) |
|
((list? con) |
|
(display (car con) out)) |
|
(else |
|
(display "a warning has been issued" out))) |
|
42) |
|
(lambda () |
|
(+ (raise-continuable |
|
(list "should be a number")) |
|
23))))) |
|
(test "should be a number" (get-output-string out)) |
|
(test 65 value)) |
|
|
|
|
|
(define (test-exception-handler-3 v out) |
|
(guard (condition |
|
(else |
|
(display "condition: " out) |
|
(write condition out) |
|
(display |
|
'exception)) |
|
(+ 1 (if (= v 0) (raise 'an-error) (/ 10 v))))) |
|
(let* ((out (open-output-string)) |
|
(value (test-exception-handler-3 0 out))) |
|
(test 'exception value) |
|
(test "condition: an-error!" (get-output-string out))) |
|
|
|
(define (test-exception-handler-4 v out) |
|
(call-with-current-continuation |
|
(lambda (k) |
|
(with-exception-handler |
|
(lambda (x) |
|
(display "reraised " out) |
|
(write x out) (display |
|
(k 'zero)) |
|
(lambda () |
|
(guard (condition |
|
((positive? condition) |
|
'positive) |
|
((negative? condition) |
|
'negative)) |
|
(raise v))))))) |
|
|
|
|
|
(let* ((out (open-output-string)) |
|
(value (test-exception-handler-4 1 out))) |
|
(test "" (get-output-string out)) |
|
(test 'positive value)) |
|
|
|
(let* ((out (open-output-string)) |
|
(value (test-exception-handler-4 -1 out))) |
|
(test "" (get-output-string out)) |
|
(test 'negative value)) |
|
|
|
(let* ((out (open-output-string)) |
|
(value (test-exception-handler-4 0 out))) |
|
(test "reraised 0!" (get-output-string out)) |
|
(test 'zero value)) |
|
|
|
|
|
(test 42 |
|
(guard (condition |
|
((assq 'a condition) => cdr) |
|
((assq 'b condition))) |
|
(raise (list (cons 'a 42))))) |
|
|
|
|
|
(test '(b . 23) |
|
(guard (condition |
|
((assq 'a condition) => cdr) |
|
((assq 'b condition))) |
|
(raise (list (cons 'b 23))))) |
|
|
|
(test 'caught-d |
|
(guard (condition |
|
((assq 'c condition) 'caught-c) |
|
((assq 'd condition) 'caught-d)) |
|
(list |
|
(sqrt 8) |
|
(guard (condition |
|
((assq 'a condition) => cdr) |
|
((assq 'b condition))) |
|
(raise (list (cons 'd 24))))))) |
|
|
|
(test-end) |
|
|
|
(test-begin "6.12 Environments and evaluation") |
|
|
|
|
|
|
|
(test 20 |
|
(let ((f (eval '(lambda (f x) (f x x)) (null-environment 5)))) |
|
(f + 10))) |
|
|
|
(test 1024 (eval '(expt 2 10) (environment '(scheme base)))) |
|
|
|
(test 0.0 (inexact (eval '(sin 0) (environment '(scheme inexact))))) |
|
|
|
(test 1024.0 (eval '(+ (expt 2 10) (inexact (sin 0))) |
|
(environment '(scheme base) '(scheme inexact)))) |
|
|
|
(test-end) |
|
|
|
(test-begin "6.13 Input and output") |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
|
|
(test |
|
(let ((in (open-input-string "abc"))) |
|
(close-input-port in) |
|
(input-port-open? in))) |
|
|
|
(test |
|
(let ((out (open-output-string))) |
|
(close-output-port out) |
|
(output-port-open? out))) |
|
|
|
(test |
|
(let ((out (open-output-string))) |
|
(close-port out) |
|
(output-port-open? out))) |
|
|
|
(test 'error |
|
(let ((in (open-input-string "abc"))) |
|
(close-input-port in) |
|
(guard (exn (else 'error)) (read-char in)))) |
|
|
|
(test 'error |
|
(let ((out (open-output-string))) |
|
(close-output-port out) |
|
(guard (exn (else 'error)) (write-char |
|
|
|
(test |
|
(test |
|
(test |
|
(test 42 (read (open-input-string " 42 "))) |
|
|
|
(test |
|
(test |
|
|
|
(test |
|
(test "abc" (read-line (open-input-string "abc"))) |
|
(test "abc" (read-line (open-input-string "abc\ndef\n"))) |
|
|
|
(test |
|
(test "abc" (read-string 3 (open-input-string "abcd"))) |
|
(test "abc" (read-string 3 (open-input-string "abc\ndef\n"))) |
|
|
|
(let ((in (open-input-string (string |
|
(let* ((c0 (peek-char in)) |
|
(c1 (read-char in)) |
|
(c2 (read-char in)) |
|
(c3 (read-char in))) |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test (string |
|
(let ((out (open-output-string))) |
|
(write-char |
|
(get-output-string out))) |
|
|
|
(test "abc" |
|
(let ((out (open-output-string))) |
|
(write 'abc out) |
|
(get-output-string out))) |
|
|
|
(test "abc def" |
|
(let ((out (open-output-string))) |
|
(display "abc def" out) |
|
(get-output-string out))) |
|
|
|
(test "abc" |
|
(let ((out (open-output-string))) |
|
(display |
|
(display "b" out) |
|
(display |
|
(get-output-string out))) |
|
|
|
(test |
|
(let* ((out (open-output-string)) |
|
(r (begin (newline out) (get-output-string out)))) |
|
(or (equal? r "\n") (equal? r "\r\n")))) |
|
|
|
(test "abc def" |
|
(let ((out (open-output-string))) |
|
(write-string "abc def" out) |
|
(get-output-string out))) |
|
|
|
(test "def" |
|
(let ((out (open-output-string))) |
|
(write-string "abc def" out 4) |
|
(get-output-string out))) |
|
|
|
(test "c d" |
|
(let ((out (open-output-string))) |
|
(write-string "abc def" out 2 5) |
|
(get-output-string out))) |
|
|
|
(test "" |
|
(let ((out (open-output-string))) |
|
(flush-output-port out) |
|
(get-output-string out))) |
|
|
|
(test |
|
(test 1 (read-u8 (open-input-bytevector |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(let ((bv (bytevector 1 2 3 4 5))) |
|
(eof-object? (read-bytevector! bv (open-input-bytevector |
|
|
|
(test |
|
(let ((bv (bytevector 1 2 3 4 5))) |
|
(read-bytevector! bv (open-input-bytevector |
|
bv)) |
|
|
|
(test |
|
(let ((bv (bytevector 1 2 3 4 5))) |
|
(read-bytevector! bv (open-input-bytevector |
|
bv)) |
|
|
|
(test |
|
(let ((bv (bytevector 1 2 3 4 5))) |
|
(read-bytevector! bv (open-input-bytevector |
|
bv)) |
|
|
|
(test |
|
(let ((out (open-output-bytevector))) |
|
(write-u8 1 out) |
|
(write-u8 2 out) |
|
(write-u8 3 out) |
|
(get-output-bytevector out))) |
|
|
|
(test |
|
(let ((out (open-output-bytevector))) |
|
(write-bytevector |
|
(get-output-bytevector out))) |
|
|
|
(test |
|
(let ((out (open-output-bytevector))) |
|
(write-bytevector |
|
(get-output-bytevector out))) |
|
|
|
(test |
|
(let ((out (open-output-bytevector))) |
|
(write-bytevector |
|
(get-output-bytevector out))) |
|
|
|
(test |
|
(let ((out (open-output-bytevector))) |
|
(flush-output-port out) |
|
(get-output-bytevector out))) |
|
|
|
(test |
|
(and (member |
|
(let ((out (open-output-string)) |
|
(x (list 1))) |
|
(set-cdr! x x) |
|
(write-shared x out) |
|
(get-output-string out)) |
|
|
|
'(" |
|
|
|
|
|
(test "((1 2 3) (1 2 3))" |
|
(let ((out (open-output-string)) |
|
(x (list 1 2 3))) |
|
(write (list x x) out) |
|
(get-output-string out))) |
|
|
|
(test "((1 2 3) (1 2 3))" |
|
(let ((out (open-output-string)) |
|
(x (list 1 2 3))) |
|
(write-simple (list x x) out) |
|
(get-output-string out))) |
|
|
|
(test |
|
(and (member (let ((out (open-output-string)) |
|
(x (list 1 2 3))) |
|
(write-shared (list x x) out) |
|
(get-output-string out)) |
|
'("( |
|
|
|
|
|
(test-begin "Read syntax") |
|
|
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
(define (read2 port) |
|
(let* ((o1 (read port)) (o2 (read port))) |
|
(cons o1 o2))) |
|
|
|
(test '( |
|
(test '( |
|
(test '( |
|
(test '( |
|
|
|
(test '() (read (open-input-string "()"))) |
|
(test '(1 2) (read (open-input-string "(1 2)"))) |
|
(test '(1 . 2) (read (open-input-string "(1 . 2)"))) |
|
(test '(1 2) (read (open-input-string "(1 . (2))"))) |
|
(test '(1 2 3 4 5) (read (open-input-string "(1 . (2 3 4 . (5)))"))) |
|
(failing-test-with-exception |
|
"https://bugs.gnu.org/38236" |
|
'1 (cadr (read (open-input-string " |
|
(failing-test-with-exception |
|
"https://bugs.gnu.org/38236" |
|
'(1 2 3) (cadr (read (open-input-string "( |
|
|
|
(test '(quote (1 2)) (read (open-input-string "'(1 2)"))) |
|
(test '(quote (1 (unquote 2))) (read (open-input-string "'(1 ,2)"))) |
|
(test '(quote (1 (unquote-splicing 2))) (read (open-input-string "'(1 ,@2)"))) |
|
(test '(quasiquote (1 (unquote 2))) (read (open-input-string "`(1 ,2)"))) |
|
|
|
(test ' |
|
(test ' |
|
|
|
(test |
|
(test |
|
|
|
(test 'abc (read (open-input-string "abc"))) |
|
(test 'abc (read (open-input-string "abc def"))) |
|
(test 'ABC (read (open-input-string "ABC"))) |
|
(test 'Hello (read (open-input-string "|H\\x65 |
|
|
|
(test 'abc (read (open-input-string " |
|
(test 'ABC (read (open-input-string " |
|
|
|
(test 'def (read (open-input-string " |
|
(test 'def (read (open-input-string " |
|
(test 'def (read (open-input-string " |
|
(test 'ghi (read (open-input-string " |
|
(test 'ghi (read (open-input-string " |
|
(test '(abs -16) (read (open-input-string "( |
|
(test '(a d) (read (open-input-string "(a |
|
(test '(a e) (read (open-input-string "(a |
|
(test '(a . c) (read (open-input-string "(a . |
|
(test '(a . b) (read (open-input-string "(a . b |
|
|
|
(define (test-read-error str) |
|
(test-assert str |
|
(guard (exn (else |
|
(read (open-input-string str)) |
|
|
|
|
|
|
|
(failing-test "https://bugs.gnu.org/38238" |
|
(failing-test "https://bugs.gnu.org/38238" |
|
(failing-test "https://bugs.gnu.org/38238" |
|
(failing-test "https://bugs.gnu.org/38238" |
|
(failing-test "https://bugs.gnu.org/38238" |
|
(failing-test "https://bugs.gnu.org/38238" |
|
|
|
(test |
|
(test |
|
(test 0 (char->integer (read (open-input-string " |
|
(test 7 (char->integer (read (open-input-string " |
|
(test 8 (char->integer (read (open-input-string " |
|
(test 9 (char->integer (read (open-input-string " |
|
(test 10 (char->integer (read (open-input-string " |
|
(test 13 (char->integer (read (open-input-string " |
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test "abc" (read (open-input-string "\"abc\""))) |
|
(test "abc" (read (open-input-string "\"abc\" \"def\""))) |
|
(test "ABC" (read (open-input-string "\"ABC\""))) |
|
(test "Hello" (read (open-input-string "\"H\\x65 |
|
(test 7 (char->integer (string-ref (read (open-input-string "\"\\a\"")) 0))) |
|
(test 8 (char->integer (string-ref (read (open-input-string "\"\\b\"")) 0))) |
|
(test 9 (char->integer (string-ref (read (open-input-string "\"\\t\"")) 0))) |
|
(test 10 (char->integer (string-ref (read (open-input-string "\"\\n\"")) 0))) |
|
(test 13 (char->integer (string-ref (read (open-input-string "\"\\r\"")) 0))) |
|
(test |
|
(test |
|
(test "line 1\nline 2\n" (read (open-input-string "\"line 1\nline 2\n\""))) |
|
(test "line 1continued\n" (read (open-input-string "\"line 1\\\ncontinued\n\""))) |
|
(failing-test-with-exception |
|
"https://bugs.gnu.org/38239" |
|
"line 1continued\n" (read (open-input-string "\"line 1\\ \ncontinued\n\""))) |
|
(test "line 1continued\n" (read (open-input-string "\"line 1\\\n continued\n\""))) |
|
(failing-test-with-exception |
|
"https://bugs.gnu.org/38239" |
|
"line 1continued\n" (read (open-input-string "\"line 1\\ \t \n \t continued\n\""))) |
|
(failing-test-with-exception |
|
"https://bugs.gnu.org/38239" |
|
"line 1\n\nline 3\n" (read (open-input-string "\"line 1\\ \t \n \t \n\nline 3\n\""))) |
|
(test |
|
|
|
(define-syntax test-write-syntax |
|
(syntax-rules () |
|
((test-write-syntax expect-str obj-expr) |
|
(let ((out (open-output-string))) |
|
(write obj-expr out) |
|
(test expect-str (get-output-string out)))))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(test-end) |
|
|
|
(test-begin "Numeric syntax") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-syntax test-numeric-syntax |
|
(syntax-rules () |
|
((test-numeric-syntax str expect strs ...) |
|
(let* ((z (read (open-input-string str))) |
|
(out (open-output-string)) |
|
(z-str (begin (write z out) (get-output-string out)))) |
|
(test expect (values z)) |
|
(test |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(test-numeric-syntax "1" 1) |
|
(test-numeric-syntax "+1" 1 "1") |
|
(test-numeric-syntax "-1" -1) |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
|
|
(test-numeric-syntax "1.0" 1.0 "1.0" "1.") |
|
(test-numeric-syntax "1." 1.0 "1.0" "1.") |
|
(test-numeric-syntax ".1" 0.1 "0.1" "100.0e-3") |
|
(test-numeric-syntax "-.1" -0.1 "-0.1" "-100.0e-3") |
|
|
|
(test-numeric-syntax "-.0" -0.0 "-0." "-0.0" "0.0" "0." ".0") |
|
(test-numeric-syntax "-0." -0.0 "-.0" "-0.0" "0.0" "0." ".0") |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
|
|
(test-numeric-syntax "1e2" 100.0 "100.0" "100.") |
|
(test-numeric-syntax "1E2" 100.0 "100.0" "100.") |
|
(test-numeric-syntax "1s2" 100.0 "100.0" "100.") |
|
(test-numeric-syntax "1S2" 100.0 "100.0" "100.") |
|
(test-numeric-syntax "1f2" 100.0 "100.0" "100.") |
|
(test-numeric-syntax "1F2" 100.0 "100.0" "100.") |
|
(test-numeric-syntax "1d2" 100.0 "100.0" "100.") |
|
(test-numeric-syntax "1D2" 100.0 "100.0" "100.") |
|
(test-numeric-syntax "1l2" 100.0 "100.0" "100.") |
|
(test-numeric-syntax "1L2" 100.0 "100.0" "100.") |
|
|
|
|
|
|
|
(test-numeric-syntax "+inf.0" +inf.0 "+inf.0" "+Inf.0") |
|
(test-numeric-syntax "+InF.0" +inf.0 "+inf.0" "+Inf.0") |
|
(test-numeric-syntax "-inf.0" -inf.0 "-inf.0" "-Inf.0") |
|
(test-numeric-syntax "-iNF.0" -inf.0 "-inf.0" "-Inf.0") |
|
|
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
|
|
(test-numeric-syntax "1/2" (/ 1 2)) |
|
(test-numeric-syntax " |
|
(test-numeric-syntax "10/2" 5 "5") |
|
(test-numeric-syntax "-1/2" (- (/ 1 2))) |
|
(test-numeric-syntax "0/10" 0 "0") |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
|
|
(cond-expand |
|
(exact-complex |
|
(test-numeric-syntax "1+2i" (make-rectangular 1 2)) |
|
(test-numeric-syntax "1+2I" (make-rectangular 1 2) "1+2i") |
|
(test-numeric-syntax "1-2i" (make-rectangular 1 -2)) |
|
(test-numeric-syntax "-1+2i" (make-rectangular -1 2)) |
|
(test-numeric-syntax "-1-2i" (make-rectangular -1 -2)) |
|
(test-numeric-syntax "+i" (make-rectangular 0 1) "+i" "+1i" "0+i" "0+1i") |
|
(test-numeric-syntax "0+i" (make-rectangular 0 1) "+i" "+1i" "0+i" "0+1i") |
|
(test-numeric-syntax "0+1i" (make-rectangular 0 1) "+i" "+1i" "0+i" "0+1i") |
|
(test-numeric-syntax "-i" (make-rectangular 0 -1) "-i" "-1i" "0-i" "0-1i") |
|
(test-numeric-syntax "0-i" (make-rectangular 0 -1) "-i" "-1i" "0-i" "0-1i") |
|
(test-numeric-syntax "0-1i" (make-rectangular 0 -1) "-i" "-1i" "0-i" "0-1i") |
|
(test-numeric-syntax "+2i" (make-rectangular 0 2) "2i" "+2i" "0+2i") |
|
(test-numeric-syntax "-2i" (make-rectangular 0 -2) "-2i" "0-2i")) |
|
(else |
|
|
|
(test-numeric-syntax "1.0+2i" (make-rectangular 1.0 2) "1.0+2.0i" "1.0+2i" "1.+2i" "1.+2.i") |
|
(test-numeric-syntax "1+2.0i" (make-rectangular 1 2.0) "1.0+2.0i" "1+2.0i" "1.+2.i" "1+2.i") |
|
(test-numeric-syntax "1e2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i") |
|
(test-numeric-syntax "1s2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i") |
|
(test-numeric-syntax "1.0+1e2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i") |
|
(test-numeric-syntax "1.0+1s2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i") |
|
|
|
(cond-expand |
|
(exact-complex |
|
(test-numeric-syntax "1/2+3/4i" (make-rectangular (/ 1 2) (/ 3 4)))) |
|
(else |
|
|
|
(test-numeric-syntax "0.5+3/4i" (make-rectangular 0.5 (/ 3 4)) |
|
"0.5+0.75i" ".5+.75i" "0.5+3/4i" ".5+3/4i" "500.0e-3+750.0e-3i") |
|
|
|
|
|
(test-numeric-syntax "+inf.0+inf.0i" (make-rectangular +inf.0 +inf.0) "+Inf.0+Inf.0i") |
|
(test-numeric-syntax "-inf.0+inf.0i" (make-rectangular -inf.0 +inf.0) "-Inf.0+Inf.0i") |
|
(test-numeric-syntax "-inf.0-inf.0i" (make-rectangular -inf.0 -inf.0) "-Inf.0-Inf.0i") |
|
(test-numeric-syntax "+inf.0-inf.0i" (make-rectangular +inf.0 -inf.0) "+Inf.0-Inf.0i") |
|
|
|
|
|
|
|
|
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
|
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
|
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
|
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
|
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(cond-expand |
|
(exact-complex |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(test-numeric-syntax " |
|
(else |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(test-end) |
|
|
|
(test-end) |
|
|
|
(test-begin "6.14 System interface") |
|
|
|
|
|
|
|
|
|
|
|
(test |
|
|
|
|
|
|
|
(let ((env (get-environment-variables))) |
|
(define (env-pair? x) |
|
(and (pair? x) (string? (car x)) (string? (cdr x)))) |
|
(define (all? pred ls) |
|
(or (null? ls) (and (pred (car ls)) (all? pred (cdr ls))))) |
|
(test |
|
(test |
|
|
|
(test |
|
|
|
(test |
|
(test |
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
|
|
(test |
|
(test |
|
|
|
(failing-test |
|
"https://bugs.gnu.org/38237" |
|
|
|
(guard (exn (else exn)) |
|
(delete-file " no such file ")))) |
|
|
|
(test-end) |
|
|
|
(test-end) |
|
|
|
(undo-install-r7rs!) |
|
|