sicp.scm 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ; Part of Scheme 48 1.9. See file COPYING for notices and license.
  2. ; Authors: Richard Kelsey, Jonathan Rees
  3. ; Compatibility mode for use with Abelson & Sussman's book,
  4. ; Structure and Interpretation of Computer Programs.
  5. ; Requires ERROR, MAKE-TABLE, TABLE-REF, and TABLE-SET!.
  6. ; Streams
  7. (define-syntax cons-stream
  8. (syntax-rules ()
  9. ((cons-stream head tail)
  10. (cons head (delay tail)))))
  11. (define stream-car car)
  12. (define (stream-cdr s) (force (cdr s)))
  13. (define the-empty-stream '(list <the-empty-stream>))
  14. (define (stream-null? s) (eq? s the-empty-stream))
  15. ; GET and PUT
  16. (define (make-property-module)
  17. (define symbol-properties-table #f)
  18. (define (put symbol indicator value)
  19. (let* ((probe (table-ref symbol-properties-table symbol))
  20. (table (if probe
  21. probe
  22. (let ((table (make-table)))
  23. (table-set! symbol-properties-table symbol table)
  24. table))))
  25. (table-set! table indicator value)))
  26. (define (get symbol indicator)
  27. (let ((probe (table-ref symbol-properties-table symbol)))
  28. (if probe
  29. (table-ref probe indicator)
  30. #f)))
  31. (set! symbol-properties-table (make-table))
  32. (cons get put))
  33. (define property-module (make-property-module))
  34. (define get (car property-module))
  35. (define put (cdr property-module))