Let

Let( bindings, in )
Let( bindings, in )
Let( bindings, in )
Let( bindings, in )
let( bindings, in )
Let( bindings, in )

Description

The Let function binds one or more variables to a single value or expression. When multiple variables are defined, the evaluation is from left to right. Variables which have previously been defined may be used to define future variables. Variables are lexically scoped to the expression passed via the in parameter. The value of a variable can be referenced with Var syntax.

Parameters

Parameter Type Definition and Requirements

bindings

List of pairs

The variable or variables to define.

in

Expression

The expression in which the variables are defined.

Returns

The evaluation of the in argument.

Examples

The following query defines two variables to be used by the expression defined by the in argument. The first variable "x" contains the value 1 and the second variable "y" contains the value 2. The expression defined by the in argument simply returns the value of the variable "x". The value is accessed by using the Var function with the associated variable’s name.

try
{
    Value result = await client.Query(
        Let("x", 1, "y", 2).In(Var("x"))
    );
    Console.WriteLine(result);
}
catch (Exception e)
{
    Console.WriteLine($"ERROR: {e.Message}");
}
LongV(1)
result, err := client.Query(
	f.Let().Bind(
		"x", 1).Bind(
		"y", 2).In(
		f.Var("x")))

if err != nil {
	fmt.Fprintln(os.Stderr, err)
} else {
	fmt.Println(result)
}
1
System.out.println(
    client.query(
        Let("x", Value(1), "y", Value(2)).in(Var("x"))
    ).get());
1
client.query(
  q.Let(
    { x: 1, y: 2 },
    q.Var('x')
  )
)
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
1
result = client.query(
  q.let({"x": 1, "y": 2}, q.var("x"))
)
print(result)
1
Let(
  { x: 1, y: 2 },
  Var('x')
)
1
Query metrics:
  •    bytesIn:  42

  •   bytesOut:  14

  • computeOps:   1

  •    readOps:   0

  •   writeOps:   0

  •  readBytes:   0

  • writeBytes:   0

  •  queryTime: 1ms

  •    retries:   0

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!