mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-19 21:59:17 +02:00
They can be close()d explicitly with close-file-descriptor, and will close() on gc, but only explicitly closing the last port on them will close the fileno. Notably needed for network sockets where we open separate input and output ports on the same socket.
45 lines
931 B
Scheme
45 lines
931 B
Scheme
|
|
(cond-expand
|
|
(modules (import (chibi) (chibi test) (srfi 16)))
|
|
(else #f))
|
|
|
|
(define plus
|
|
(case-lambda
|
|
(() 0)
|
|
((x) x)
|
|
((x y) (+ x y))
|
|
((x y z) (+ (+ x y) z))
|
|
(args (apply + args))))
|
|
|
|
(test-begin "case-lambda")
|
|
|
|
(test 0 (plus))
|
|
(test 1 (plus 1))
|
|
(test 6 (plus 1 2 3))
|
|
(test-error ((case-lambda ((a) a) ((a b) (* a b))) 1 2 3))
|
|
|
|
(define print
|
|
(case-lambda
|
|
(()
|
|
(display ""))
|
|
((arg)
|
|
(display arg))
|
|
((arg . args)
|
|
(display arg)
|
|
(display " ")
|
|
(apply print args))))
|
|
|
|
(define (print-to-string . args)
|
|
(let ((out (open-output-string))
|
|
(old-out (current-output-port)))
|
|
(dynamic-wind
|
|
(lambda () (current-output-port out))
|
|
(lambda () (apply print args))
|
|
(lambda () (current-output-port old-out)))
|
|
(get-output-string out)))
|
|
|
|
(test "" (print-to-string))
|
|
(test "hi" (print-to-string 'hi))
|
|
(test "hi there world" (print-to-string 'hi 'there 'world))
|
|
|
|
(test-end)
|