Feel.Runtime.Kind (feel v0.1.0)

Copy Markdown View Source

The kind of a value: which row of the semantic tables of DMN 1.6 (section 10.3.2.15) applies to it.

The tables speak of "kinds" and "datatypes": two operands must be of the same kind for = and <, and + is defined for some pairs of kinds only. The kind of a value is one of the atoms that Feel.Type uses for the primitive types, or :list, :context, :range, :function, or :null. A term that is not a FEEL value at all, such as a float or an atom, has the kind :unknown, so a host that binds one gets a type mismatch and not a crash.

A kind is looked up from the outermost shape of the value alone: the elements of a list are not examined.

Summary

Functions

Returns the name of a kind as FEEL writes it, for messages.

Returns the kind of a value.

Returns true for a string of FEEL: a binary that is valid UTF-8 (Feel.Value.String.value?/1).

Types

t()

@type t() ::
  :null
  | :boolean
  | :string
  | :number
  | :date
  | :time
  | :date_and_time
  | :years_and_months_duration
  | :days_and_time_duration
  | :range
  | :list
  | :context
  | :function
  | :unknown

Functions

name(kind)

@spec name(t()) :: String.t()

Returns the name of a kind as FEEL writes it, for messages.

iex> Feel.Runtime.Kind.name(:date_and_time)
"date and time"
iex> Feel.Runtime.Kind.name(:null)
"null"

of(value)

@spec of(term()) :: t()

Returns the kind of a value.

iex> Feel.Runtime.Kind.of(Decimal.new(1))
:number
iex> Feel.Runtime.Kind.of(nil)
:null
iex> Feel.Runtime.Kind.of(%{"a" => 1})
:context
iex> Feel.Runtime.Kind.of(1.5)
:unknown

string?(value)

@spec string?(term()) :: boolean()

Returns true for a string of FEEL: a binary that is valid UTF-8 (Feel.Value.String.value?/1).

of/1 calls any binary a string, since the operators take it as one, and a value that is bound to a name declared as a string has to be a valid one (Feel.Runtime.BindingTypes, D-138): this is that test, for the code that checks it itself (the BEAM backend's fast path, D-164).

iex> Feel.Runtime.Kind.string?("é")
true
iex> Feel.Runtime.Kind.string?(<<0xFF>>)
false
iex> Feel.Runtime.Kind.string?(1)
false