display.scm 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. (define (display-symbol form) (%display form))
  2. (define (display-char ch) (%display ch))
  3. (define (display-chars ch) (for-each display-char ch))
  4. (define (display-boolean form)
  5. (if form
  6. (display-chars '(#\# #\t))
  7. (display-chars '(#\# #\f))))
  8. (define (display-int form) (%display form))
  9. (define (display-aux readable? form)
  10. (cond ((symbol? form) (display-symbol form))
  11. ((string? form)
  12. (when readable?
  13. (display-char #\"))
  14. (%display form) ;; TODO escaping
  15. (when readable?
  16. (display-char #\")))
  17. ((char? form)
  18. (when readable?
  19. (display-chars '(#\# #\\)))
  20. (display-char form)) ;; TODO newlien space etc.
  21. ((boolean? form) (display-boolean form))
  22. ((number? form) (display-int form))
  23. ((null? form) (display-chars '(#\( #\))))
  24. ((vector? form)
  25. (display-char #\#)
  26. (display-aux readable? (vector->list form)))
  27. ((pair? form)
  28. (display-char #\()
  29. (let loop ((form form))
  30. (display-aux readable? (car form))
  31. (cond ((null? (cdr form))
  32. (display-char #\)))
  33. ((pair? (cdr form))
  34. (display-char #\space)
  35. (loop (cdr form)))
  36. (else (display-chars '(#\space #\. #\space))
  37. (display-aux readable? (cdr form))
  38. (display-char #\))))))
  39. (else
  40. (%display "[????]"))))
  41. (define (display p) (display-aux #f p))
  42. (define (write p) (display-aux #t p))
  43. (define (print p) (display-aux #t p) (newline))