sicp.scm 1.2 KB

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