git @ Cat's Eye Technologies Dipple / master scheme / utils.scm
master

Tree @master (Download .tar.gz)

utils.scm @masterraw · history · blame

; SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
; For more information, please refer to <https://unlicense.org/>
; SPDX-License-Identifier: Unlicense

;
; Useful R5RS utility functions for testing and debugging.
; In the public domain, so feel free to just copy them into your code.
;

(define-syntax print
  (syntax-rules ()
    ((print e)
      (display e))
    ((print e1 e2 ...)
      (begin (display e1)
             (print e2 ...)))))

(define-syntax println
  (syntax-rules ()
    ((println e)
      (begin (display e)
             (newline)))
    ((println e1 e2 ...)
      (begin (display e1)
             (println e2 ...)))))

(define-syntax test
  (syntax-rules ()
    ((test test-name expr expected)
      (begin
        (print "Running test: " (quote test-name) "... ")
        (let ((result expr))
          (cond
            ((equal? result expected)
              (println "passed."))
            (else
              (println "FAILED!")
              (println "Expected: " expected)
              (println "Actual:   " result))))))))