Write
Write a byte
Section titled “Write a byte”Given a file named “main.scm” with:
(import (scheme base))
(write-u8 65)
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Write a character
Section titled “Write a character”Given a file named “main.scm” with:
(import (scheme base))
(write-char #\<value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<value>”.
Examples
Section titled “Examples”value |
---|
a |
A |
~ |
Write a multi-byte character
Section titled “Write a multi-byte character”Given a file named “main.scm” with:
(import (scheme base))
(write-char #\<value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<value>”.
Examples
Section titled “Examples”value |
---|
д |
∰ |
😄 |
Write an escaped character
Section titled “Write an escaped character”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write <value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<output>”.
Examples
Section titled “Examples”value | output |
---|---|
#\a | #\a |
#\A | #\A |
#( | #\( |
## | #\# |
Write an escaped special character
Section titled “Write an escaped special character”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write <value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<output>”.
Examples
Section titled “Examples”value | output |
---|---|
#\alarm | #\alarm |
#\backspace | #\backspace |
#\delete | #\delete |
#\escape | #\escape |
#\newline | #\newline |
#\null | #\null |
#\return | #\return |
#\space | #\space |
#\tab | #\tab |
Write a string
Section titled “Write a string”Given a file named “main.scm” with:
(import (scheme base))
(write-string "Hello, world!")
When I successfully run stak main.scm
Then the stdout should contain exactly “Hello, world!”.
Write a special character in a string
Section titled “Write a special character in a string”Given a file named “main.scm” with:
(import (scheme base))
(write-string "<value>")
When I successfully run stak main.scm
Then the stdout should contain exactly “<value>”.
Examples
Section titled “Examples”value |
---|
\n |
\t |
” |
Write a boolean
Section titled “Write a boolean”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write <value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<value>”.
Examples
Section titled “Examples”value |
---|
#f |
#t |
Write a list
Section titled “Write a list”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write '<value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<value>”.
Examples
Section titled “Examples”value |
---|
() |
(1) |
(1 2) |
(1 2 3) |
(1 (1 2) (3 4 5)) |
(1 . 2) |
(1 2 . 3) |
Write a number
Section titled “Write a number”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write <value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<value>”.
Examples
Section titled “Examples”value |
---|
0 |
1 |
42 |
-1 |
-42 |
Write a procedure
Section titled “Write a procedure”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write (lambda () #f))
When I successfully run stak main.scm
Then the stdout should contain exactly “#procedure”.
Write a record
Section titled “Write a record”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(define-record-type foo (make-foo) foo?)
(write (make-foo))
When I successfully run stak main.scm
Then the stdout should contain exactly “#record”.
Write a quoted string
Section titled “Write a quoted string”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write "<value>")
When I successfully run stak main.scm
Then the stdout should contain exactly ""<output>"".
Examples
Section titled “Examples”value | output |
---|---|
foo | foo |
Hello, world! | Hello, world! |
\n | \n |
\t | \t |
\r | \r |
\n\t\r | \n\t\r |
Write a symbol
Section titled “Write a symbol”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write 'foo)
When I successfully run stak main.scm
Then the stdout should contain exactly “foo”.
Write an empty symbol
Section titled “Write an empty symbol”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write (string->symbol ""))
When I successfully run stak main.scm
Then the stdout should contain exactly ”||”.
Write a vector
Section titled “Write a vector”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write <value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<value>”.
Examples
Section titled “Examples”value |
---|
#() |
#(1) |
#(1 2) |
#(1 2 3) |
#(1 #(1 2) #(3 4 5)) |
Write a byte vector
Section titled “Write a byte vector”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write <value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<value>”.
Examples
Section titled “Examples”value |
---|
#u8() |
#u8(1) |
#u8(1 2) |
#u8(1 2 3) |
Write to a port
Section titled “Write to a port”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write '(42 foo #f) (current-output-port))
When I successfully run stak main.scm
Then the stdout should contain exactly “(42 foo #f)”.
Write a quote
Section titled “Write a quote”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write '<value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<value>”.
Examples
Section titled “Examples”value |
---|
’() |
`() |
`(,1) |
(quote) |
(quasiquote) |
(unquote) |
(quote . 42) |
(quasiquote . 42) |
(unquote . 42) |
Write a value in a collection
Section titled “Write a value in a collection”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(write '<value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<output>”.
Examples
Section titled “Examples”value | output |
---|---|
(#\a) | (#\a) |
(#\space) | (#\space) |
(“foo”) | (“foo”) |
((#\a)) | ((#\a)) |
((#\space)) | ((#\space)) |
((“foo”)) | ((“foo”)) |
#(#\a) | #(#\a) |
#(#\space) | #(#\space) |
#(“foo”) | #(“foo”) |
#(#(#\a)) | #(#(#\a)) |
#(#(#\space)) | #(#(#\space)) |
#(#(“foo”)) | #(#(“foo”)) |
Display a value
Section titled “Display a value”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(display '<value>)
When I successfully run stak main.scm
Then the stdout should contain exactly “<output>”.
Examples
Section titled “Examples”value | output |
---|---|
#\a | a |
”foo” | foo |
(#\a) | (a) |
(#\space) | ( ) |
(“foo”) | (foo) |
((#\a)) | ((a)) |
((#\space)) | (( )) |
((“foo”)) | ((foo)) |
#(#\a) | #(a) |
#(#\space) | #( ) |
#(“foo”) | #(foo) |
#(#(#\a)) | #(#(a)) |
#(#(#\space)) | #(#( )) |
#(#(“foo”)) | #(#(foo)) |
Flush a port
Section titled “Flush a port”Given a file named “main.scm” with:
(import (scheme base))
(flush-output-port)
When I successfully run stak main.scm
Then the exit status should be 0.
Recursive values
Section titled “Recursive values”Write a recursive pair
Section titled “Write a recursive pair”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(define x (cons 42 #f))(set-cdr! x x)
(<procedure> x)
When I successfully run stak main.scm
Then the stdout should contain exactly “#0=(42 . #0#)”.
Examples
Section titled “Examples”procedure |
---|
write |
write-shared |
Write recursive pairs
Section titled “Write recursive pairs”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(define x (cons (cons 123 #f) (cons #f 42)))(set-cdr! (car x) x)(set-car! (cdr x) (cdr x))
(<procedure> x)
When I successfully run stak main.scm
Then the stdout should contain exactly “#0=((123 . #0#) . #1=(#1# . 42))”.
Examples
Section titled “Examples”procedure |
---|
write |
write-shared |
Write a recursive vector
Section titled “Write a recursive vector”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(define x (vector 42 #f))(vector-set! x 1 x)
(<procedure> x)
When I successfully run stak main.scm
Then the stdout should contain exactly “#0=#(42 #0#)”.
Examples
Section titled “Examples”procedure |
---|
write |
write-shared |
Shared values
Section titled “Shared values”Write a shared pair
Section titled “Write a shared pair”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(define x (cons 42 #f))
(<procedure> (cons x x))
When I successfully run stak main.scm
Then the stdout should contain exactly “<output>”.
Examples
Section titled “Examples”procedure | output |
---|---|
write | ((42 . #f) 42 . #f) |
write-shared | (#0=(42 . #f) . #0#) |
Write a shared vector
Section titled “Write a shared vector”Given a file named “main.scm” with:
(import (scheme base) (scheme write))
(define x #(42 #f))
(<procedure> (vector x x))
When I successfully run stak main.scm
Then the stdout should contain exactly “<output>”.
Examples
Section titled “Examples”procedure | output |
---|---|
write | #(#(42 #f) #(42 #f)) |
write-shared | #(#0=#(42 #f) #0#) |