mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-06 04:36: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! input-program
|
||||
(cons
|
||||
;; Experimental version of call-with-values, but this
|
||||
;; is not working yet!
|
||||
;;
|
||||
;; may want to look at:
|
||||
;; http://stackoverflow.com/questions/16674214/how-to-implement-call-with-values-to-match-the-values-example-in-r5rs
|
||||
;; Experimental version of call-with-values,
|
||||
;; seems OK in compiler but not in eval.
|
||||
'(define call-with-values
|
||||
(lambda (k producer consumer)
|
||||
(producer
|
||||
(lambda (val)
|
||||
(consumer k val)))))
|
||||
;(lambda vals
|
||||
; (apply k consumer vals)))))
|
||||
(lambda (result)
|
||||
(consumer k result)))))
|
||||
;; multiple args requires more than just this.
|
||||
;; 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
|
||||
;; call/cc must be written in CPS form, so it is added here
|
||||
;; 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))
|
||||
(vector-copy! b 1 a 0 2)
|
||||
(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