NAME
Muldis::D::Core::Routines - Muldis D general purpose routines
VERSION
This document is Muldis::D::Core::Routines version 0.31.0.
PREFACE
This document is part of the Muldis D language specification, whose root document is Muldis::D; you should read that root document before you read this one, which provides subservient details. Moreover, you should read the Muldis::D::Core document before this current document, as that forms its own tree beneath a root document branch.
DESCRIPTION
This document contains one or more sections that were moved here from Muldis::D::Core so that that other document would not be too large.
SYSTEM-DEFINED GENERIC UNIVERSAL FUNCTIONS
These functions are applicable to values of any data type at all.
function sys.std.Core.Universal.is_identical result Bool params { topic(Universal), other(Universal) }
-
This function results in
Bool:true
iff its 2 arguments are exactly the same value, andBool:false
otherwise. This function's 2 parameters are mutually commutative. This function will warn if, in regards to the declared types of its arguments, none the following are true: 1. they are both subtypes of a common scalar root type; 2. they are both subtypes of a common non-incomplete tuple or relation type, that is they essentially have the same headings; 3. at least one type is a generic (eg-Universal
) or incomplete (eg-Array
) type, and it is a supertype of the other. function sys.std.Core.Universal.is_not_identical result Bool params { topic(Universal), other(Universal) }
-
This function is exactly the same as
sys.std.Core.Universal.is_identical
except that it results in the opposite boolean value when given the same arguments. function sys.std.Core.Universal.is_value_of_type result Bool params { topic(Universal), type(Cat.TypeRef) }
-
This function results in
Bool:true
iff the value of itstopic
argument is a member of the data type whose name is given in thetype
argument, andBool:false
otherwise. As trivial cases, this function always results inBool:true
if the named type isUniversal
, andBool:false
if it isEmpty
. This function will fail if the named type doesn't exist in the virtual machine. function sys.std.Core.Universal.treated result Universal params { topic(Universal), as(Cat.TypeRef) }
-
This function results in the value of its
topic
argument, but that the declared type of the result is the not-Empty
data type whose name is given in theas
argument. This function will fail if the named type doesn't exist in the virtual machine, or iftopic
isn't a member of the named type. The purpose oftreated
is to permit taking values from a context having a more generic declared type, and using them in a context having a more specific declared type; such an action would otherwise be blocked at compile time due to a type-mismatch error;treated
causes the type-mismatch validation, and possible failure, to happen at runtime instead, on the actual value rather than declared value. For example, if you are storing anInt
value in aScalar
-typed variable, usingtreated
will cause the compiler to let you use that variable as an argument tosys.std.Integer.difference
, which it otherwise wouldn't. function sys.std.Core.Universal.default result Universal params { of(Cat.TypeRef) }
-
This function is the externalization of a not-
Empty
data type'stype_default
function. This function results in the default value of the not-Empty
data type whose name is given in theof
argument, and the declared type of the result is that same type. This function will fail if the named type doesn't exist in the virtual machine, either at compile or runtime depending whether the type is in the system or user namespace. This function is conceptually implicitly used to provide default values for variables, so they always hold valid values of their declared type. function sys.std.Core.Universal.assertion result Universal params { is_true(Bool), result(Universal) }
-
This function results in the value of its
result
argument, when itsis_true
argument isBool:true
. This function will fail if itsis_true
argument isBool:false
. The purpose ofassertion
is to perform condition assertions in a pure functional context that may be better done without the overhead of creating a new constrained data type, especially when the assertion is on some fact that is only known after performing calculations from multiple function arguments; this can potentially be done at compile time as per type constraints.
SYSTEM-DEFINED GENERIC SCALAR-CONCERNING FUNCTIONS
These functions are applicable to mainly scalar types, but are generic in that they typically work with any scalar types. Now some of these functions (those with a parameter named possrep
) work only with scalar values that have possreps, and not with values of the 6 system-defined scalar types lacking any possreps: Bool
, Int
, Blob
, Text
, Cat.Name
, Cat.Comment
; other functions are not limited in that way, but may be limited in other ways. Note that the terminology used to describe these functions is taking advantage of the fact that a scalar possrep looks just like a tuple. Each possrep
parameter is optional and defaults to the empty string if no explicit argument is given to it.
function sys.std.Core.Scalar.attr result ScaTupRel params { topic(Scalar), possrep(Cat.Name)?, name(Cat.Name) }
-
This function results in the scalar or nonscalar value of the possrep attribute of
topic
where the possrep name is given bypossrep
and the attribute name is given byname
. This function will fail ifpossrep
specifies a possrep name thattopic
doesn't have orname
specifies an attribute name that the named possrep oftopic
doesn't have. function sys.std.Core.Scalar.update_attr result Scalar params { topic(Scalar), possrep(Cat.Name)?, name(Cat.Name), value(ScaTupRel) }
-
This function results in its
topic
argument but that its possrep attribute whose possrep name ispossrep
and whose attribute name isname
has been updated with a new scalar or nonscalar value given byvalue
. This function will fail ifpossrep
specifies a possrep name thattopic
doesn't have orname
specifies an attribute name that the named possrep oftopic
doesn't have, or ifvalue
isn't of the declared type of the attribute; this function will otherwise warn if the declared type ofvalue
isn't a subtype of the declared type of the attribute. function sys.std.Core.Scalar.multi_update result Scalar params { topic(Scalar), possrep(Cat.Name)?, attrs(Tuple) }
-
This function is like
sys.std.Core.Scalar.update_attr
except that it handles N scalar possrep attributes at once rather than just 1. The heading of theattrs
argument must be a subset of the heading of thetopic
argument's possrep named bypossrep
; this function's result istopic
with all the possrep attribute values ofattrs
substituted into it. This function could alternately be named sys.std.Core.Scalar.static_substitution. function sys.std.Core.Scalar.projection result Tuple params { topic(Scalar), possrep(Cat.Name)?, attrs(set_of.Cat.Name) }
-
This function results in the
Tuple
that is the projection of the possrep (whose name is given in thepossrep
argument) of itstopic
argument that has just the subset of attributes oftopic
which are named in itsattrs
argument. As a trivial case, this function's result is the entire named possrep oftopic
ifattrs
lists all attributes of that possrep; or, it is the nullary tuple ifattrs
is empty. This function will fail ifpossrep
specifies a possrep name thattopic
doesn't have orattrs
specifies any attribute names thattopic
doesn't have. function sys.std.Core.Scalar.cmpl_projection result Tuple params { topic(Scalar), possrep(Cat.Name)?, attrs(set_of.Cat.Name) }
-
This function is the same as
projection
but that it results in the complementary subset of possrep attributes oftopic
when given the same arguments. function sys.std.Core.Scalar.Tuple_from_Scalar result Tuple params { topic(Scalar), possrep(Cat.Name)? }
-
This function results in the
Tuple
that has all the same attributes of the possrep oftopic
whose name is given inpossrep
; in other words, the function results in the externalization of one of a scalar value's possreps. This function will fail ifpossrep
specifies a possrep name thattopic
doesn't have. function sys.std.Core.Scalar.Scalar_from_Tuple result Scalar params { topic(Tuple), type(Cat.TypeRef), possrep(Cat.Name)? }
-
This function results in the
Scalar
value whose scalar root (|sub)type is named bytype
, which has a possrep whose name matchespossrep
, and whose complete set of attributes of that named possrep match the attributes oftopic
. This function can be used to select any scalar value at all that has a possrep. function sys.std.Core.Scalar.order result Cat.Order params { topic(Scalar), other(Scalar), assuming(QuasiTuple)? }
-
This function is the externalization of a scalar root type's type-default (total)
order_determination
function. This function results inCat.Order:same
iff itstopic
andother
arguments are exactly the same value, and otherwise it results inCat.Order:increase
if the value of theother
argument is considered to be an increase (as defined by the type) over the value of thetopic
argument, and otherwise it results inCat.Order:decrease
as the reverse of the last condition would be true. This function will fail if itstopic
andother
arguments are not values of a common scalar root type that declares a type-defaultorder_determination
function; this function will otherwise warn if the declared types of those arguments are not both subtypes of such a common scalar root type. Note thatorder_determination
functions are considered the only fundamental order-sensitive operators, and all others are defined over them. This function also has aTuple
-typed third parameter, namedassuming
, which carries optional customization details for the order-determination algorithm; this permits the function to implement a choice between multiple (typically similar) ordering algorithms rather than just one, which reduces the number of functions needed for supporting that choice; if the algorithm is not customizable, then a tuple argument would be of degree zero. Theassuming
parameter is optional and defaults to the zero-attribute tuple if no explicit argument is given to it.
SYSTEM-DEFINED BOOLEAN-CONCERNING FUNCTIONS
These functions implement commonly used boolean operations.
function sys.std.Core.Bool.not result Bool params { topic(Bool) }
-
This function results in the logical not of its argument.
function sys.std.Core.Bool.and result Bool params { topic(set_of.Bool) }
-
This function is a reduction operator that recursively takes each pair of its N input element values and does a logical and (which is both commutative and associative) on them until just one is left, which is the function's result. If
topic
has zero values, thenand
results inBool:true
, which is the identity value for logical and. function sys.std.Core.Bool.or result Bool params { topic(set_of.Bool) }
-
This function is a reduction operator that recursively takes each pair of its N input element values and does a logical inclusive-or (which is both commutative and associative) on them until just one is left, which is the function's result. If
topic
has zero values, thenor
results inBool:false
, which is the identity value for logical inclusive-or. function sys.std.Core.Bool.xor result Bool params { topic(bag_of.Bool) }
-
This function is a reduction operator that recursively takes each pair of its N input element values and does a logical exclusive-or (which is both commutative and associative) on them until just one is left, which is the function's result. If
topic
has zero values, thenxor
results inBool:false
, which is the identity value for logical exclusive-or.
SYSTEM-DEFINED GENERIC TUPLE-CONCERNING FUNCTIONS
These functions are applicable to mainly tuple types, but are generic in that they typically work with any tuple types.
function sys.std.Core.Tuple.attr result ScaTupRel params { topic(Tuple), name(Cat.Name) }
-
This function results in the scalar or nonscalar value of the attribute of
topic
whose name is given byname
. This function will fail ifname
specifies an attribute name thattopic
doesn't have. function sys.std.Core.Tuple.update_attr result Tuple params { topic(Tuple), name(Cat.Name), value(ScaTupRel) }
-
This function results in its
topic
argument but that its attribute whose name isname
has been updated with a new scalar or nonscalar value given byvalue
. This function will fail ifname
specifies an attribute name thattopic
doesn't have; this function will otherwise warn if the declared type ofvalue
isn't a subtype of the declared type of the attribute. function sys.std.Core.Tuple.multi_update result Tuple params { topic(Tuple), attrs(Tuple) }
-
This function is like
sys.std.Core.Tuple.update_attr
except that it handles N tuple attributes at once rather than just 1. The heading of theattrs
argument must be a subset of the heading of thetopic
argument; this function's result istopic
with all the attribute values ofattrs
substituted into it. This function could alternately be named sys.std.Core.Tuple.static_substitution. function sys.std.Core.Tuple.rename result Tuple params { topic(Tuple), map(Cat.AttrRenameMap) }
-
This function results in a
Tuple
value that is the same as itstopic
argument but that some of its attributes have different names. Each tuple of the argumentmap
specifies how to rename onetopic
attribute, with thebefore
andafter
attributes of amap
tuple representing the old and new names of atopic
attribute, respectively. As a trivial case, this function's result istopic
ifmap
has no tuples. This function supports renaming attributes to each others' names. This function will fail ifmap
specifies any old names thattopic
doesn't have, or any new names that are the same astopic
attributes that aren't being renamed. function sys.std.Core.Tuple.projection result Tuple params { topic(Tuple), attrs(set_of.Cat.Name) }
-
This function results in the projection of its
topic
argument that has just the subset of attributes oftopic
which are named in itsattrs
argument. As a trivial case, this function's result istopic
ifattrs
lists all attributes oftopic
; or, it is the nullary tuple ifattrs
is empty. This function will fail ifattrs
specifies any attribute names thattopic
doesn't have. function sys.std.Core.Tuple.cmpl_projection result Tuple params { topic(Tuple), attrs(set_of.Cat.Name) }
-
This function is the same as
projection
but that it results in the complementary subset of attributes oftopic
when given the same arguments. function sys.std.Core.Tuple.wrap result Tuple params { topic(Tuple), inner(set_of.Cat.Name), outer(Cat.Name) }
-
This function results in a
Tuple
value that is the same as itstopic
argument but that some of its attributes have been wrapped up into a newTuple
-typed attribute, which exists in place of the original attributes. Theinner
argument specifies whichtopic
attributes are to be removed and wrapped up, and theouter
argument specifies the name of their replacement attribute. As a trivial case, ifinner
is empty, then the result has all the same attributes as before plus a new tuple-typed attribute of degree zero; or, ifinner
lists all attributes oftopic
, then the result has a single attribute whose value is the same astopic
. This function supports the new attribute having the same name as an old one being wrapped into it. This function will fail ifinner
specifies any attribute names thattopic
doesn't have, or ifouter
is the same astopic
attributes that aren't being wrapped. function sys.std.Core.Tuple.cmpl_wrap result Tuple params { topic(Tuple), cmpl_inner(set_of.Cat.Name), outer(Cat.Name) }
-
This function is the same as
wrap
but that it wraps the complementary subset of attributes oftopic
to those specified bycmpl_inner
. function sys.std.Core.Tuple.unwrap result Tuple params { topic(Tuple), outer(Cat.Name) }
-
This function is the inverse of
sys.std.Core.Tuple.wrap
, such that it will unwrap aTuple
-type attribute into its member attributes. This function will fail ifouter
specifies any attribute name thattopic
doesn't have, or if an attribute oftopic{outer}
is the same as anothertopic
attribute. function sys.std.Core.Tuple.product result Tuple params { topic(quasi_set_of.Tuple) }
-
This function is similar to
sys.std.Core.Relation.product
but that it works with tuples rather than relations. This function is mainly intended for use in connecting tuples that have all disjoint headings, such as for extending one tuple with additional attributes.
SYSTEM-DEFINED GENERIC SINGLE INPUT RELATION FUNCTIONS
These functions are applicable to mainly relation types, but are generic in that they typically work with any relation types. Each \w*assuming
parameter is optional and defaults to the zero-attribute tuple if no explicit argument is given to it.
function sys.std.Core.Relation.cardinality result UInt params { topic(Relation) }
-
This function results in the cardinality of its argument (that is, the count of tuples its body has).
function sys.std.Core.Relation.is_member result Bool params { r(Relation), t(Tuple) }
-
This function results in
Bool:true
iff itst
argument matches a tuple of itsr
argument (that is, iff conceptuallyt
is a member ofr
), andBool:false
otherwise. This function is likesys.std.Core.Relation.is_subset
except that the tuple being looked for doesn't have to be wrapped in a relation. This function will fail|warn if its 2 arguments are incompatible as peris_subset
. function sys.std.Core.Relation.is_not_member result Bool params { r(Relation), t(Tuple) }
-
This function is exactly the same as
sys.std.Core.Relation.is_member
except that it results in the opposite boolean value when given the same arguments. function sys.std.Core.Relation.Tuple_from_Relation result Tuple params { topic(Relation) }
-
This function results in the
Tuple
that is the sole member tuple of its argument. This function will fail if its argument does not have exactly one tuple. function sys.std.Core.Relation.Relation_from_Tuple result Relation params { topic(Tuple) }
-
This function results in the
Relation
value those body has just the oneTuple
that is its argument. function sys.std.Core.Relation.insertion result Relation params { r(Relation), t(Tuple) }
-
This function results in a
Relation
that is the relational union ofr
and a relation whose sole tuple ist
; that is, conceptually the result ist
inserted intor
. As a trivial case, ift
already exists inr
, then the result is justr
. function sys.std.Core.Relation.disjoint_insertion result Relation params { r(Relation), t(Tuple) }
-
This function is exactly the same as
sys.std.Core.Relation.insertion
except that it will fail ift
already exists inr
. function sys.std.Core.Relation.deletion result Relation params { r(Relation), t(Tuple) }
-
This function results in a
Relation
that is the relational difference fromr
of a relation whose sole tuple ist
; that is, conceptually the result ist
deleted fromr
. As a trivial case, ift
already doesn't exist inr
, then the result is justr
. function sys.std.Core.Relation.rename result Relation params { topic(Relation), map(Cat.AttrRenameMap) }
-
This function is the same as
sys.std.Core.Tuple.rename
but that it operates on and results in aRelation
rather than aTuple
. function sys.std.Core.Relation.projection result Relation params { topic(Relation), attrs(set_of.Cat.Name) }
-
This function is the same as
sys.std.Core.Tuple.projection
but that it operates on and results in aRelation
rather than aTuple
. But note that the result relation will have fewer tuples thantopic
if anytopic
tuples were non-distinct for just the projected attributes. function sys.std.Core.Relation.cmpl_projection result Relation params { topic(Relation), attrs(set_of.Cat.Name) }
-
This function is the same as
sys.std.Core.Tuple.cmpl_projection
but that it operates on and results in aRelation
rather than aTuple
. function sys.std.Core.Relation.wrap result Relation params { topic(Relation), inner(set_of.Cat.Name), outer(Cat.Name) }
-
This function is the same as
sys.std.Core.Tuple.wrap
but that it operates on and results in aRelation
rather than aTuple
, where each of its member tuples was transformed as persys.std.Core.Tuple.wrap
. function sys.std.Core.Relation.cmpl_wrap result Relation params { topic(Relation), cmpl_inner(set_of.Cat.Name), outer(Cat.Name) }
-
This function is the same as
sys.std.Core.Tuple.cmpl_wrap
but that it operates on and results in aRelation
rather than aTuple
, where each of its member tuples was transformed as persys.std.Core.Tuple.cmpl_wrap
. function sys.std.Core.Relation.unwrap result Relation params { topic(Relation), outer(Cat.Name), inner(set_of.Cat.Name) }
-
This function is the inverse of
sys.std.Core.Relation.wrap
assys.std.Core.Tuple.unwrap
is tosys.std.Core.Tuple.wrap
. But unlike theTuple
variant ofunwrap
, this current function requires the extrainner
argument to prevent ambiguity in the general case wheretopic
might have zero tuples, because in that situation the most-specific-type oftopic{outer}
would beEmpty
, and the names of the attributes to add totopic
in place oftopic{outer}
are not known. This function will fail iftopic
has at least 1 tuple andinner
does not match the names of the attributes oftopic{outer}
. function sys.std.Core.Relation.group result Relation params { topic(Relation), inner(set_of.Cat.Name), outer(Cat.Name) }
-
This function is similar to
sys.std.Core.Relation.wrap
but that thetopic
attribute-wrapping transformations result in newRelation
-typed attributes rather than newTuple
-typed attributes, and moreover multipletopic
tuples may be combined into fewer tuples whose newRelation
-typed attributes have multiple tuples. This function takes a relation of N tuples and divides the tuples into M groups where all the tuples in a group have the same values in the attributes which aren't being grouped (and distinct values in the attributes that are being grouped); it then results in a new relation of M tuples where the new relation-valued attribute of the result has the tuples of the M groups. A grouped relation contains all of the information in the original relation, but it has less redundancy due to redundant non-grouped attributes now just being represented in one tuple per the multiple tuples whose grouped attributes had them in common. A relation having relation-valued attributes like this is a common way to group so-called child tuples under their parents. As a trivial case, ifinner
is empty, then the result has all the same tuples and attributes as before plus a new relation-typed attribute of degree zero whose value per tuple is of cardinality one; or, ifinner
lists all attributes oftopic
, then the result has a single tuple of a single attribute whose value is the same astopic
. This function supports the new attribute having the same name as an old one being grouped into it. This function will fail ifinner
specifies any attribute names thattopic
doesn't have, or ifouter
is the same astopic
attributes that aren't being grouped. function sys.std.Core.Relation.cmpl_group result Relation params { topic(Relation), group_per(set_of.Cat.Name), outer(Cat.Name) }
-
This function is the same as
group
but that it groups the complementary subset of attributes oftopic
to those specified bygroup_per
. function sys.std.Core.Relation.ungroup result Relation params { topic(Relation), outer(Cat.Name), inner(set_of.Cat.Name) }
-
This function is the inverse of
sys.std.Core.Relation.group
assys.std.Core.Relation.unwrap
is tosys.std.Core.Relation.wrap
; it will ungroup aRelation
-type attribute into its member attributes and tuples. A relation can be first grouped and then that result ungrouped to produce the original relation, with no data loss. However, the ungroup of a relation on a relation-valued attribute will lose the information in any outer relation tuples whose inner relation value has zero tuples; a group on this result won't bring them back. This function will fail ifouter
specifies any attribute name thattopic
doesn't have, or if an attribute oftopic{outer}
is the same as anothertopic
attribute. function sys.std.Core.Relation.restriction result Relation params { topic(Relation), func(Cat.FuncRef), assuming(QuasiTuple)? }
-
This function results in the relational restriction of its
topic
argument as determined by applying theBool
-resulting function named in itsfunc
argument when the latter function is curried by itsassuming
argument. The result relation has the same heading astopic
, and its body contains the subset oftopic
tuples where, for each tuple, the function named byfunc
results inBool:true
when passed the tuple as itstopic
argument andassuming
as itsassuming
argument. As a trivial case, iffunc
is defined to unconditionally result inBool:true
, then this function results simply intopic
; or, for an unconditionalBool:false
, this function results in the empty relation with the same heading. Note that this operation is also legitimately known as where. See also thesys.std.Core.Relation.semijoin
function, which is a simpler-syntax alternative forsys.std.Core.Relation.restriction
in its typical usage where restrictions are composed simply of anded or ored tests for attribute value equality. function sys.std.Core.Relation.cmpl_restriction result Relation params { topic(Relation), func(Cat.FuncRef), assuming(QuasiTuple)? }
-
This function is the same as
restriction
but that it results in the complementary subset of tuples oftopic
when given the same arguments. See also thesys.std.Core.Relation.semidifference
function. function sys.std.Core.Relation.extension result Relation params { topic(Relation), func(Cat.FuncRef), assuming(QuasiTuple)? }
-
This function results in the relational extension of its
topic
argument as determined by applying theTuple
-resulting function named in itsfunc
argument when the latter function is curried by itsassuming
argument. The result relation has a heading that is a superset of that oftopic
, and its body contains the same number of tuples, with all attribute values oftopic
retained, and possibly extra present, determined as follows; for eachtopic
tuple, the function named byfunc
results in a second tuple when passed the first tuple as itstopic
argument andassuming
as itsassuming
argument; the first and second tuples must have no attribute names in common, and the result tuple is derived by joining (cross-product) the tuples together. As a trivial case, iffunc
is defined to unconditionally result in the degree-zero tuple, then this function results simply intopic
. function sys.std.Core.Relation.static_extension result Relation params { topic(Relation), attrs(Tuple) }
-
This function is a simpler-syntax alternative to both
sys.std.Core.Relation.extension
andsys.std.Core.Relation.product
in the typical scenario of extending a relation, given in thetopic
argument, such that every tuple has mutually identical values for each of the new attributes; the new attribute names and common values are given in theattrs
argument. function sys.std.Core.Relation.summary result Relation params { topic(Relation), group_per(set_of.Cat.Name), summ_func(Cat.FuncRef), summ_assuming(QuasiTuple)? }
-
This function provides a convenient context for using aggregate functions to derive a per-group summary relation, which is its result, from another relation, which is its
topic
argument. This function first performs acmpl_group
ontopic
usinggroup_per
to specify which attributes get grouped into a new relation-valued attribute and which don't; those that don't instead get wrapped into a tuple-valued attribute. Then, per tuple in the main relation, this function applies theTuple
-resulting function named in itssumm_func
argument when the latter function is curried by itssumm_assuming
argument (passed to it as justassuming
); the curried function has, rather than the typical 1topic
varying parameter, 2 varying parameters namedsummarize
andper
, which are valued with the relation-valued attribute and tuple-valued attribute, respectively. As per a function thatmap
applies, the function named bysumm_func
effectively takes a whole post-grouping input tuple and results in a whole tuple; the applied function would directly invoke any N-ary / aggregate operators, and extract their inputs from (or calculate)summarize
as it sees fit. Note thatsummary
is not intended to be used to summarize an entiretopic
relation at once (except by chance of it resolving to 1 group); you should instead invoke your summarize-allfunc
directly, or inline it, rather than by way ofsummary
, especially if you want a single-tuple result on an emptytopic
(whichsummary
) won't do.
SYSTEM-DEFINED GENERIC MULTIPLE INPUT RELATION FUNCTIONS
These functions are applicable to mainly relation types, but are generic in that they typically work with any relation types.
function sys.std.Core.Relation.is_subset result Bool params { look_in(Relation), look_for(Relation) }
-
This function results in
Bool:true
iff the set of tuples comprisinglook_for
is a subset of the set of tuples comprisinglook_in
, andBool:false
otherwise. This function will fail if the 2 arguments have attributes with common names but their most specific types would be fatally incompatible in a common relation value; this function will otherwise warn with common-named attributes where their declared types are incompatible as peris_identical
. function sys.std.Core.Relation.is_not_subset result Bool params { look_in(Relation), look_for(Relation) }
-
This function is exactly the same as
sys.std.Core.Relation.is_subset
except that it results in the opposite boolean value when given the same arguments. function sys.std.Core.Relation.union result Relation params { topic(set_of.Relation) }
-
This function results in the relational union/inclusive-or of the N element values of its argument; it is a reduction operator that recursively takes each pair of input values and relationally unions (which is both commutative and associative) them together until just one is left, which is the result. The result relation has the same heading as all of its inputs, and its body contains every tuple that is in any of the input relations. If
topic
has zero values, then this function will fail. Note that, conceptuallyunion
does have an identity value which could be this function's result whentopic
has zero values, which is the empty relation with the same heading, which is the per-distinct-heading identity value for relational union; however, since atopic
with zero values wouldn't know the heading / attribute names for the result relation in question, it seems the best alternative is to require invoking code to work around the limitation somehow, which might mean it will supply the identity value explicitly as an extratopic
element. function sys.std.Core.Relation.disjoint_union result Relation params { topic(set_of.Relation) }
-
This function is exactly the same as
sys.std.Core.Relation.union
except that it will fail if any 2 input values have a tuple in common. function sys.std.Core.Relation.intersection result Relation params { topic(set_of.Relation) }
-
This function results in the relational intersection/and of the N element values of its argument; it is a reduction operator that recursively takes each pair of input values and relationally intersects (which is both commutative and associative) them together until just one is left, which is the result. The result relation has the same heading as all of its inputs, and its body contains only the tuples that are in every one of the input relations. If
topic
has zero values, then this function will fail. Note that, conceptuallyintersection
does have an identity value which could be this function's result whentopic
has zero values, which is the universal relation with the same heading (that is, the relation having all the tuples that could ever exist in a relation with that heading), which is the per-distinct-heading identity value for relational intersection; however, since atopic
with zero values wouldn't know the heading / attribute names for the result relation in question (and even if they were, more information on attribute types would be needed to produce said universal relation, and even then it might be infinite or impossibly large), it seems the best alternative is to require invoking code to work around the limitation somehow, which might mean it will supply the identity value explicitly as an extratopic
element. Note that this intersection operator is conceptually a special case ofjoin
, applicable when the headings of the inputs are the same, and the other will produce the same result as this when given the same inputs, but with the exception that intersection has a different identity value when given zero inputs. function sys.std.Core.Relation.difference result Relation params { source(Relation), filter(Relation) }
-
This function results in the relational difference when its
filter
argument is subtracted from itssource
argument. The result relation has the same heading as both of its arguments, and its body contains only the tuples that are insource
and are not infilter
. This function will fail|warn if its 2 arguments are incompatible as peris_subset
. Note that this difference operator is conceptually a special case of semidifference, applicable when the headings of the inputs are the same. function sys.std.Core.Relation.semidifference result Relation params { source(Relation), filter(Relation) }
-
This function is the same as
semijoin
but that it results in the complementary subset of tuples ofsource
when given the same arguments. Note that this operation is also legitimately known as antijoin or anti-semijoin. function sys.std.Core.Relation.semijoin result Relation params { source(Relation), filter(Relation) }
-
This function results in the relational semijoin of its
source
andfilter
arguments. The result relation has the same heading assource
, and its body contains the subset ofsource
tuples that match those offilter
as perjoin
. Note that relational semijoin is conceptually a short-hand for first doing an ordinary relational join between its 2 arguments, and then performing a relational projection on all of the attributes that justsource
has. This function will fail|warn any time thatjoin
would fail|warn on the same 2 input relations. function sys.std.Core.Relation.join result Relation params { topic(quasi_set_of.Relation) }
-
This function results in the relational join of the N element values of its argument; it is a reduction operator that recursively takes each pair of input values and relationally joins (which is both commutative and associative) them together until just one is left, which is the result. The result relation has a heading that is a union of all of the headings of its inputs, and its body is the result of first pairwise-matching every tuple of each input relation with every tuple of each other input relation, then where each member of a tuple pair has attribute names in common, eliminating pairs where the values of those attributes differ and unioning the remaining said tuple pairs, then eliminating any result tuples that duplicate others. If
topic
has zero values, thenjoin
results in the nullary relation with one tuple, which is the identity value for relational join. As a trivial case, if any input relation has zero tuples, then the function's result will too; or, if any input is the nullary relation with one tuple, that input can be ignored (see identity value); or, if any 2 inputs have no attribute names in common, then the join of just those 2 is a cartesian product; or, if any 2 inputs have all attribute names in common, then the join of just those 2 is an intersection; or, if for 2 inputs, one's set of attribute names is a proper subset of another's, then the join of just those to is a semijoin with the former filtering the latter. This function will fail if any input relations have attributes with common names but their most specific types would be fatally incompatible in a common relation value; this function will otherwise warn with common-named attributes where their declared types are incompatible as peris_identical
. Note that this operation is also legitimately known as natural inner join. function sys.std.Core.Relation.product result Relation params { topic(quasi_set_of.Relation) }
-
This function results in the relational cartesian/cross product of the N element values of its argument; it is conceptually a special case of
join
where all input relations have mutually distinct attribute names; unlikejoin
,product
will fail if any inputs have attribute names in common. Note that this operation is also legitimately known as cartesian/cross join. function sys.std.Core.Relation.quotient result Relation params { dividend(Relation), divisor(Relation) }
-
This function results in the quotient when its
dividend
argument is divided by itsdivisor
argument using relational division. Speaking informally, say the relationsdividend
anddivisor
are calledA
andB
, and their attribute sets are respectively named{X,Y}
and{Y}
, then the result relation has a heading composed of attributes{X}
(so the result anddivisor
headings are both complementary subsets of thedividend
heading); the result has all tuples{X}
such that a tuple{X,Y}
appears inA
for all tuples{Y}
appearing inB
; that is,A / B
is shorthand forA{X} - ((A{X} join B) - A){X}
.
SYSTEM-DEFINED GENERIC CONTROL FLOW FUNCTIONS
function sys.std.Core.Control.func_invo result Universal params { function(Cat.FuncRef), args(QuasiTuple)? }
-
This function results in the result of invoking the other function named in its
function
argument when the latter function is curried by itsargs
argument; each attribute name ofargs
is mapped to a parameter name of the invoked function, and the corresponding attribute value is the corresponding argument for the function invocation. This function will fail if the invoked function has any non-optional parameters such that there aren't any corresponding attributes inargs
, or if there are any attributes inargs
that don't have corresponding parameters, or if any attribute values aren't of the declared types of the corresponding parameters. The purpose offunc_invo
is to support invocation of any function whose name or parameters potentially aren't known until runtime; it forms the foundation of all other system-defined functions that want to invoke a function whose name they take as an argument. Theargs
parameter is optional and defaults to the zero-attribute quasi-tuple if no explicit argument is given to it.
SYSTEM-DEFINED GENERIC UNIVERSAL UPDATERS
These update operators are applicable to values of any data type at all.
updater sys.std.Core.Universal.assign update { target(Universal) } read { v(Universal) }
-
This update operator will update the variable supplied as its
target
argument so that it holds the value supplied as itsv
argument. This updater will fail ifv
isn't of the declared type of the variable behindtarget
; this function will otherwise warn if the declared type ofv
isn't a subtype of the declared type of the variable behindtarget
.
SYSTEM-DEFINED GENERIC TUPLE VARIABLE UPDATERS
Updaters That Rename Attributes
updater sys.std.Core.Tuple.assign_rename update { topic(Tuple) } read { map(Cat.AttrRenameMap) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Tuple.rename
function with the same arguments, and then assigning the result of that function totopic
. This procedure is analagous to the data-manipulation phase of a SQL RENAME TABLE|VIEW or ALTER TABLE|VIEW RENAME TO statement ifftopic
isDatabase
-typed; each tuple ofmap
corresponds to a renamed SQL table.
Updaters That Add Attributes
updater sys.std.Core.Tuple.assign_product update { topic(Tuple) } read { other(Tuple) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Tuple.product
function such that it has 2 input tuples fromassign_product
's 2 arguments, and then assigning the result of that function totopic
. This procedure is analagous to the data-manipulation phase of a SQL CREATE TABLE|VIEW statement iff both arguments areDatabase
-typed; each relation-typed attribute ofother
corresponds to a created SQL table.
Updaters That Remove Attributes
updater sys.std.Core.Tuple.assign_projection update { topic(Tuple) } read { attrs(set_of.Cat.Name) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Tuple.projection
function with the same arguments, and then assigning the result of that function totopic
. updater sys.std.Core.Tuple.assign_cmpl_projection update { topic(Tuple) } read { attrs(set_of.Cat.Name) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Tuple.cmpl_projection
function with the same arguments, and then assigning the result of that function totopic
. This procedure is analagous to the data-manipulation phase of a SQL DROP TABLE|VIEW statement ifftopic
isDatabase
-typed; each relation-typed attribute named byattrs
corresponds to a dropped SQL table.
SYSTEM-DEFINED GENERIC RELATION VARIABLE UPDATERS
Updaters That Add Tuples
updater sys.std.Core.Relation.assign_insertion update { r(Relation) } read { t(Tuple) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.insertion
function with the same arguments, and then assigning the result of that function tor
. This updater is analagous to the general case of the single-row SQL "INSERT" statement. updater sys.std.Core.Relation.assign_disjoint_insertion update { r(Relation) } read { t(Tuple) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.disjoint_insertion
function with the same arguments, and then assigning the result of that function tor
. updater sys.std.Core.Relation.assign_union update { topic(Relation) } read { other(Relation) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.union
function such that it has 2 input relations fromassign_union
's 2 arguments, and then assigning the result of that function totopic
. This updater is analagous to the general case of the multiple-row SQL "INSERT" statement. updater sys.std.Core.Relation.assign_disjoint_union update { topic(Relation) } read { other(Relation) }
-
This update operator is to
sys.std.Core.Relation.disjoint_union
what the functionsys.std.Core.Relation.assign_union
is tosys.std.Core.Relation.union
.
Updaters That Remove Tuples
updater sys.std.Core.Relation.assign_deletion update { r(Relation) } read { t(Tuple) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.deletion
function with the same arguments, and then assigning the result of that function tor
. updater sys.std.Core.Relation.assign_restriction update { topic(Relation) } read { func(Cat.FuncRef), assuming(QuasiTuple)? }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.restriction
function with the same arguments, and then assigning the result of that function totopic
. updater sys.std.Core.Relation.assign_cmpl_restriction update { topic(Relation) } read { func(Cat.FuncRef), assuming(QuasiTuple)? }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.cmpl_restriction
function with the same arguments, and then assigning the result of that function totopic
. This updater is analagous to the general case of the SQL "DELETE" statement. updater sys.std.Core.Relation.assign_intersection update { topic(Relation) } read { other(Relation) }
-
This update operator is to
sys.std.Core.Relation.intersection
what the functionsys.std.Core.Relation.assign_union
is tosys.std.Core.Relation.union
. updater sys.std.Core.Relation.assign_difference update { source(Relation) } read { filter(Relation) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.difference
function with the same arguments, and then assigning the result of that function tosource
. updater sys.std.Core.Relation.assign_semidifference update { source(Relation) } read { filter(Relation) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.semidifference
function with the same arguments, and then assigning the result of that function tosource
. This updater is analagous to the common case of the SQL "DELETE" statement where the criteria is simply a set of and-ed and or-ed value equality tests. updater sys.std.Core.Relation.assign_semijoin update { source(Relation) } read { filter(Relation) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.semijoin
function with the same arguments, and then assigning the result of that function tosource
.
Updaters That Rename Attributes
updater sys.std.Core.Relation.assign_rename update { topic(Relation) } read { map(Cat.AttrRenameMap) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.rename
function with the same arguments, and then assigning the result of that function totopic
. This procedure is analagous to the data-manipulation phase of a SQL ALTER TABLE|VIEW RENAME COLUMN statement; each tuple ofmap
corresponds to a renamed SQL table column.
Updaters That Add Attributes
updater sys.std.Core.Relation.assign_extension update { topic(Relation) } read { func(Cat.FuncRef), assuming(QuasiTuple)? }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.extension
function with the same arguments, and then assigning the result of that function totopic
. updater sys.std.Core.Relation.assign_static_extension update { topic(Relation) } read { attrs(Tuple) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.static_extension
function with the same arguments, and then assigning the result of that function totopic
. This procedure is analagous to the data-manipulation phase of a SQL ALTER TABLE|VIEW ADD COLUMN statement; each attribute ofattrs
corresponds to an added SQL table column.
Updaters That Remove Attributes
updater sys.std.Core.Relation.assign_projection update { topic(Relation) } read { attrs(set_of.Cat.Name) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.projection
function with the same arguments, and then assigning the result of that function totopic
. updater sys.std.Core.Relation.assign_cmpl_projection update { topic(Relation) } read { attrs(set_of.Cat.Name) }
-
This update operator is a short-hand for first invoking the
sys.std.Core.Relation.cmpl_projection
function with the same arguments, and then assigning the result of that function totopic
. This procedure is analagous to the data-manipulation phase of a SQL ALTER TABLE|VIEW DROP COLUMN statement; each attribute named byattrs
corresponds to an dropped SQL table column.
SYSTEM-DEFINED GENERIC CONTROL FLOW UPDATERS
updater sys.std.Core.Control.upd_invo update { upd_args(QuasiTuple) } read { updater(Cat.ProcRef), ro_args(QuasiTuple)? }
-
This update operator has the same purpose and features as
sys.std.Core.Control.func_invo
but that it invokes an updater rather than a function; there is no result to deal with, and there are both subject-to-update parameters and read-only parameters of the invoked updater to bind to; they are bound with the attributes of this updater'supd_args
andro_args
arguments, respectively. Thero_args
parameter is optional and defaults as per theargs
parameter offunc_invo
; theupd_args
parameter is non-optional because an updater must always be invoked with at least one subject-to-update argument.
SYSTEM-DEFINED GENERIC SYSTEM SERVICES FOR STANDARD I/O
These system services are provided so Muldis D can do basic user input/output by itself, using standard input and standard output, like any general purpose programming language, and help satisfy its need to be computationally complete. For now they just work with plain (Unicode) text data, so one can implement a basic command-line program interface, or do basic invoker-setup file piping, as well as display diagnostics to standard error. These routines are not exhaustive, and their details are subject to future revision.
system_service sys.std.Core.STDIO.read_Text update { target(Text) } read { length_in_graphemes(UInt) }
-
This system service routine will attempt to read
length_in_graphemes
characters from standard input as a singleText
value, blocking the current in-DBMS process until it finishes, and then update the variable supplied as itstarget
argument so that it holds the read value. The routine will only fetch fewer than the requested number of characters if the input stream is closed first. This routine will throw an exception if any system errors occur. system_service sys.std.Core.STDIO.read_Text_line update { target(Text) } read { ignore_empty_lines(Bool)? }
-
This system service routine is the same as
sys.std.Core.STDIO.read_Text
except that it will read from standard input until an implementation-defined end-of-line character is read, rather than reading a fixed number of characters; this end-of-line character will not be included in the readText
value. If theignore_empty_lines
argument isBool:true
, then this routine will keep reading lines from standard input until it reads a non-empty line, and thentarget
is only updated to hold that last non-empty line; otherwise, this routine will end as soon as one line is read, even if it is empty. system_service sys.std.Core.STDIO.write_Text update {} read { v(Text) }
-
This system service routine will attempt to write the characters of its
v
argument to standard output, blocking the current in-DBMS process until it finishes. This routine will throw an exception if any system errors occur. system_service sys.std.Core.STDIO.write_Text_line update {} read { v(Text) }
-
This system service routine is the same as
sys.std.Core.STDIO.write_Text
except that it will additionally write an implementation-defined end-of-line character after writingv
. system_service sys.std.Core.STDIO.prompt_Text_line update { target(Text) } read { prompt(Text), ignore_empty_lines(Bool)? }
-
This system service routine is a wrapper over first invoking
sys.std.Core.STDIO.write_Text
with itsprompt
argument and then invokingsys.std.Core.STDIO.read_Text_line
with itstarget
argument. A trueignore_empty_lines
argument will result in both of the wrapped routines being invoked repeatedly, not justread_text_line
. system_service sys.std.Core.STDIO.error_Text update {} read { v(Text) }
-
This system service routine is the same as
sys.std.Core.STDIO.write_Text
except that it will write to standard error rather than standard output. system_service sys.std.Core.STDIO.error_Text_line update {} read { v(Text) }
-
This system service routine is the same as
sys.std.Core.STDIO.write_Text_line
except that it will write to standard error rather than standard output.
SYSTEM-DEFINED GENERIC CONTROL FLOW PROCEDURES
These procedures are applicable to use in all kinds of procedures.
procedure sys.std.Core.Control.proc_invo update { upd_args(QuasiTuple)? } read { procedure(Cat.ProcRef), ro_args(QuasiTuple)? }
-
This procedure is the same as
sys.std.Core.Control.upd_invo
but that it invokes a procedure rather than an updater, and thatupd_args
is optional. procedure sys.std.Core.Control.fail update {} read { topic(Cat.Exception) }
-
This procedure will throw the exception given as its argument; this results in the call stack unwinding, and transaction rollbacks, until it is caught.
procedure sys.std.Core.Control.try_catch update { try_updating(QuasiTuple)?, catch_updating(QuasiTuple)? } read { try(Cat.ProcRef), catch(Cat.ProcRef), try_assuming(QuasiTuple)?, catch_assuming(QuasiTuple)? }
-
This procedure invokes the procedure named in its
try
argument, giving it the argumentstry_updating
andtry_assuming
as itsupdating
andassuming
arguments, respectively. If thetry
procedure throws an exception, then any state changes it made roll back (but changes made before that don't), and the call stack unwinds to thetry_catch
itself; then the procedure named bycatch
is invoked similarly totry
was, with corresponding arguments, but with the extra read-only argumenttopic
whose value is aCat.Exception
; if thecatch
procedure also throws an exception (such as to say its not handling the thrown one), then that one is not caught and the call stack unwinding plus applicable transaction rollback carries on to the caller of thetry_catch
. If thetry
procedure succeeds (doesn't throw an exception), then thecatch
procedure is not called. Each of the(try|catch)_(updating|assuming)
parameters is optional and defaults to the zero-attribute tuple if no explicit argument is given to it.
SYSTEM-DEFINED GENERIC BOOTLOADER EXCLUSIVES
These system services may only be invoked directly by a bootloader
routine.
bootloader_exclusive sys.std.Core.Control.start_trans read {}
-
This system service starts a new child-most transaction.
bootloader_exclusive sys.std.Core.Control.commit_trans read {}
-
This system service commits the child-most transaction; it will fail if there isn't one.
bootloader_exclusive sys.std.Core.Control.rollback_trans read {}
-
This system service rolls back the child-most transaction; it will fail if there isn't one.
SEE ALSO
Go to Muldis::D for the majority of distribution-internal references, and Muldis::D::SeeAlso for the majority of distribution-external references.
AUTHOR
Darren Duncan (perl@DarrenDuncan.net
)
LICENSE AND COPYRIGHT
This file is part of the formal specification of the Muldis D language.
Muldis D is Copyright © 2002-2008, Darren Duncan.
See the LICENSE AND COPYRIGHT of Muldis::D for details.
TRADEMARK POLICY
The TRADEMARK POLICY in Muldis::D applies to this file too.
ACKNOWLEDGEMENTS
The ACKNOWLEDGEMENTS in Muldis::D apply to this file too.