Fact
type (joe
)
An ad hoc type for Nero facts, consisting of a relation
name
and ordered or named fields. A Nero ruleset
produces
Fact
values by default, and also accepts Facts
as input.
Many Joe values can be converted to Facts
.
- fact.fieldMap() → Map
- fact.fields() → List
- fact.isOrdered() → Boolean
- fact.relation() → String
- fact.toString() → String
Fact Fields and Field Names
A Fact
's field values are accessible by the
fields()
method if the Fact
isOrdered()
, and as a map of field names and
values via the
fieldMap()
method.
In addition, a fact's fields can be access as normal Joe object fields:
// Simple ordered fact; field names are `f1` and `f2`.
var fact = Fact("Thing", #car, #red);
// Prints "This Thing is #red"
println("This " + fact.relation() + " is " + fact.f2);
// Simple unordered fact; field names are as given.
var fact2 = Fact.ofMap("Thing", {"id": #car, "color": #red});
// Prints "This Thing is #red"
println("This " + fact.relation() + " is " + fact.color);
Static Methods
Fact.of()
Fact.of(relation, fields)
Creates a new ordered Fact
given the relation and a list of
field values. Its fields will be named f0
, f1
, etc.
The Fact
will be an instance of the Java ListFact
class.
Fact.ofMap()
Fact.ofMap(relation, fieldMap)
Creates a new unordered Fact
given the relation and the field map.
Its fields will have the names given as keys in the map.
The Fact
will be an instance of the Java MapFact
class.
Fact.ofPairs()
Fact.ofPairs(relation, pairs)
Creates a new ordered Fact
given a flat list of field name/value
pairs. Its fields will have the names given in the list.
The Fact
will be an instance of the Java RecordFact
class.
Fact Initializer
Fact(relation, field, ...) → Fact
Creates a new Fact
given the relation and one or more the
field values. Its fields will be named f0
, f1
, etc.
The Fact
will be an instance of the Java ListFact
class.
Methods
fact.fieldMap()
fact.fieldMap() → Map
Returns a read-only map of the field values.
fact.fields()
fact.fields() → List
Returns a read-only list of the field values, if the fact
isOrdered()
.
fact.isOrdered()
fact.isOrdered() → Boolean
Returns true if the fact has ordered fields, and false otherwise.
fact.relation()
fact.relation() → String
Returns the Fact's relation name.
fact.toString()
fact.toString() → String
Returns the value's string representation.