Let

Let( bindings, in )
Let( bindings, in )
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(varname) syntax.

Parameters

Argument 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 query below 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 statement with the associated variable’s name.

curl https://db.fauna.com/ \
    -u fnAChGwBcAACAO70ziE0cfROosNJHdgBmJU1PgpL: \
    -d '{ "let": { "x": 1, "y": 2 }, "in": { "var": "x" } }'
Value result = await client.Query(
  Let("x", 1, "y", 2).In(Var("x"))
);
System.out.println(
         client.query(
               Let( "x", Value(1), "y", Value(2) ).in( Var("x") )
         ).get() );
result, _ := client.Query(f.Let(f.Obj{"x": 1, "y": 2}, f.Var("x")))

fmt.Println(result)
Let(Seq("x" -> 1, "y" -> 2), Var("x"))
client.query(q.let({"x": 1, "y": 2}, q.var("x")))
$client.query do
  let(x: 1, y: 2) do
    x
  end
end
client.query(Let(bindings: [ x: 1, y: 2 ], in: Var("x")))
client.query(
  q.Let(
    { x: 1, y: 2 },
    q.Var('x')
  )
)
.then((ret) => console.log(ret))
HTTP/1.1 200 OK
{ "resource": 1 }
1
1
1
1
1
1
1
1

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve! documentation@fauna.com

Thank you for your feedback!