Evaluation
Import an eval
library
Section titled “Import an eval library”Given a file named “main.scm” with:
(import (scheme eval))
When I successfully run stak main.scm
Then the exit status should be 0.
Evaluate false
Section titled “Evaluate false”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(write-u8 (if (eval #f (environment)) 65 66))
When I successfully run stak main.scm
Then the stdout should contain exactly “B”.
Evaluate a number
Section titled “Evaluate a number”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(write-u8 (eval 65 (environment)))
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Evaluate a string
Section titled “Evaluate a string”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(write-string (eval "foo" (environment)))
When I successfully run stak main.scm
Then the stdout should contain exactly “foo”.
Use an environment
Section titled “Use an environment”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(write-u8 (eval 65 (environment '(scheme base))))
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Use two environments
Section titled “Use two environments”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(write-u8 (eval 65 (environment '(scheme base) '(scheme write))))
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Use an interaction environment
Section titled “Use an interaction environment”Given a file named “main.scm” with:
(import (scheme base) (scheme eval) (scheme repl))
(write-u8 (eval 65 (interaction-environment)))
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Define variables in an interaction environment
Section titled “Define variables in an interaction environment”Given a file named “main.scm” with:
(import (scheme base) (scheme eval) (scheme repl))
(eval '(import (scheme base)) (interaction-environment))(eval '(define x 42) (interaction-environment))(eval '(define y 23) (interaction-environment))(write-u8 (eval '(+ x y) (interaction-environment)))
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Environment
Section titled “Environment”Use a define
syntax with a variable
Section titled “Use a define syntax with a variable”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(eval '(begin (define x 65) (write-u8 x)) (environment '(scheme base)))
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Use a define
syntax with a procedure
Section titled “Use a define syntax with a procedure”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(eval '(begin (define (f x) (+ x 65)) (write-u8 (f 1))) (environment '(scheme base)))
When I successfully run stak main.scm
Then the stdout should contain exactly “B”.
Do not access outer environment
Section titled “Do not access outer environment”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(define x #t)
(eval '(unless x (error "Oh, no!")) (environment '(scheme base)))
When I run stak main.scm
Then the exit status should not be 0.
Do not corrupt outer environment
Section titled “Do not corrupt outer environment”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(define x 65)
(eval '(begin (define x 66)) (environment '(scheme base)))
(write-u8 x)
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Procedures
Section titled “Procedures”Use a +
procedure
Section titled “Use a + procedure”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(write-u8 (eval '(+ 60 5) (environment '(scheme base))))
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Use a display
procedure
Section titled “Use a display procedure”Given a file named “main.scm” with:
(import (scheme base) (scheme eval) (scheme write))
(eval '(display "foo") (environment '(scheme write)))
When I successfully run stak main.scm
Then the stdout should contain exactly “foo”.
Use a set!
procedure
Section titled “Use a set! procedure”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(write-u8 (eval '(let ((x 0)) (set! x 65) x) (environment '(scheme base))))
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Syntaxes
Section titled “Syntaxes”Use a begin
syntax
Section titled “Use a begin syntax”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(write-u8 (eval '(begin 42 65) (environment '(scheme base))))
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Use an if
syntax
Section titled “Use an if syntax”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(eval '(write-u8 (if <value> 65 66)) (environment '(scheme base)))
When I successfully run stak main.scm
Then the stdout should contain exactly “<output>”.
Examples
Section titled “Examples”value | output |
---|---|
#f | B |
#t | A |
Use a lambda
syntax with no argument
Section titled “Use a lambda syntax with no argument”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(write-u8 (eval '((lambda () 65)) (environment '(scheme base))))
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Use a lambda
syntax with an argument
Section titled “Use a lambda syntax with an argument”Given a file named “main.scm” with:
(import (scheme base) (scheme eval))
(write-u8 (eval '((lambda (x) x) 65) (environment '(scheme base))))
When I successfully run stak main.scm
Then the stdout should contain exactly “A”.