test-alist-ref: pass
(define (test-alist-ref _)
(let ((alst '((a 3) (b 2))))
(⊦= '(3) (alist-ref 'a alst))
(⊦= '(2) (alist-ref 'b alst))
(⊦= #f (alist-ref 'c alst))))
((eta 0.002) (memory #(6291456 1313168 1048576)) (stdout "") (stderr ""))
test/len: pass
(define (test/len _)
(let ((my-strlen
(foreign-lambda*
int
((scheme-object cons))
"C_return(C_header_size(cons));")))
(⊦= 2 (my-strlen (cons 1 '())))
(⊦= 2 (my-strlen (cons 1 (cons 2 (cons 3 '())))))
(⊦= 11 (my-strlen "hello world"))))
((eta 0.001) (memory #(6291456 1314104 1048576)) (stdout "") (stderr ""))
test/unquote: pass
Very interesting test about quasiquotation Quasiquotation, Chicken Scheme manual. : it shows how unquote can be used in a quasiquotation pattern in the cdr slot.
(define (test/unquote _) (let1 (a '(3)) (⊦= (cons 1 a) `(1 unquote a))))
((eta 0.0) (memory #(6291456 1315384 1048576)) (stdout "") (stderr ""))
test/c_callback: pass
(define (test/c_callback _)
(let ((witness (gensym))
(my-strlen
(foreign-safe-lambda*
scheme-object
((scheme-object f))
"\t\t\t\t\t C_word res = C_callback(f, 0);\n\t\t\t\t\t printf(\"from within a safe lambda\\n\");\n\t\t\t\t\t C_return (res);")))
(⊦= witness (car (my-strlen (lambda () (list witness 4)))))))
((eta 0.001) (memory #(6291456 1316352 1048576)) (stdout "") (stderr ""))
test/foreign-safe-lambda*/allocate_string/inline: pass
(define (test/foreign-safe-lambda*/allocate_string/inline _)
(let1 (allocate_string
(foreign-safe-lambda*
scheme-object
()
" char* str = \"hello world\";\n C_word length = strlen(str);\n C_word* ptr = C_alloc (C_SIZEOF_STRING (length));\n C_word res = C_string (&ptr, length, str);\n C_return (res);"))
(⊦= "hello world" (allocate_string))))
((eta 0.0) (memory #(6291456 1317392 1048576)) (stdout "") (stderr ""))
test/foreign-primitive/allocate-string: pass
An example of foreign-primitive foreign-primitive, Chicken Scheme manual. that allocates a string in C and returns it to Scheme. The C code is inlined in the Scheme source code.
(define (test/foreign-primitive/allocate-string _)
(let1 (allocate_string
(foreign-primitive scheme-object () "C_my_allocate_string(C_k);"))
(⊦= "hello world" (allocate_string))))
((eta 0.001) (memory #(6291456 1318864 1048576)) (stdout "") (stderr ""))
test/foreign-safe-lambda/list-walk: pass
(define (test/foreign-safe-lambda/list-walk _)
(let1 (list-walk
(foreign-safe-lambda
scheme-object
"C_list_walk"
scheme-object
scheme-object))
(⊦= '(1 2 3) (list-walk '(1 2 3) identity))))
((eta 0.001) (memory #(6291456 1319880 1048576)) (stdout "") (stderr ""))
test/foreign/callout-callin: pass
This test shows how to call out to C code that in turn calls back into Scheme code. The C code is in the file bar.c, and the function called from Scheme is callout. The function that is called back from C into Scheme is callin. Taken from the Chicken Scheme manual An example for simple calls to foreign code involving callbacks, Chicken Scheme manual..
(define (test/foreign/callout-callin _)
(define callout (foreign-safe-lambda int "callout" int int int))
(define-external
(callin (scheme-object xyz))
int
(print "This is 'callin': " xyz)
123)
(⊦= 123 (callout 1 2 3)))
((eta 0.001)
(memory #(6291456 1321536 1048576))
(stdout "This is 'callin': (1 2 3)\n")
(stderr ""))
test/string/ref: pass
(define (test/string/ref _) (⊦ equal? #\o (string-ref "hello" 4)))
((eta 0.0) (memory #(6291456 1322504 1048576)) (stdout "") (stderr ""))
test/string/first: pass
(define (test/string/first _) (⊦ equal? #\h (first/string "hello")))
((eta 0.0) (memory #(6291456 1323488 1048576)) (stdout "") (stderr ""))
test/string/last: pass
(define (test/string/last _) (⊦ equal? #\o (last/string "hello")))
((eta 0.0) (memory #(6291456 1324464 1048576)) (stdout "") (stderr ""))
test/string/take-right: pass
(define (test/string/take-right _)
(⊦ equal? "o" (string-take-right "hello" 1)))
((eta 0.0) (memory #(6291456 1325448 1048576)) (stdout "") (stderr ""))
test-null-eq?: pass
(define (test-null-eq? _) (⊨ (eq? '() '())))
((eta 0.0) (memory #(6291456 1326416 1048576)) (stdout "") (stderr ""))
test-last-syntax: pass
(define (test-last-syntax _)
(define-syntax-rule (var-last body ... last) last)
(⊦ equal? 'a (var-last 'a))
(⊦ equal? 7 (var-last 'a (+ 3 4))))
((eta 0.0) (memory #(6291456 1327392 1048576)) (stdout "") (stderr ""))
test-syntax-with-_: pass
(define (test-syntax-with-_ _)
(define-syntax
with-underscore
(syntax-rules () ((_ body ...) (list '_ body ...))))
(⊦ equal? '(_ a) (with-underscore 'a)))
((eta 0.0) (memory #(6291456 1328376 1048576)) (stdout "") (stderr ""))
test-syntax-with-literal: pass
(define (test-syntax-with-literal _)
(define where +)
(define-syntax-rule (literal where) (my-macro a where b) '(a b where))
(⊦ equal? '(c d where) (my-macro c where d)))
((eta 0.0) (memory #(6291456 1329368 1048576)) (stdout "") (stderr ""))
test-syntax-with-literal-and-ellipses: pass
(define (test-syntax-with-literal-and-ellipses _)
(define-syntax-rule (literal :) (my-macro a ... : b ...) '((a ...) (b ...)))
(⊦ equal? '((a b c) (d e)) (my-macro a b c : d e)))
((eta 0.0) (memory #(6291456 1330384 1048576)) (stdout "") (stderr ""))
test-vec-syntax: pass
(define (test-vec-syntax _)
(define-syntax-rule
(v-aux (v #(x z ... y)) body ...)
(let1 (v (list z ...)) body ...))
(⊦ equal? '(0 2) (v-aux (v #(1 2 3)) (cons 0 v))))
((eta 0.0) (memory #(6291456 1331352 1048576)) (stdout "") (stderr ""))
Categories: scheme
See also
CHICKEN Scheme
Versions and implementation notes
The SBRAL data structure
Skew Binary Random-Access Lists
Pattern matching
Scheme macrology: a generalized pattern matcher
The (aux hansei) module
The (aux nondeterministic) module
The (aux stream) module
The (aux unittest) module
Bootstrapping a unittest framework
Scheme lang: Chez, 48 and Chicken
Some docs, refs and containers, respectively.
The Reasoned Schemer
miniKanren, microKanren and some implementations
Aggregation predicates for µkanren
Groups, window functions, sets and enumerations
miniKanren, live and untagged
Quine generation via relational interpreters
Pure, declarative, and constructive arithmetic relations
A declarative pearl
Final shift for call/cc
Direct implementation of shift and reset
Call with Current Continuation Patterns
Cogen in six lines
The Seasoned Schemer
The Little Schemer
Adding generic functions to Scheme
Handling control