main.ss
;; $Id: main.ss,v 1.12 2009/05/15 23:48:08 neilpair Exp $

#lang r5rs

(#%require (only scheme/base
                 error
                 print-mpair-curly-braces
                 print-pair-curly-braces
                 random)
           (planet soegaard/sicp/sicp))

(define-syntax sicp-error
  (syntax-rules ()
    ((_ REASON ARG ...) (error REASON ARG ...))))

(define true #t)

(define false #f)

(define nil '())

(define (identity x) x)

(define (inc x) (+ x 1))

(define (dec x) (- x 1))

(define (sicp-random x)
  (if (zero? x)
      (error "You called \"(random 0)\".  If you're doing SICP section 1.2.6, don't use 1 for the first argument of \"fast-prime?\".")
      (random x)))

(define-syntax sicp-syntax-error
  (syntax-rules ()
    ((_) #f)))

;; Note: This only works with top-level "define" in PLT.
;;
;; (define-syntax sicp-define
;;   (syntax-rules ()
;;     ((_ A B0 B1 ...)
;;      (sicp-define:1 (define A B0 B1 ...) A))))
;;
;; (define-syntax sicp-define:1
;;   (syntax-rules ()
;;     ((_ DEF (X0 X1 ...))
;;      (sicp-define:1 DEF  X0))
;;     ((_ DEF ())
;;      (%sicp-syntax-error "Invalid define form"))
;;     ((_ DEF X0)
;;      (begin DEF (quote X0)))))

(define-syntax check-expect
  (syntax-rules ()
    ((_ VAL EXPECT)
     (begin (display "check-expect: ")
            (write (quote VAL))
            (display " \u21D2 ")
            (let ((v VAL)
                  (e EXPECT))
              (display v)
              (newline)
              (if (equal? val e)
                  (values)
                  (error 'check-expect
                         "Test failed: expected ~S"
                         e)))))))

(#%provide
 (for-syntax syntax-rules ...)
 (all-from r5rs)
 (all-from (planet soegaard/sicp/sicp))
 (rename sicp-error  error)
 (rename sicp-random random)
 check-expect
 dec
 false
 identity
 inc
 nil
 true)