ps-utils.scm 1011 B

123456789101112131415161718192021222324252627282930313233
  1. ;;; ps-utils --- Utilities for Pre-Scheme
  2. (define-syntax when
  3. (syntax-rules ()
  4. ((_ condition consequent ...)
  5. (if condition
  6. (begin consequent ...)))))
  7. (define-syntax unless
  8. (syntax-rules ()
  9. ((_ condition antecedent ...)
  10. (if (not condition)
  11. (begin antecedent ...)))))
  12. (define-syntax define-wrapper-type
  13. (lambda (exp rename compare)
  14. (define (symbol-append . args)
  15. (string->symbol
  16. (apply string-append (map (lambda (s)
  17. (if (string? s) s (symbol->string s)))
  18. args))))
  19. (let* ((name (cadr exp))
  20. (type-id (symbol-append ":" name))
  21. (constructor (rename (symbol-append "make-" name)))
  22. (%begin (rename 'begin))
  23. (%define-record-type (rename 'define-record-type))
  24. (%define-external (rename 'define-external)))
  25. `(,%define-record-type ,name ,type-id
  26. (,constructor)))))
  27. (define (zero? n) (= n 0))
  28. (define (one? n) (= n 1))