boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

109-values-cwv.scm (668B)


      1 ; values + call-with-values: producer yields 2+ values, consumer
      2 ; receives them as positional args.
      3 
      4 (if (= 6 (call-with-values (lambda () (values 1 2 3)) +)) 0 (sys-exit 1))
      5 
      6 (if (= 5 (call-with-values
      7            (lambda () (values 2 3))
      8            (lambda (a b) (+ a b))))
      9     0 (sys-exit 2))
     10 
     11 ; Producer yielding a single value via (values x): receiver gets x.
     12 (if (= 7 (call-with-values
     13            (lambda () (values 7))
     14            (lambda (x) x)))
     15     0 (sys-exit 3))
     16 
     17 ; Producer returning a bare (non-values) value also flows as a single arg.
     18 (if (= 42 (call-with-values
     19             (lambda () 42)
     20             (lambda (x) x)))
     21     0 (sys-exit 4))
     22 
     23 (sys-exit 0)