cond-expand
Expand an else clause
Section titled “Expand an else clause”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand (else (write-u8 65)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Match an implemented feature
Section titled “Match an implemented feature”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand (r7rs (write-u8 65)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Match a missing feature
Section titled “Match a missing feature”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand (foo (write-u8 65)) (else (write-u8 66)))When I successfully run stak main.scm
Then the stdout should contain exactly “B”.
Match an implemented library
Section titled “Match an implemented library”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((library (scheme base)) (write-u8 65)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Match a built-in library
Section titled “Match a built-in library”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((library <library>) (write-u8 65)) (else (write-u8 66)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Examples
Section titled “Examples”| library |
|---|
| (scheme char) |
| (scheme lazy) |
| library |
|---|
| (srfi 1) |
Match an imported library
Section titled “Match an imported library”Given a file named “main.scm” with:
(import (scheme base) (scheme read))
(cond-expand ((library (scheme read)) (write-u8 65)) (else (write-u8 66)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Match a library defined in a program
Section titled “Match a library defined in a program”Given a file named “main.scm” with:
(define-library (foo) (export foo)
(import (scheme base))
(begin (define foo 65)))
(import (scheme base))
(cond-expand ((library (foo)) (write-u8 65)) (else (write-u8 66)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Match a library in a load path
Section titled “Match a library in a load path”Given a file named “library/foo/bar.sld” with:
(define-library (foo bar) (export bar)
(import (scheme base))
(begin (define bar 65)))And a file named “main.scm” with:
(import (scheme base))
(cond-expand ((library (foo bar)) (write-u8 65)) (else (write-u8 66)))When I successfully run stak -I library main.scm
Then the stdout should contain exactly “A”.
Match a missing library
Section titled “Match a missing library”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((library (scheme miracle)) (write-u8 65)) (else (write-u8 66)))When I successfully run stak main.scm
Then the stdout should contain exactly “B”.
Match a library missing in a load path
Section titled “Match a library missing in a load path”Given a directory named “library”
And a file named “main.scm” with:
(import (scheme base))
(cond-expand ((library (foo bar)) (write-u8 65)) (else (write-u8 66)))When I successfully run stak -I library main.scm
Then the stdout should contain exactly “B”.
Expand only a matched library clause
Section titled “Expand only a matched library clause”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((library (scheme miracle)) (syntax-error "unexpected expansion")) (else (write-u8 65)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Match an invalid feature
Section titled “Match an invalid feature”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((lib (scheme base)) (write-u8 65)) (else (write-u8 66)))When I run stak main.scm
Then the exit status should not be 0.
Expand an empty clause
Section titled “Expand an empty clause”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand (r7rs))When I successfully run stak main.scm
Then the exit status should be 0.
Expand an empty else clause
Section titled “Expand an empty else clause”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand (else))When I successfully run stak main.scm
Then the exit status should be 0.
Use a not requirement
Section titled “Use a not requirement”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((not foo) (write-u8 65)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Use a not requirement with a library
Section titled “Use a not requirement with a library”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((not (library (scheme miracle))) (write-u8 65)) (else (write-u8 66)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Examine features
Section titled “Examine features”Given a file named “main.scm” with:
(import (scheme base))
(write-u8 (if (memq 'r7rs (features)) 65 66))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Expand no requirement
Section titled “Expand no requirement”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((and) (write-u8 65)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Expand a requirement
Section titled “Expand a requirement”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((and r7rs) (write-u8 65)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Expand two requirements
Section titled “Expand two requirements”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((and r7rs r7rs) (write-u8 65)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Expand no requirement
Section titled “Expand no requirement”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((or) (write-u8 65)) (else (write-u8 66)))When I successfully run stak main.scm
Then the stdout should contain exactly “B”.
Expand a requirement
Section titled “Expand a requirement”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((or r7rs) (write-u8 65)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.
Expand two requirements
Section titled “Expand two requirements”Given a file named “main.scm” with:
(import (scheme base))
(cond-expand ((or foo r7rs) (write-u8 65)))When I successfully run stak main.scm
Then the stdout should contain exactly “A”.