essenceDocumentation
essenceDocs
on this pageAt a glance
Coming from JavaScript?

Record

type

The methods every record has: equality, printing and reading its keys.

Taught on: Records.

At a glance

Declared
namespace Record for Record

Equality and printing

is

on Record

is(_ other: Record) -> Boolean

Answers whether the Record has the same members and values as another.

The order the members stand in does not matter. Each member the Record's Type declares is compared by that member's own Equatable conformance. So a value whose Namespace writes its own is compares the same way on its own and as a member. A member the static Type can not see is compared by the structural equality the language defines. The member sets have to match either way. A Dictionary keyed by Records finds a key by this same comparison.

A Record Type whose declared members are not all Equatable is not Equatable either, exactly as a List of such a Type is not.

NameTypeDescription
_Recordthe Record to compare against

true when the Records are equal.

Example
constant ada = { name = "Ada", born = 1815 }

expect ada::is({ born = 1815, name = "Ada" })
expect ada::is({ name = "Ada", born = 1816 })::negate()

toString

on Record

toString() -> String

Answers the Record and its members as a String.

Each member is written as name = value. Each member the Record's Type declares is written the way its own Printable conformance writes it. A Money member whose Namespace answers EUR 1999 is written that way. A Case member is written as its Case name. A member the static Type can not see is written structurally. A whole Rational member prints its numerator alone. A String member keeps its quotation marks. A Record too long for one line is written over several lines.

A Record Type whose declared members are not all Printable is not Printable either. Terminal.inspect renders any value and asks for no conformance. That is what to reach for then.

the String representation of the Record.

Example
constant ada = { name = "Ada", born = 1815 }

expect ada::toString()::is("\{ name = \"Ada\", born = 1815 \}")

isNot

on Record · provided by Equatable

isNot(_ other: Record) -> Boolean

Answers whether the values differ.

NameTypeDescription
_Recordthe value to compare with

true when the values differ.

Example
expect "Ada"::isNot("Grace")
expect 3::isNot(3)::negate()

Reading

keys

on Record

keys() -> List<String>

Answers the names of the Record's members.

The names are one third of a reflective trio. The other two, entries and values, answer a value of any Type, and there is no Type to write that with. So a Program can read the names and not what they name.

the member names, as a List of Strings.

Example
constant ada = { name = "Ada", born = 1815 }

expect ada::keys()::is(["name", "born"])
esc