Expressions in the Alexa Conversations Description Language

In the Alexa Conversations Description Language (ACDL), an expression is a statically typed representation of an artifact or behavior in your dialog samples. Because ACDL isn't a general-purpose programming language, expressions don't represent the implementation of logic.

Expression examples

The following example shows a type declaration.

type WeatherPayload {
  String forecast
}

The following example shows an expression of an action declaration.

action String getWeather(String cityName)

The following example shows an expression of a dialog declaration.

dialog Nothing GetWeatherDialog() {
  sample {
    // An expression of an action call and a named expression.
    req = expect(Invoke, WeatherEvent)
    ...
  }
}

Expression blocks

An expression block, or block of expressions, is a set of one or more expressions within matching braces. An expression block defines a local naming scope.

blockExpression
    : LBRACE expression+ RBRACE
    ;

Expression blocks have the following characteristics:

  • Block type – Each block has a type. The type of the final expression in the block is the type of the entire block.
  • Nesting – An expression block can contain other expression blocks, creating a parent-child relationship.
  • Multiple blocks – An expression or a block can have multiple child block expressions. The type of each child block expression must match. The matching type is the type for the whole expression or whole block.
  • Non-empty – An expression block can't be empty; it must contain at least one expression.

You declare a dialog expression block as a set of sample blocks. You can only declare arbitrary expression blocks inside a sample block or a conditional expression.

Expression block examples

The following example shows an expression block.

action WeatherResult getWeather(US_CITY cityName, DATE date)

// Dialog block expression
dialog Nothing WeatherDialog() {

  // Sample block expression
  sample {
    weatherEvent = expect(Invoke, getWeatherEvent)
    weatherResult = getWeather(weatherEvent.cityName, weatherEvent.date)
  }
}

In the previous example, the type of the sample block is WeatherResult because the type of the last expression in the block is WeatherResult. Because the dialog's type is Nothing, there's no need for the type of the sample block to match with that of the dialog block.

action WeatherResult getWeather(US_CITY cityName, DATE date)

// Dialog block expression
dialog WeatherResult WeatherDialog() {

  // Sample block expression
  sample {
    weatherEvent = expect(Invoke, getWeatherEvent)
    weatherResult = getWeather(weatherEvent.cityName, weatherEvent.date)
  }

  sample {
    weatherEvent = expect(Invoke, getWeatherJustCityEvent)
    getWeather(weatherEvent.cityName)
  }
}

In the previous example, the dialog returns a WeatherResult. The two sample blocks match.

The following example shows the use of expression blocks in a conditional expression. The type of the if and else blocks match.

type Person {
  String firstName
}

dialog Person SomeDialog() {
  sample {
    ...

    if (someBooleanExpression) {
      ...

      Person { firstName = "Alice" }
    } else {
      ...

      Person { firstName = "Bob" }
    }
  }
}

In the previous example, the if and else expression blocks have the same type, Person, because Person is the last expression in the blocks. Because the if expression is the last expression in the sample, the type Person becomes the type of the sample block, which also matches with the type of dialog.