=pod

=encoding utf8

=head1 NAME

Muldis::D::Ext::QSet -
Muldis D extension for QSet and QMaybe specific operators

=head1 VERSION

This document is Muldis::D::Ext::QSet version 0.58.0.

=head1 PREFACE

This document is part of the Muldis D language specification, whose root
document is L<Muldis::D>; you should read that root document
before you read this one, which provides subservient details.

=head1 DESCRIPTION

Muldis D has a mandatory core set of system-defined (eternally available)
entities, which is referred to as the I<Muldis D core> or the I<core>; they
are the minimal entities that all Muldis D implementations need to provide;
they are mutually self-describing and are used to bootstrap the language;
any entities outside the core, called I<Muldis D extensions>, are
non-mandatory and are defined in terms of the core or each other, but the
reverse isn't true.

This current C<QSet> document describes the system-defined I<Muldis D QSet
Extension>, which consists of generic operators that are specific to the
C<QSet> and C<QMaybe> parameterized q/relation types, and said operators
are short-hands for generic relational operators in the language core.

This current document does not describe the polymorphic operators that all
types, or some types including core types, have defined over them; said
operators are defined once for all types in L<Muldis::D::Core>.

I<This documentation is pending.>

=head1 SYSTEM-DEFINED QUASI-/SET-CONCERNING FUNCTIONS

Each C<assuming> parameter is optional and defaults to the zero-attribute
tuple if no explicit argument is given to it.

=over

=item C<function sys.std.QSet.is_member result Bool params { set(QSet),
value(Universal) }>

This function results in C<Bool:true> iff its C<value> argument matches the
sole attribute of a q/tuple of its C<set> argument (that is, iff
conceptually C<value> is a member of C<set>), and C<Bool:false> otherwise.
This function will warn if its 2 arguments are incompatible as per
C<sys.std.Core.QRelation.is_subset>.

=item C<function sys.std.QSet.is_not_member result Bool params { set(QSet),
value(Universal) }>

This function is exactly the same as C<sys.std.QSet.is_member> except that
it results in the opposite boolean value when given the same arguments.

=item C<function sys.std.QSet.insertion result QSet params { set(QSet),
value(Universal) }>

This function results in a C<QSet> that is the relational union of C<set>
and a QSet whose sole q/tuple has the sole attribute value of C<value>;
that is, conceptually the result is C<value> inserted into C<set>.  As a
trivial case, if C<value> already exists in C<set>, then the result is just
C<set>.

=item C<function sys.std.QSet.disjoint_insertion result QSet params {
set(QSet), value(Universal) }>

This function is exactly the same as C<sys.std.QSet.insertion> except that
it will fail if C<value> already exists in C<set>.

=item C<function sys.std.QSet.deletion result QSet params { set(QSet),
value(Universal) }>

This function results in a C<QSet> that is the relational difference from
C<set> of a QSet whose sole q/tuple has the sole attribute value of
C<value>; that is, conceptually the result is C<value> deleted from C<set>.
As a trivial case, if C<value> already doesn't exist in C<set>, then the
result is just C<set>.

=item C<function sys.std.QSet.reduction result Universal params {
topic(QSet), func(FuncRef), assuming(QTuple)?, identity(Universal) }>

This function is a generic reduction operator that recursively takes each
pair of input values in C<topic> and applies an argument-specified q/scalar
or q/nonscalar value-resulting function (which is both commutative and
associative) to the pair until just one input value is left, which is the
result.  The function to apply is named in the C<func> argument, and that
function must have 3 arguments named C<v1>, C<v2>, C<assuming>; the last
parameter is curried with the same-named argument of C<reduction>, and the
first 2 parameters are the 2 input q/scalar or q/nonscalar values for an
invocation.  If C<topic> has zero values, then C<reduction> results in the
value given in C<identity>.  I<Note that C<identity> may be changed to take
a function name rather than a value, for consistency with C<func>.>  This
function will fail|warn if the |declared type of C<identity> isn't a
subtype of the |declared type of the sole attribute of C<topic>.

=item C<function sys.std.QSet.maybe_reduction result QMaybe params {
topic(QSet), func(FuncRef), assuming(QTuple)? }>

This function is exactly the same as C<sys.std.QSet.reduction> except that
it does not take an C<assuming> argument, and it results in a C<QMaybe> of
what is otherwise the result type, and that result has zero elements if the
argument has zero elements.

=item C<function sys.std.QSet.QSet_from_wrap result set_of.QTuple params {
topic(QRelation) }>

