Documentation Language: Swift

Structure

MTLQuery

Represents an MTL query - a side-effect-free operation returning a value.

struct MTLQuery

Overview

Queries provide reusable computation logic in MTL modules, extending AQL with custom operations that can be invoked from templates and other queries. Unlike templates, queries do not generate text output.

Overview

MTL queries serve multiple purposes:

Side-Effect Freedom

Queries must be side-effect-free, meaning they:

Example Usage

// Simple query
let fullNameQuery = MTLQuery(
    name: "fullName",
    parameters: [
        MTLVariable(name: "person", type: "Person")
    ],
    returnType: "String",
    body: MTLExpression(AQLBinaryExpression(
        left: AQLNavigationExpression(
            source: AQLVariableExpression(name: "person"),
            property: "firstName"
        ),
        right: AQLNavigationExpression(
            source: AQLVariableExpression(name: "person"),
            property: "lastName"
        ),
        op: .concat
    ))
)

// Type-checking query
let isPublicQuery = MTLQuery(
    name: "isPublic",
    parameters: [MTLVariable(name: "element", type: "Element")],
    returnType: "Boolean",
    body: MTLExpression(AQLNavigationExpression(
        source: AQLVariableExpression(name: "element"),
        property: "visibility"
    ))
)

Topics

Initializers

Instance Properties

V
body

The query body expression.

V
documentation

Optional documentation string.

V
name

The name of the query.

V
parameters

The parameters accepted by this query.

V
returnType

The return type of the query.

V
visibility

The visibility of this query.

Default Implementations

Relationships

Conforms To

See Also

Module Structure

S
MTLModule

Represents an MTL (Model-to-Text Language) module.

S
MTLTemplate

Represents an MTL template for text generation.