4.1. val: Bind Value

The val declaration binds variables to values. The declaration val P = G, followed by expression F, is a different way of writing the expression F <P< G. Thus, val shares all of the behavior of the pruning combinator.

4.1.1. Syntax

[21]DeclareVal::= val Pattern = Expression  

4.1.2. Examples

Binding variables to values
{- Bind x to true or false arbitrarily 
   Bind y to 2
-}

val x = true | false
val y = Rwait(200) >> 2 | Rwait(300) >> 3

"x is " + x + ", " +
"y is " + y

{-
OUTPUT:
"x is true, y is 2"
-}
{-
OUTPUT:
"x is false, y is 2"
-}
Timeout
include "search.inc"

{- Publish the result of a Google search.
   If it takes more than 5 seconds, time out.
-}

val result = Google("impatience") | Rwait(5000) >> "Search timed out."

result
Roll Die
{- Bind an arbitrary integer between 1 and 6, inclusive,
   to a variable in order to simulate a 6-sided die roll.
-}

val roll = (1 | 2 | 3 | 4 | 5 | 6)
"You rolled " + roll

{-
OUTPUT:
"You rolled 1"
-}
{-
OUTPUT:
"You rolled 2"
-}
{-
OUTPUT:
"You rolled 3"
-}
{-
OUTPUT:
"You rolled 4"
-}
{-
OUTPUT:
"You rolled 5"
-}
{-
OUTPUT:
"You rolled 6"
-}

4.1.3. Related Links