Previous: , Up: Defining a Process   [Contents][Index]

4.3 Useful procedures

The (gwl utils) module provides a number of useful helpers that are intended to simplify common tasks when defining processes. The helpers defined by this module are all available by default.

Scheme Procedure: on collection higher proc

The on procedure is an alternative way to express the application of a higher order function to some collection. The only purpose of this procedure is to improve legibility when using Wisp syntax, as it allows one to avoid leading dots. The following two expressions are equivalent:

;; With "on"
on numbers map
   lambda (number)
     + number 10

;; Without "on"
  lambda (number)
    + number 10
  . samples
Scheme Procedure: expand file-name-part

This procedure returns a list of file names by combining any number of file name parts given as arguments. A file name part can either be a string or a list of strings. This is very useful when you need to generate a list of input or output file names.

(expand "/home/"
        '("me" "you" "them")
        '("old" "new"))

=> '("/home/me/data/old"
Scheme Procedure: pick [n] key collection

This procedure allows you to pick a named item from a collection by looking for the specified keyword key. Optionally, you can provide a selector procedure or index n as the first argument. Without a selector the first item matching the given key will be returned. When the selector is * all items following the key (up to the next tag) will be returned. If the selector is a number it is used as a zero-based index into the list of items following the key. If the selector is a procedure it is applied to the list of items following the key.

define collection
    . "one"
    . "two"
    . "three"
    . mine: "four"
    . "five"
    . yours: "six"

pick mine: collection

; => "four"

pick * mine: collection

; => '("four" "five")

pick second mine: collection

; => "five"

pick 0 yours: collection

; => "six"
Scheme Syntax: load-workflow file

This macro lets you load a workflow from the given file. The file must evaluate to a workflow value. This macro is useful for when you want to extend previously defined workflows. The argument file is expected to be a file name relative to the file invoking load-workflow.

Previous: , Up: Defining a Process   [Contents][Index]