ExMaude. Term
(ExMaude v0.2.0)
View Source
Structured representation of a Maude term.
This module provides a rich type for representing Maude terms in Elixir, including their value, sort (type), and optionally the module they came from.
Structure
A term contains:
:value- The string representation of the term's value:sort- The Maude sort (type) of the term:module- The module the term belongs to (optional):raw- The raw output from Maude (for debugging)
Examples
# Parse a reduction result
{:ok, term} = ExMaude.Term.parse("result Nat: 42")
term.value #=> "42"
term.sort #=> "Nat"
# Create directly
term = %ExMaude.Term{value: "true", sort: "Bool"}
Summary
Functions
Creates a new Term struct.
Parses Maude output into a Term struct.
Checks if the term has a specific sort.
Attempts to convert the term value to an Elixir boolean.
Attempts to convert the term value to an Elixir float.
Attempts to convert the term value to an Elixir integer.
Returns the term value as a string (always succeeds).
Types
Functions
Creates a new Term struct.
Examples
term = ExMaude.Term.new("42", "Nat")
term.value #=> "42"
term.sort #=> "Nat"
Parses Maude output into a Term struct.
Examples
iex> ExMaude.Term.parse("result Nat: 6")
{:ok, %ExMaude.Term{value: "6", sort: "Nat", module: nil, raw: "result Nat: 6"}}
iex> ExMaude.Term.parse("result Bool: true")
{:ok, %ExMaude.Term{value: "true", sort: "Bool", module: nil, raw: "result Bool: true"}}
Checks if the term has a specific sort.
Examples
term = ExMaude.Term.new("42", "Nat")
ExMaude.Term.sort?(term, "Nat") #=> true
ExMaude.Term.sort?(term, "Bool") #=> false
Attempts to convert the term value to an Elixir boolean.
Only works for terms with Bool sort.
Examples
term = ExMaude.Term.new("true", "Bool")
ExMaude.Term.to_boolean(term) #=> {:ok, true}
Attempts to convert the term value to an Elixir float.
Only works for terms with Float sort.
Examples
term = ExMaude.Term.new("3.14", "Float")
ExMaude.Term.to_float(term) #=> {:ok, 3.14}
Attempts to convert the term value to an Elixir integer.
Only works for terms with numeric sorts (Nat, Int, NzNat, etc.).
Examples
term = ExMaude.Term.new("42", "Nat")
ExMaude.Term.to_integer(term) #=> {:ok, 42}
term = ExMaude.Term.new("true", "Bool")
ExMaude.Term.to_integer(term) #=> {:error, :not_numeric}
Returns the term value as a string (always succeeds).