#lang scheme/base
(provide
 (all-defined-out))

;; Lighten up verbose syntax-rules
(define-syntax define-sr
  (syntax-rules ()
    ((_ (name (args ...)) template)
     (define-syntax name
       (syntax-rules ()
         ((_ args ...) template))))
    ((_ (name . args) template)
     (define-syntax name
       (syntax-rules ()
         ((_ . args) template))))))

;; Convert anything to a port.
(define (port string/port)
  (cond
   ((string? string/port)
    (open-input-string
     (string-append string/port "\n")))
   ((port? string/port)
    string/port)
   (else
    (error 'invalid-type string/port))))


(define-sr (require/provide item ...)
  (begin
    (require item ...)
    (provide (all-from-out item ...))))


(define (make-counter init)
  (let ((state (- init 1)))
    (lambda ()
      (set! state (+ 1 state))
      state)))

(define (id . vals) (apply values vals))
(define (true . args) #t)
(define (false . args) #f)

(define-syntax-rule (fail/false expr ...)
  (with-handlers ((void false)) expr ...))


(define-syntax-rule (inc! val) (begin (set! val (add1 val)) val))

(define (resolve-module m)
  ((current-module-name-resolver) m #f #f #f))