This function results in a C<QSet> whose sole attribute is q/tuple-typed
and the attribute values are all the q/tuples of C<topic>; is a short-hand
for a relational wrap of all attributes of C<topic> such that the new
q/tuple-valued attribute is named C<value>.

=item C<function sys.std.QSet.QSet_from_attr result QSet params {
topic(QRelation), name(Name) }>

This function results in a C<QSet> consisting of all the values of the
attribute of C<topic> named by C<name>.  It is a short-hand for a unary
projection of just the named attribute plus its renaming to C<value>.

=back

=head1 SYSTEM-DEFINED QUASI-/MAYBE-CONCERNING FUNCTIONS

=over

=item C<function sys.std.QSet.QMaybe.nothing result Nothing params {}>

This selector function results in the only zero-tuple QMaybe value.

=item C<function sys.std.QSet.QMaybe.single result QSingle params {
value(Universal) }>

This selector function results in the QMaybe value with a single q/tuple
whose C<value> attribute's value is the C<value> argument.

=item C<function sys.std.QSet.QMaybe.attr result Universal params {
topic(QSingle) }>

This function results in the q/scalar or q/nonscalar value of the sole
attribute of the sole q/tuple of its argument, which always exists when the
argument is a C<QSingle>.

=item C<function sys.std.QSet.QMaybe.attr_or_default result Universal
params { topic(QMaybe), default(TypeRef) }>

This function results in the q/scalar or q/nonscalar value of the sole
attribute of the sole q/tuple of its argument, if said q/tuple exists;
otherwise, it results in the default value of the q/scalar or q/nonscalar
data type whose name is given in the C<default> argument.  This function is
a short-hand for invoking C<attr_or_value> with the result from invoking
C<sys.std.Core.Universal.default>.

=item C<function sys.std.QSet.QMaybe.attr_or_value result Universal params
{ topic(QMaybe), value(Universal) }>

This function results in the q/scalar or q/nonscalar value of the sole
attribute of the sole q/tuple of C<topic>, if said q/tuple exists;
otherwise, it results in C<value>.  This function will warn if the declared
type of C<value> isn't a subtype of the declared type of the attribute.

=item C<function sys.std.QSet.QMaybe.order result Order params {
topic(QMaybe), other(QMaybe), treat_nothing_as_max(Bool),
ord_func(OrdDetFuncRef)?, ord_assuming(QTuple)?,
reverse_order_of_singles(Bool)? }>

This function is a generic (total) C<order_determination> function for
C<QMaybe> values.  Iff both of its C<topic> and C<other> arguments are
identical, this function results in C<Order:same>.  Otherwise, iff both of
those 2 arguments are C<QSingle> values, then the result of this function
is the result of applying to those 2 arguments the (total)
C<order_determination> function given in its C<ord_func> argument, as
curried by its C<ord_assuming> argument; if C<reverse_order_of_singles> is
C<Bool:true> then C<sys.std.Core.Cat.Order_reverse> is also applied such
that the result of C<ord_func> is reversed, and otherwise it isn't applied.
Otherwise, iff C<topic> is C<Nothing>, this function results in
C<Order:increase> or C<Order:decrease> respectively when
C<treat_nothing_as_max> is C<Bool:false> (the default) or C<Bool:true>.
Otherwise (iff C<other> is C<Nothing>), this function results in the
reverse of when only C<topic> is C<Nothing>.  In situations where a
C<QMaybe> is used analagously to a SQL nullable value and this function is
analagous to the binary comparison underlying a SQL "ORDER BY", then
C<reverse_order_of_singles> designates SQL's "ASC|DESC" and
C<treat_nothing_as_max> designates SQL's "NULLS FIRST|LAST".

=back

=head1 SEE ALSO

Go to L<Muldis::D> for the majority of distribution-internal
references, and L<Muldis::D::SeeAlso> for the majority of
distribution-external references.

=head1 AUTHOR

Darren Duncan (C<perl@DarrenDuncan.net>)

=head1 LICENSE AND COPYRIGHT

This file is part of the formal specification of the Muldis D language.

Muldis D is Copyright © 2002-2009, Darren Duncan.

See the LICENSE AND COPYRIGHT of L<Muldis::D> for details.

=head1 TRADEMARK POLICY

The TRADEMARK POLICY in L<Muldis::D> applies to this file too.

=head1 ACKNOWLEDGEMENTS

The ACKNOWLEDGEMENTS in L<Muldis::D> apply to this file too.

=cut
