mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-06 20:56:36 +02:00
Experimental (call-with-values)
This commit is contained in:
parent
1436694c80
commit
2d664f1e06
2 changed files with 13 additions and 9 deletions
18
cyclone.scm
18
cyclone.scm
|
@ -134,18 +134,18 @@
|
||||||
(set! module-globals (cons 'call/cc module-globals))
|
(set! module-globals (cons 'call/cc module-globals))
|
||||||
(set! input-program
|
(set! input-program
|
||||||
(cons
|
(cons
|
||||||
;; Experimental version of call-with-values, but this
|
;; Experimental version of call-with-values,
|
||||||
;; is not working yet!
|
;; seems OK in compiler but not in eval.
|
||||||
;;
|
|
||||||
;; may want to look at:
|
|
||||||
;; http://stackoverflow.com/questions/16674214/how-to-implement-call-with-values-to-match-the-values-example-in-r5rs
|
|
||||||
'(define call-with-values
|
'(define call-with-values
|
||||||
(lambda (k producer consumer)
|
(lambda (k producer consumer)
|
||||||
(producer
|
(producer
|
||||||
(lambda (val)
|
(lambda (result)
|
||||||
(consumer k val)))))
|
(consumer k result)))))
|
||||||
;(lambda vals
|
;; multiple args requires more than just this.
|
||||||
; (apply k consumer vals)))))
|
;; may want to look at:
|
||||||
|
;; http://stackoverflow.com/questions/16674214/how-to-implement-call-with-values-to-match-the-values-example-in-r5rs
|
||||||
|
;; (lambda vals
|
||||||
|
;; (apply k consumer vals)))))
|
||||||
(cons
|
(cons
|
||||||
;; call/cc must be written in CPS form, so it is added here
|
;; call/cc must be written in CPS form, so it is added here
|
||||||
;; TODO: prevents this from being optimized-out
|
;; TODO: prevents this from being optimized-out
|
||||||
|
|
4
test.scm
4
test.scm
|
@ -20,3 +20,7 @@
|
||||||
(define b (vector 10 20 30 40 50))
|
(define b (vector 10 20 30 40 50))
|
||||||
(vector-copy! b 1 a 0 2)
|
(vector-copy! b 1 a 0 2)
|
||||||
(write (equal? b #(10 1 2 40 50)))
|
(write (equal? b #(10 1 2 40 50)))
|
||||||
|
(call-with-values
|
||||||
|
(lambda () (values 1 1))
|
||||||
|
(lambda (a) (write a)))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue