list-interface.scm 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. ; Copyright (c) 1993-2008 by Richard Kelsey and Jonathan Rees. See file COPYING.
  2. ; ,open interfaces packages meta-types sort syntactic
  3. ; ,config scheme
  4. ; Print out the names and types exported by THING, which is either a structure
  5. ; or an interface.
  6. (define (list-interface thing)
  7. (cond ((structure? thing)
  8. (list-interface-1 (structure-interface thing)
  9. (lambda (name type)
  10. (let ((x (structure-lookup thing name #t)))
  11. (if (binding? x)
  12. (binding-type x)
  13. #f)))))
  14. ((interface? thing)
  15. (list-interface-1 thing
  16. (lambda (name type)
  17. type)))
  18. (else '?)))
  19. ; LOOKUP is passed the package-name and the type from the interface and
  20. ; returns a (possibly different) type.
  21. (define (list-interface-1 int lookup)
  22. (let ((names '()))
  23. (for-each-declaration (lambda (name package-name type)
  24. (if (not (assq name names)) ;compound signatures...
  25. (set! names
  26. (cons (cons name
  27. (lookup package-name type))
  28. names))))
  29. int)
  30. (for-each (lambda (pair)
  31. (let ((name (car pair))
  32. (type (cdr pair)))
  33. (write name)
  34. (display (make-string
  35. (max 0 (- 25 (string-length
  36. (symbol->string name))))
  37. #\space))
  38. (write-char #\space)
  39. (write (careful-type->sexp type)) ;( ...)
  40. (newline)))
  41. (sort-list names
  42. (lambda (pair1 pair2)
  43. (string<? (symbol->string (car pair1))
  44. (symbol->string (car pair2))))))))
  45. (define (careful-type->sexp thing)
  46. (cond ((not thing) 'undefined)
  47. ((or (symbol? thing)
  48. (null? thing)
  49. (number? thing))
  50. thing) ;?
  51. ((pair? thing) ;e.g. (variable #{Type :value})
  52. (cons (careful-type->sexp (car thing))
  53. (careful-type->sexp (cdr thing))))
  54. (else
  55. (type->sexp thing #t))))