mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-22 07:09:17 +02:00
More robust version of (scheme lazy)
This commit is contained in:
parent
4dda1b8a49
commit
5fbdc54628
2 changed files with 30 additions and 16 deletions
|
@ -10,6 +10,7 @@ Features
|
||||||
|
|
||||||
Bug Fixes
|
Bug Fixes
|
||||||
|
|
||||||
|
- Improved `(scheme lazy)` to allow `force` and `make-promise` to accept an argument of any type. Improved representation of promises to more precisely differentiate them from other objects.
|
||||||
- Add type checking to record type accessor functions. We now raise an error if the passed object is of the wrong record type.
|
- Add type checking to record type accessor functions. We now raise an error if the passed object is of the wrong record type.
|
||||||
- Fix issues with expanding `cond-expand` expressions in libraries. Previously there would be issues with the expansion if the code needed to be within the context of a `begin`.
|
- Fix issues with expanding `cond-expand` expressions in libraries. Previously there would be issues with the expansion if the code needed to be within the context of a `begin`.
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,19 @@
|
||||||
)
|
)
|
||||||
(begin
|
(begin
|
||||||
|
|
||||||
|
;; promise
|
||||||
|
;; ( tag value/obj )
|
||||||
|
|
||||||
|
(define *promise-tag* '(promise))
|
||||||
|
(define (promise? obj)
|
||||||
|
(and (pair? obj)
|
||||||
|
(eq? *promise-tag* (car obj))))
|
||||||
|
|
||||||
(define force
|
(define force
|
||||||
(lambda (object)
|
(lambda (obj)
|
||||||
(object)))
|
(if (promise? obj)
|
||||||
|
((cdr obj))
|
||||||
|
obj)))
|
||||||
|
|
||||||
(define-syntax delay
|
(define-syntax delay
|
||||||
(er-macro-transformer
|
(er-macro-transformer
|
||||||
|
@ -32,20 +42,23 @@
|
||||||
`(make-promise (lambda () ,(cadr expr))))))
|
`(make-promise (lambda () ,(cadr expr))))))
|
||||||
|
|
||||||
(define make-promise
|
(define make-promise
|
||||||
(lambda (proc)
|
(lambda (obj)
|
||||||
|
(if (promise? obj)
|
||||||
|
obj
|
||||||
(let ((result-ready? #f)
|
(let ((result-ready? #f)
|
||||||
(result #f))
|
(result #f))
|
||||||
|
(cons
|
||||||
|
*promise-tag*
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(if result-ready?
|
(if result-ready?
|
||||||
result
|
result
|
||||||
(let ((x (proc)))
|
(let ((x (if (procedure? obj)
|
||||||
|
(obj)
|
||||||
|
obj)))
|
||||||
(if result-ready?
|
(if result-ready?
|
||||||
result
|
result
|
||||||
(begin (set! result x)
|
(begin (set! result x)
|
||||||
(set! result-ready? #t)
|
(set! result-ready? #t)
|
||||||
result))))))))
|
result))))))))))
|
||||||
|
|
||||||
;; Not a very satisfying implementation, but would need to change
|
|
||||||
;; how promises are stored to do better
|
|
||||||
(define promise? procedure?)
|
|
||||||
))
|
))
|
||||||
|
|
Loading…
Add table
Reference in a new issue