Next: , Previous: , Up: lang   [Index]


1.14 Pipelining expressions

The following bindings are exported by the library (vicare language-extensions pipelines).

Syntax: pipeline ?producer => ?formals ?consumer
Auxiliary Syntax: =>

Allow a sequence of producer/consumer expressions to be written with simpler and less indented syntax. The following expansions are implemented:

(pipeline ?producer => ?formals ?consumer)
→ (call-with-values
        (lambda () ?producer)
      (lambda ?formals ?consumer))

(pipeline ?producer
  => ?formals0
  ?consumer0
  => ?formals1
  ?consumer1)
→ (call-with-values
        (lambda () ?producer)
      (lambda ?formals0
        (call-with-values
            (lambda () ?consumer0)
          (lambda ?formals1
            ?consumer1))))

The auxiliary syntax => is the one exported by (rnrs base (6)).

Examples:

(pipeline 1)
⇒ 1

(pipeline
  1.2
  => (x0)
  (sin x0)
  => (x1)
  (cos x1)
  => (x2)
  (tan x2)
  => (x3)
  x3)
≡ (tan (cos (sin 1.2)))

(pipeline
  (values 1 2)
  => (a0 b0)
  (values (times10 a0) (times10 b0))
  => (a1 b1)
  (values (times10 a1) (times10 b1))
  => (a2 b2)
  (values (times10 a2) (times10 b2))
  => (a3 b3)
  (list a3 b3))
⇒ (1000 2000)

(pipeline
  (values 1 2 3 4)
  => (a0 b0 . rest0)
  (apply values (times10 a0) (times10 b0) (map times10 rest0))
  => (a1 b1 . rest1)
  (apply values (times10 a1) (times10 b1) (map times10 rest1))
  => (a2 b2 . rest2)
  (apply values (times10 a2) (times10 b2) (map times10 rest2))
  => (a3 b3 . rest3)
  (cons* a3 b3 rest3))
⇒ (1000 2000 3000 4000)