Next: , Previous: , Up: Blocks   [Contents]


3.1.3 Pipelines

Blocks can be run as a pipeline. The results of the parent block is inserted into the child’s #:code field, using the #:chain string as a marker for what to replace.

Pipelines are not limited to two elements.

run-blocks* is a wrapper around run-blocks that automatically inserts its arguments into a list.

(define-block ruby-print-python-code
  #:code     "puts \"print(74, end='')\""
  #:language ruby)

(define-block python-print
  #:code     "%ruby%"
  #:chain    "%ruby%"     ;text to replace in #:code
  #:language python)

(define-block ruby-add-1
  #:code     "print %python% + 1"
  #:chain    "%python%"   ;this can be anything
  #:language ruby)

(block-result (run-blocks*
               ruby-print-python-code
               python-print
               ruby-add-1)) ;=> "75"

If the child’s #:code field is not set, the #:result field is inserted directly into the #:code field.

(define-block guile-print-guile-code
  #:code ''(+ 1 1)  ;result => '(+ 1 1)
  #:language guile-direct)

(define-block guile-eval
  #:language guile-direct)

(block-result (run-blocks* guile-print-guile-code guile-eval)) ;=> 2

It is possible to run a nested list of blocks directly, without needing to call combine-blocks first.

(run-blocks `((,a ,b)
              ,c ,d))
;; is equivalent to
(run-blocks `(,(combine-blocks* a b)
              ,c ,d))

Directly running nested blocks is only supported one level deep.

(run-blocks `((,a ,b (,c ,d))
              ,d)) ;invalid
(run-blocks `((,a ,b ,(combine-blocks* c d))
              ,d)) ;valid

Explicit calls to combine-blocks would be required.