=pod =encoding utf8 =head1 NAME Muldis::D::Dialect::HDMD_Perl6_STD - How to format Perl 6 Hosted Data Muldis D =head1 VERSION This document is Muldis::D::Dialect::HDMD_Perl6_STD version 0.99.0. =head1 PREFACE This document is part of the Muldis D language specification, whose root document is L; you should read that root document before you read this one, which provides subservient details. =head1 DESCRIPTION This document outlines the grammar of the I dialect named C. The fully-qualified name of this Muldis D dialect, in combination with the base language spec it is bundled with, is C<[ 'Muldis_D', 'http://muldis.com', 'N.N.N', 'HDMD_Perl6_STD' ]> (when the bundled base language version is substituted for the C). The C dialect is defined to be hosted in Perl 6, and is composed of just|mainly core Perl 6 types. This dialect is optimized for Perl 6 specifically, and doesn't try to match the version for Perl 5; you *will* have to reformat any Perl Hosted Data Muldis D when migrating between Perl 5 and Perl 6, same as with your ordinary Perl code. This dialect is designed to exactly match the structure of a possible concrete syntax tree, comprised of native Perl 6 scalar and collection typed values, resulting from parsing code written in the Muldis D dialect L using Perl 6. This dialect exists as a convenience to Perl 6 programmers that want to generate or introspect Muldis D code by saving them the difficulty and overhead of escaping and stitching plain text code; it is expected that a Muldis D implementation written in Perl 6 will natively accept input in both the C and C dialects. Furthermore, the C dialect provides additional Muldis D syntax options to Perl 6 programmers besides what C would canonically parse into, such as the direct use of some Perl 6-only features. B file, for both dialects; this current file will mainly focus on the differences; you should read the L file before the current one, so to provide a context for better understanding it.> =head1 GENERAL STRUCTURE A C Muldis D code file is actually a Perl 6 code file that defines particular multi-dimensional Perl data structures which resemble possible concrete syntax trees (CSTs) from parsing C Muldis D code. Each component of a CST is called a I or node element, and roughly corresponds to a capture by the C parser. A node is typically represened as a Perl Seq|Array, but could alternately be a Perl scalar or something else, and so C Muldis D code is typically a tree of Perl structures, called I, with Perl Seq|Array as the central nodes and Perl scalars as the leaf nodes. Often C code is embedded or constructed in one or more files of a larger Perl 5 program that does more than define this code, such as various non-database-related tasks. A node tree is just composed using basic Perl data types, and there are no Muldis D node-specific Perl classes or objects required for doing this. Note that Perl undefined values are not allowed anywhere in a node in the general case; you must use only defined values instead. This documentation also assumes that only defined values are used, and that supplying a Perl undef will result in an error. The few exceptions to this rule are explicitly stated. The grammar in this file is informal and consists just of written descriptions of how each kind of I must be composed and how to interpret such Perl data structures as Muldis D code. Every named grammar node is a Perl Seq|Array unless otherwise stated, and every grammar element is a Seq|Array element; the first node element is the Seq|Array element at index zero, and so on. The root grammar node for the entire dialect is C. =head1 START A C node has 2 ordered elements where the first element is a C node and the second element is either a C node or a C node. See the pod sections in this file named L, L, and L, for more details about the aforementioned tokens/nodes. When Muldis D is being compiled and invoked piecemeal, such as because the Muldis D implementing virtual machine (VM) is attached to an interactive user terminal, or the VM is embedded in a host language where code in the host language invokes Muldis D code at various times, many C may be fed to the VM directly for inter-language exchange, and not every one would then have its own C. Usually a C would be supplied to the Muldis D VM just once as a VM configuration step, which provides a context for further interaction with the VM that just involves Muldis D code that isn't itself qualified with a C. =head1 LANGUAGE NAME As per the VERSIONING pod section of L, code written in Muldis D must start by declaring the fully-qualified Muldis D language name it is written in. The C dialect formats this name as a C node having 5 ordered elements: =over =item C This is the Muldis D language base name; it is simply the Perl C value C. =item C This is the base authority; it is a Perl C formatted as per a specific-context C value literal; it is typically the Perl C value C. =item C This is the base version number; it is a Perl C formatted as per C; it is typically a Perl C value like C<1.2.3>. =item C This is the dialect name; it is simply the Perl C value C. =item C This is a set of chosen pragma/parser-config options, which is formatted similarly to a C SCVL. The only currently defined pragma, C (see the L pod section), is mandatory; others may be added later which would likely be optional. The value associated with the C attribute named C must be one of these 4 Perl C values: C, C, C, C. =back Examples: [ 'Muldis_D', 'http://muldis.com', '1.2.3', 'HDMD_Perl6_STD', { catalog_abstraction_level => 'rtn_inv_alt_syn' } ] =head1 CATALOG ABSTRACTION LEVELS The C pragma determines with a broad granularity how large the effective Muldis D grammar is that a programmer may employ with their Muldis D code. The catalog abstraction level of some Muldis D code is a measure of how much or how little that code would resemble the system catalog data that the code would parse into. The lower the abstraction level, the smaller and simpler the used Muldis D grammar is and the more like data structure literals it is; the higher the abstraction level, the larger and more complicated the Muldis D grammar is and the more like general-purpose-language typical code it is. There are currently 4 specified catalog abstraction levels, which when arranged from lowest to highest amount of abstraction, are: C, C, C, C. Every abstraction level has a proper superset of the grammar of every other abstraction level that is lower than itself, so for example any code that is valid C is also valid C, and so on. =head2 the_floor This abstraction level exists more as an academic exercise and is not intended to actually be used. Examples: [ [ 'Muldis_D', 'http://muldis.com', '1.2.3', 'HDMD_Perl6_STD', { catalog_abstraction_level => 'the_floor' } ], :Relation( Set.new( { food => [ 'Scalar', 'Text', nfd_codes => { '' => ['Scalar', 'String.<67><97><114><114><111><116><115>',{}] } ], qty => [ 'Scalar', 'Int', { '' => ['Scalar','String.<100>',{}] } ] }, { food => [ 'Scalar', 'Text', nfd_codes => { '' => ['Scalar','String.<75><105><119><105><115>',{}] } ], qty => [ 'Scalar', 'Int', { '' => ['Scalar','String.<30>',{}] } ] } ) ) ] =head2 code_as_data This abstraction level is the best one for when you want to write code in exactly the same form as it would take in the system catalog. Code written to the C level can employ all of the language grammar constructs described in these main pod sections: L, L, L. Examples: [ [ 'Muldis_D', 'http://muldis.com', '1.2.3', 'HDMD_Perl6_STD', { catalog_abstraction_level => 'code_as_data' } ], :Relation( Set.new( { food => 'Carrots', qty => 100 }, { food => 'Kiwis', qty => 30 } ) ) ] [ [ 'Muldis_D', 'http://muldis.com', '1.2.3', 'HDMD_Perl6_STD', { catalog_abstraction_level => 'code_as_data' } ], [ 'depot', :depot-catalog[ 'Database', 'Depot', { functions => :Relation( Set.new( { name => :Name, is_public => Bool::True, material => [ 'Tuple', 'Function', { result_type => :NameChain, params => [ 'Relation', 'NameTypeMap', Set.new( { name => :Name, type => :NameChain } ) ], expr => [ 'Database', 'ExprNodeSet', { sca_val_exprs => :Relation( Set.new( { name => :Name, value => 3 } ) ), func_invo_exprs => :Relation( Set.new( { name => :Name(''), function => :NameChain('Integer.power'), args => [ 'Relation', 'NameExprMap', [ {name=>:Name, expr=>:Name}, {name=>:Name, expr=>:Name} ] ] } ) ) } ] } ] } ) ) } ] ] ] =head2 plain_rtn_inv This abstraction level is the lowest one that can be recommended for general use. Code written to the C level can employ all of the language grammar constructs that C can, plus all of those described in these main pod sections: L. Examples: [ [ 'Muldis_D', 'http://muldis.com', '1.2.3', 'HDMD_Perl6_STD', { catalog_abstraction_level => 'plain_rtn_inv' } ], [ 'depot', :depot-catalog[ [ 'function', 'public', 'cube', [ 'Int', { topic => 'Int' }, [ [ 'func-invo', 'Integer.power', { radix => ['$','topic'], exponent => 3 } ] ] ] ] ] ] ] =head2 rtn_inv_alt_syn This abstraction level is the highest one and is the most recommended one for general use. Code written to the C level can employ all of the language grammar constructs that C can, plus all of those described in these main pod sections: L. Examples: [ [ 'Muldis_D', 'http://muldis.com', '1.2.3', 'HDMD_Perl6_STD', { catalog_abstraction_level => 'rtn_inv_alt_syn' } ], [ 'depot', :depot-catalog[ [ 'function', 'public', 'cube', [ 'Int', { topic => 'Int' }, [ [ 'op', 'I^', [ ['$','topic'], 3 ] ] ] ] ] ] ] ] =head1 VALUE LITERALS AND SELECTORS A C node is a Muldis D value literal, which is a common special case of a Muldis D value selector. There are 27 main varieties of C node, each of which is a named node kind of its own: C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C. Fundamentally, the various Muldis D scalar and collection types are represented by their equivalent Perl native scalar and collection types. But since Muldis D is more strongly typed, or at least differently typed, than Perl, each C node is represented by a Perl Seq|Array, whose elements include both the payload Perl literal plus explicit meta-data for how to interpret that Perl literal for mapping to Muldis D. =head2 Value Literal Common Elements Every C node is either a GCVL (generic context value literal) or a SCVL (specific context value literal). Every GCVL has 1-3 ordered elements: =over =item C This is a Perl C value of the format C<< <[A..Z]> <[ a..z A..Z ]>+ >>; it identifies the data type of the value literal in broad terms and is the only external meta-data of C generally necessary to interpret the latter; what grammars are valid for C depend just on C. Between the various kinds of C node, these 51 values are allowed for C: C, C, C, C<[|NN|P]Int>, C<[|NN|P]Rat>, C<[|Octet]Blob>, C, C, C, C, C, C, C, C, C, C, C, C<[|B|O|UCP]String>, C<[|DH]Scalar>, C<[|DH]Tuple>, C, C<[|DH]Relation>, C<[|DH]Set>, C<[|DH][Maybe|Single]>, C<[|DH]Array>, C<[|DH]Bag>, C<[|DH]Interval>. For just some data types, the C may be omitted; see below. =item C Only when the C node has 3 elements: This is a Muldis D data type name, for example C; it identifies a specific subtype of the generic type denoted by C, and serves as an assertion that the Muldis D value denoted by C is a member of the named subtype. Its format is a C node. Iff C is C<[|DH]Scalar> then C is mandatory; otherwise, C is optional for all C, except that C must be omitted when C is one of the 2 [C, C]; this isn't because those 2 types can't be subtyped, but because in practice doing so isn't useful. =item C This is mandatory for all C. Format varies with C. =back A Perl Pair may alternately be used to represent a GCVL iff that node has exactly 2 elements (C and C); in that case, the C is stored in that Pair's key, and the C is stored in the Pair's value. For some data types, a GCVL may alternately be just its payload for the sake of brevity. If any Perl value of one of the following types is encountered where a GCVL node is expected, then it is interpreted as a full C node as follows: Muldis D <- Perl 6 -------------------- Bool <- Bool Order <- Order Int <- Int Rat <- Rat|Num Blob <- Blob Text <- Str Instant <- Instant Duration <- Duration Interval <- Range The above details are subject to revision regarding when a Perl object might claim to do multiple type interfaces. For GCVL and SCVL examples, see the subsequent documentation sections. =head1 OPAQUE VALUE LITERALS =head2 Boolean Literals A C node represents a logical boolean value. It is interpreted as a Muldis D C value as follows: The payload must be a Perl C, and so C and C are mapped directly. Examples: :Bool(Bool::True) Bool::False =head2 Order-Determination Literals A C node represents an order-determination. It is interpreted as a Muldis D C value as follows: The payload must be a Perl C, and so C and C and C are mapped directly. Examples: :Order(Order::Same) Order::Decrease =head2 Rational Rounding Method Literals A C node represents a rational rounding method. It is interpreted as a Muldis D C value by directly mapping the payload. The payload must be a Perl C having one of the 7 values C, C, C, C, C, C, C. Examples: :RatRoundMeth :RatRoundMeth =head2 General Purpose Integer Numeric Literals An C node represents an integer numeric value. It is interpreted as a Muldis D C value as follows: The payload must be a Perl C, which is mapped directly. Examples: :Int(:2<11001001>) # binary # :8<0> # octal # :8<644> # octal # -34 # decimal # 42 # decimal # :16 # hexadecimal # :36<-HELLOWORLD> # base-36 # :4<301> # base-4 # :12 # base-12 # =head2 General Purpose Rational Numeric Literals A C node represents a rational numeric value. It is interpreted as a Muldis D C value as follows: The payload must be a Perl C, which is mapped directly. Examples: :Rat(:2<-1.1>) -1.5 # same val as prev # 3.14159 :11<0.0> :16 :36<0.000AZE> :Rat(:7<500001>/:7<1000>) :12/:12 :Rat(:2<1011101101> * :2<10> ** :2<-11011>) 45207196 * 10 ** 37 1/43 314159 * 10 ** -5 =head2 General Purpose Binary String Literals A C node represents a general purpose bit string. It is interpreted as a Muldis D C value as follows: The payload must be a Perl C, which is mapped directly. Examples I: :Blob( Blob.new( 2 => '00101110100010' ) ) # binary # Blob.new( 4 => '' ) Blob.new( 16 => 'A705E' ) # hexadecimal # Blob.new( 8 => '523504376' ) =head2 General Purpose Character String Literals A C node represents a general purpose character string. It is interpreted as a Muldis D C value by directly mapping the payload. The payload must be a Perl C. Examples: :Text 'サンプル' '' 'Perl' "\c[LATIN SMALL LETTER OU]\x[263A]\c[65]" =head2 DBMS Entity Name Literals A C node represents a canonical short name for any kind of DBMS entity when declaring it; it is a character string type, that is disjoint from C. It is interpreted as a Muldis D C value by directly mapping the payload. The payload must be a Perl C. A C node represents a canonical long name for invoking a DBMS entity in some contexts; it is conceptually a sequence of entity short names. Its payload is a Perl C value or C value. This node is interpreted as a Muldis D C value as follows: =over =item * If the payload is an C, then it must have at least 1 element, and every element must be a valid payload for a C node (that is, any Perl character string). Each element of the payload, in order, defines an element of the C possrep's attribute of a C. =item * If the payload is a C, then it must be formatted as a catenation (using period (C<.>) separators) of at least 1 part, where each part can not have any literal period (C<.>) characters (if you want literal periods then you can only use the C payload format to express it). The C format of payload is interpreted by splitting it on the separators into the C format, then processed as per the latter. As a special case, if the C payload begins with a period separator, then the first element of the post-split result is treated not as the empty string C, but rather as the C value C; that is, C<.foo> means the same thing as C (if you want a literal empty string first element, then you can only use the C payload format to express it). =back A C node represents a canonical long name for declaring a DBMS entity in N-depth contexts; the format and interpretation of a C (but as a C value) is the same as a C but that the chain may have as few as zero parts rather than as few as 1 or 2; however, a zero part chain can only be expressed with the C payload format; an empty string C format will be interpreted as having a single element that is the empty string. Examples: :Name :Name('First Name') :NameChain['fed','data','the_db','gene','sorted_person_names'] :NameChain('fed.data.the_db.stats.samples by order') :NameChain('.attr') # same as :NameChain('lex.topic.attr') # :DeclNameChain['gene','sorted_person_name'] :DeclNameChain('stats.samples by order') :DeclNameChain[] =head2 Code Comment Literals A C node represents the text of a Muldis D code comment; it is a character string type, that is disjoint from both C and C. It is interpreted as a Muldis D C value by directly mapping the payload. The payload must be a Perl C. Examples: :Comment('This does something.') :Comment('So does this.') =head2 TAI Temporal Literals An C node represents a single point in time which is specified in terms of atomic seconds. This node is interpreted as a Muldis D C value as follows: The payload must be a Perl C, which is mapped directly. A C node represents a single amount of time (the difference between two instants) which is specified in terms of atomic seconds. This node is interpreted as a Muldis D C value as follows: The payload must be a Perl C, which is mapped directly. Examples I: :Instant( Instant.new(1235556432.0) ) Instant.new(854309115.0) :Duration( Duration.new(3600.0) ) Duration.new(-50.0) Duration.new(3.14159) Duration.new(:2<1011101101> * :2<10> ** :2<-11011>) Duration.new(1/43) =head2 UTC and Float Temporal Literals A C node represents an "instant"/"datetime" value that is affiliated with the UTC time-zone. This node is interpreted as a Muldis D C value whose C possrep attribute values are defined as follows: The payload must be a Perl C with 6 elements, where each element may be either undefined or defined; or if fewer than 6 elements are provided, the C will be implicitly extended to 6, filling with undefs. The 6 payload elements correspond in order, from the lowest to the highest indexed, to the 6 attributes: C, C, C, C, C, C. For each payload element that Perl considers undefined or defined, the corresponding attribute has the C or a C value, respectively. For each of the first 5 elements, when it is defined, it must qualify as a valid payload for an C node; for the 6th element, when it is defined, it must qualify as a valid payload for a C node. A defined C may be any integer, each of [C, C] must be a positive integer, each of [C, C] must be a non-negative integer, and C must be a non-negative rational number. If all 6 attributes are defined, then the new C value is also a C; if just the first 3 or last 3 are defined, then the value is not a C but rather a C or C, respectively; if any other combination of attributes are defined, then the value is just a C and not of any of the other 3 subtypes. A C node represents an "instant"/"datetime" value that is "floating" / not affiliated with any time-zone. This node is interpreted as a Muldis D C value in an identical fashion to how a C node is interpreted, whose format it completely shares. Likewise regarding C. A C node represents a duration value, an amount of time, which is not fixed to any instant in time. This node is interpreted as a Muldis D C value whose C possrep attribute values are defined as follows: The payload must be a Perl C with 6 elements, where each element may be either undefined or defined; or if fewer than 6 elements are provided, the C will be implicitly extended to 6, filling with undefs. The 6 payload elements correspond in order, from the lowest to the highest indexed, to the 6 attributes: C, C, C, C, C, C. For each payload element that Perl considers undefined or defined, the corresponding attribute has the C or a C value, respectively. For each of the first 5 elements, when it is defined, it must qualify as a valid payload for an C node; for the 6th element, when it is defined, it must qualify as a valid payload for a C node. A defined [C, C, C, C, C] may be any integer, and C may be any rational number. I has no system-defined subtypes, but that may change later.> Examples: :UTCInstant[1964,10,16,16,12,47.5] # a UTCDateTime # :UTCInstant[2002,12,6] # a UTCDate # :UTCInstant[undef,undef,undef,14,2,29.0] # a UTCTime # :FloatInstant[2003,4,5,2] # min,sec unknown or N/A # :FloatInstant[1407] # just know its sometime in 1407 # :UTCDuration[3,5,1,6,15,45.000012] =head2 Rational Rounding Rule Literals A C node represents a rational rounding rule. It is interpreted as a Muldis D C value whose attributes are defined by the C. A C must be a Perl C with 3 elements, which correspond in order to the 3 attributes: C (a C), C (an C), and C (a C). Each of C and C must qualify as a valid C, and C must qualify as a valid C. Examples: :RatRoundRule[10,-2,'half_even'] :RatRoundRule[2,-7,'to_zero'] =head2 Low Level Integer String Literals A C node represents an integer string value. It is interpreted as a Muldis D C value as follows: The payload must be a Perl C, whose elements are all Perl C, which is mapped directly; each payload element is mapped directly as per the payload of an C node. Examples: :String[80,101,114,109] # Unicode abstract codepoints = 'Perl' # :String[0x50,0x65,0x72,0x6C] # same thing # =head1 COLLECTION VALUE SELECTORS Note that, with each of the main value selector nodes documented in this main POD section, any occurrences of child C nodes should be read as being C nodes instead in contexts where instances of the main nodes are being composed beneath C nodes. That is, any C node options beyond what C options exist are only valid within a C node. =head2 Scalar Selectors A C node represents a literal or selector invocation for a scalar subtype value. It is interpreted as a Muldis D C subtype value whose declared type is specified by the node's (mandatory for C) C element and whose attributes are defined by the payload. If the payload is a Perl C, then its key and value, respectively, are designated I and I; if the payload is not a Perl C, then it is interpreted as if it was just the I, and the I was the empty string. The possrep name and possrep attrs must be as per the payload of a C and C node, respectively. The I is interpreted specifically as attributes of the declared type's possrep which is specified by the I. Each key+value pair of the I defines a named possrep attribute of the new scalar; the pair's key and value are, respectively, a Perl C that specifies the possrep attribute name, and a C node that specifies the possrep attribute value. Examples: [ 'Scalar', 'sys.std.Core.Type.Cat.Name', { '' => 'the_thing' } ] [ 'Scalar', 'sys.std.Core.Type.Rat', float => { mantissa => 45207196, radix => 10, exponent => 37, } ] [ 'Scalar', 'sys.std.Temporal.Type.UTCDateTime', datetime => { year => 2003, month => 10, day => 26, hour => 1, minute => 30, second => 0.0, } ] [ 'Scalar', 'fed.lib.the_db.WeekDay', name => { '' => 'monday', } ] [ 'Scalar', 'fed.lib.the_db.WeekDay', number => { '' => 5, } ] [ 'Scalar', 'Int', { '' => ['Scalar','String.<42>',{}] } ] [ 'Scalar', 'Text', nfd_codes => { '' => ['Scalar','String.<80><101><114><109>',{}] } ] =head2 Tuple Selectors A C node represents a literal or selector invocation for a tuple value. It is interpreted as a Muldis D C value whose attributes are defined by the payload. The payload must be a Perl C. Each key+value pair of the payload defines a named attribute of the new tuple; the pair's key and value are, respectively, a Perl C that specifies the attribute name, and a C node that specifies the attribute value. Examples: :Tuple{} [ 'Tuple', 'type.tuple_from.var.fed.data.the_db.account.users', { login_name => 'hartmark', login_pass => 'letmein', is_special => Bool::True, } ] :Tuple{ name => 'Michelle', age => 17, } =head2 Database Selectors A C node represents a literal or selector invocation for a 'database' value. It is interpreted as a Muldis D C value whose attributes are defined by the payload. The payload must be a Perl C. Each key+value pair of the payload defines a named attribute of the new 'database'; the pair's key and value are, respectively, a Perl C that specifies the attribute name, and a C node that specifies the attribute value, which must be represent a relation value. =head2 Relation Selectors A C node represents a literal or selector invocation for a relation value. It is interpreted as a Muldis D C value whose attributes and tuples are defined by the payload, which is interpreted as follows: =over =item * Iff the payload is a Perl C with zero elements, then it defines the only relation value having zero attributes and zero tuples. =item * Iff the payload is a Perl C with at least one element, and every element is a Perl C (as per a valid payload for a C node), then it defines the attribute names of a relation having zero tuples. =item * Iff the payload is a Perl C with at least one element, and every element is a Perl C (as per a valid payload for a C node), then each element of the payload defines a tuple of the new relation; every tuple-defining element of the payload must be of the same degree and have the same attribute names as its sibling elements; these are the degree and attribute names of the relation as a whole, which is its heading for the current purposes. =item * Iff the payload is a Perl C, then: The new relation value's attribute names are defined by the payload's key, which is a Perl C of C (each as per a C node payload), and the relation body's tuples' attribute values are defined by the payload's value, which is a Perl C of C of tuple attribute value defining nodes. This format is meant to be the most compact of the generic relation payload formats, as the attribute names only appear once for the relation rather than repeating for each tuple. As a trade-off, the attribute values per tuple from the payload value must appear in the same order as their corresponding attribute names appear in the payload key, as the names and values in the relation literal are matched up by ordinal position here. =back Examples I: :Relation( Set.new() ) # zero attrs + zero tuples # :Relation( Set.new() ) # 3 attrs + zero tuples # :Relation( Set.new( {} ) ) # zero attrs + 1 tuple # :Relation( Set.new( { login_name => 'hartmark', login_pass => 'letmein', is_special => Bool::True, }, ) ) # 3 attrs + 1 tuple # [ 'Relation', 'fed.lib.the_db.gene.Person', => Set.new( [ 'Michelle', 17 ], ) ] # 2 attrs + 1 tuple # =head2 Set Selectors A C node represents a literal or selector invocation for a set value. It is interpreted as a Muldis D C value whose elements are defined by the payload. The payload must be a Perl C. Each element of the payload defines a unary tuple of the new set; each element is a C node that defines the C attribute of the tuple. Examples I: [ 'Set', 'fed.lib.the_db.account.Country_Names', Set.new( 'Canada', 'Spain', 'Jordan', 'Thailand', ) ] :Set( Set.new( 3, 16, 85, ) ) =head2 Maybe Selectors A C node represents a literal or selector invocation for a maybe value. It is interpreted as a Muldis D C value. If the node payload is missing or undefined, then the node is interpreted as the special value C, aka C, which is the only C value with zero elements. If the node payload is defined then the node is interpreted as a C whose element is defined by the payload. The payload is a C node that defines the C attribute of the single tuple of the new 'single'. Examples: :Maybe( 'I know this one!' ) :Maybe() # or how does Perl 6 make a Pair with undef/default value? # =head2 Array Selectors A C node represents a literal or selector invocation for a array value. It is interpreted as a Muldis D C value whose elements are defined by the payload. The payload must be a Perl C. Each element of the payload defines a binary tuple of the new sequence; the element value is a C node that defines the C attribute of the tuple, and the element index is used as the C attribute of the tuple. Examples: :Array[ 'Alphonse', 'Edward', 'Winry', ] [ 'Array', 'fed.lib.the_db.stats.Samples_By_Order', [ 57, 45, 63, 61, ] ] =head2 Bag Selectors A C node represents a literal or selector invocation for a bag value. It is interpreted as a Muldis D C value whose elements are defined by the payload. The payload must be a Perl C value; the payload element keys are C nodes corresponding to the C attribute of the new bag's tuples, and the payload element values are positive integers (or C, which counts as the number 1) corresponding to the C attribute; the payload element mapping is as you should expect. Examples I: [ 'Bag', 'fed.lib.the_db.inventory.Fruit', Bag.new( 'Apple' => 500, 'Orange' => 300, 'Banana' => 400, ) ] :Bag( Bag.new( [ 'Foo', 'Quux', 'Foo', 'Bar', 'Baz', 'Baz', ] ) ) =head2 Interval Selectors An C node represents a literal or selector invocation for an interval value. It is interpreted as a Muldis D C value whose attributes are defined by the payload. The node payload must be a Perl C, which is mapped directly. Each of the C and C attributes/method-return-values of the Range is an C node that defines the C and C attribute value, respectively, of the new interval. Each of the C and C of the Range maps directly with the interval. Examples: :Interval(1..10) 2.7..^9.3 'a'^..'z' :UTCInstant[2002,12,6] ^..^ :UTCInstant[2002,12,20] =head1 DEPOT SPECIFICATION A C node has 2-3 ordered elements such that 3 elements means the depot has a normal-user-data database and 2 elements means it has just a (possibly empty) system catalog database: The first element is the Perl C value C. Iff the C has 3 elements then the third element specifies the normal-user-data database; it is a Perl C whose key is the Perl C value C and whose value is a C node. The second element specifies the system catalog database; it is a Perl C whose key is the Perl C value C and whose value is either a C node or a Perl C which is hereafter referred to as C. A C either has zero elements, designating an empty catalog, or all of its elements are Perl C (in particular, none of its elements is the Perl C value 'Database'), each of which is one of the following kinds of nodes: C, C, C. A C node has 3 ordered elements: The first element is the Perl C value C. The second element is a C, which is the declared name of the subdepot within the namespace defined by its parent subdepot (or depot). The third element is a C. A C node has 2 ordered elements: The first element is the Perl C value C. The second element is a C, which specifies what the normal-user-data database has as its declared data type. Examples: # A completely empty depot that doesn't have a self-local dbvar. # [ 'depot', :depot-catalog[] ] # Empty depot with self-local dbvar with unrestricted allowed values. # [ 'depot', :depot-catalog[ [ 'self-local-dbvar-type', 'Database' ] ], :depot-data[ 'Database', {} ] ] # A depot having just one function and no dbvar. # [ 'depot', :depot-catalog[ [ 'function', 'public', 'cube', [ 'Int', { topic => 'Int' }, [ [ 'op', 'I^', [ ['$','topic'], 3 ] ] ] ] ] ] ] =head1 MATERIAL SPECIFICATION A C node specifies a new material (routine or type) that lives in a depot or subdepot. There are 7 main varieties of C node, each of which is a named node kind of its own: C, C, C, C, C, C, C. =head2 Material Specification Common Elements A C node has 2-4 ordered elements, such that a material that has 2 elements is an C and a material with 3-4 elements is a C: The first element is C. The last element is C. Iff there are 3-4 elements then the second-to-last element is C. Iff there are 4 elements then the second element is C. =over =item C This is a Perl C value of the format C<< [<[ a..z ]>+] ** '-' >>; it identifies the kind of the material and is the only external meta-data of C generally necessary to interpret the latter; what grammars are valid for C depend just on C. =item C This is one of the 2 Perl C values [C, C]; it is C if the material is part of its containing subdepot's own public interface and may be invoked from outside the subdepot; it is C if it is just part of the subdepot's internals. This is optional iff C is a C; this must be omitted iff C is an C. If C is not explicitly specified then the C is interpreted as if it were explicitly C (so all C are private). =item C This is the declared name of the material within the namespace defined by its subdepot (or depot). It is explicitly specified iff the C is a C =item C This is mandatory for all C. It specifies the entire material sans its name. Format varies with C. =back For material examples, see the subsequent documentation sections. =head2 Function Specification I =head2 Updater Specification I =head2 Procedure Specification I =head2 Scalar Type Specification I =head2 Nonscalar Type Specification I =head2 Union Type Specification I =head2 Subset Type Specification I =head1 GENERIC VALUE EXPRESSIONS An C node has 2 ordered elements: The first element is the Perl C value C<$>. The second element is a C. An C node may alternately be formatted as a Perl Pair whose key and value are what would otherwise be the first and second node elements, respectively. A C node has 3 ordered elements: The first element is the Perl C value C<::=>. The second element is a C and the third element is an C node; the second element declares an explicit expression node name for the third element. Examples: # an expr_name node # ['$','foo_expr'] # a named_expr node # [ '::=', 'bar_expr', [ 'func-invo', 'factorial', [['$','foo_expr']] ] ] =head2 Generic Expression Attribute Accessors An C node has 2-3 ordered elements, such that 2 elements makes it an C and 3 elements makes it an C: The first element is the Perl C value C<$.>. The last element of an C is a C, which is by itself the C of the accessor (naming both the other node plus its attribute to alias). The second element of an C is an C node which is the other node whose attribute is being aliased. The last element of an C is a C and names the attribute. Examples: # an accessor node of a named tuple-valued node # ['$.','foo_t.bar_attr'] # an accessor node of an anonymous tuple-valued node # ['$.',['func-invo','sdp.lib.tuple_res_func',[['$','arg']]],'quux_attr'] =head2 Generic Function Invocation Expressions An C node has 2-4 ordered elements: The first element is the Perl C value C. The second element is a C, which names the function to invoke. The last 1-2 elements provide arguments to the function invocation; either or both or none of a C element and a C element may be given. The C 3rd/4th element is for any anonymous (and ordered if multiple exist) arguments, and the C 3rd/4th element is for any named arguments; each C element or C element value is an C node which is the argument value. Examples: # zero params # [ 'func-invo', 'nothing' ] # single mandatory param # [ 'func-invo', 'Integer.median', [ :Bag( Bag.new( [ 22, 20, 21, 20, 21, 21, 23 ] ) ) ] ] # single mandatory param # [ 'func-invo', 'factorial', { topic => 5 } ] # two mandatory params # [ 'func-invo', 'Rational.quotient', { dividend => 43.7, divisor => 16.9 } ] # one mandatory 'topic' param, two optional # [ 'func-invo', 'sdp.lib.barfunc', [ ['$','mand_arg'] ], { oa1 => ['$','opt_arg1'], oa2 => ['$','opt_arg2'] } ] # a user-defined function # [ 'func-invo', 'dep.lib.foodb.bazfunc', { a1 => 52, a2 => 'hello world' } ] # two params named 'topic' and 'other' # [ 'func-invo', 'is_identical', [ ['$','foo'], ['$','bar'] ] ] =head2 Generic If-Else Expressions An C node has 2-3 ordered elements: The first element is either of the 2 Perl C values C and C. The optional second element is I, a Perl C with 0..N elements, each of those being a 2-element Perl C or a Perl Pair, where each element is an C node; the first element / key is an I condition expression, and the second element / value is the associated I result expression. The 3rd/last element of an C node is I result expression, which is an C node. Examples: [ 'if-else-expr', [ [ 'op', '>', [['$','foo'], 5] ] => ['$','bar'], ], ['$','baz'] ] [ 'if-else-expr', [ [ 'op', 'is-empty', [['$','ary']] ] => ['$','empty_result'], ], [ 'op', '.[]', [['$','ary'], 0] ] ] [ 'op', 'T~', ['My answer is: ', [ '??!!', [ ['$','maybe'] => 'yes' ], 'no' ]] ] =head2 Generic Given-When-Default Expressions A C node has 3-4 ordered elements: The first element is the Perl C value C. The second element is an C node which is the I common comparand. The optional third element is I, a Perl C with 0..N elements, each of those being a 2-element Perl C or a Perl Pair, where each element is an C node; the first element / key is a I comparand, and the second element / value is the associated I result expression. The 4th/last element of an C node is I result expression, which is an C node. Examples: [ 'given-when-def-expr', ['$','digit'], [ 'T' => 10, 'E' => 11, ], ['$','digit'], ] =head2 Library Entity Reference Selector A C<[func|upd|proc|type|ord_det_func]_ref> node has 2 ordered elements: The first element is the Perl C value C<[func|upd|proc|type|ord-det-func]-ref>. The second element is a C, which names the routine|type to invoke. A C<[func|proc|type|ord-det-func]-ref> node may alternately be formatted as a Perl Pair whose key and value are what would otherwise be the first and second node elements, respectively. Examples: :func-ref :upd-ref :proc-ref :type-ref :ord-det-func-ref =head1 FUNCTION INVOCATION ALTERNATE SYNTAX EXPRESSIONS A C node has 3-4 ordered elements: The first element is the Perl C value C. The second element is a Perl C value, hereafter referred to as I or I, which determines the function to invoke. The third element is (usually) a Perl C, hereafter referred to as I
, which is an ordered list of 1-N mandatory inputs to the function invocation. The (optional) fourth element is a Perl C, hereafter referred to as I, which is a named list of optional function inputs. The number and format of elements of either I
or I varies depending on I. Note that, when a I
would just contain a single element, such as when it is for a monadic operator, it may alternately be formatted as what is otherwise just its sole (node) element iff that node is not formatted as a Perl C. =head2 Simple Commutative N-adic Infix Reduction Operators A C node has 2-N main op args, each of which is an C node. Note that the I
may alternately be given as a Perl C rather than a Perl C. Examples: [ 'op', 'and', [ Bool::True, Bool::False, Bool::True ] ] [ 'op', 'or', [ Bool::True, Bool::False, Bool::True ] ] [ 'op', 'xor', [ Bool::True, Bool::False, Bool::True ] ] [ 'op', 'I+', [ 14, 3, -5 ] ] [ 'op', 'I*', [ -6, 2, 25 ] ] [ 'op', 'N+', [ 4.25, -0.002, 1.0 ] ] [ 'op', 'N*', [ 69.3, 15 * 2 ** 6, 49/23 ] ] [ 'op', '∪', [ :Set( Set.new( 1, 3, 5 ) ), :Set( Set.new( 4, 5, 6 ) ), :Set( Set.new( 0, 9 ) ) ] ] [ 'op', '∩', [ :Set( Set.new( 1, 3, 5, 7, 9 ) ), :Set( Set.new( 3, 4, 5, 6, 7, 8 ) ), :Set( Set.new( 2, 5, 9 ) ) ] ] =head2 Simple Non-commutative N-adic Infix Reduction Operators A C node has 2-N main op args, each of which is an C node. Examples: [ 'op', '[<=>]', [ Order::Same, Order::Increase, Order::Decrease ] ] [ 'op', 'B~', [ Blob.new( 16 => 'DEAD' ), Blob.new( 2 => '10001101' ), Blob.new( 16 => 'BEEF' ) ] ] [ 'op', 'T~', [ 'hello', ' ', 'world' ] ] [ 'op', 'A~', [ :Array[24, 52], :Array[-9], :Array[0, 11, 24, 7] ] ] [ 'op', '//', [ ['$','a'], ['$','b'], 42 ] ] [ 'op', '//d', [ ['$','a'], ['$','b'], :type-ref ] ] =head2 Simple Symmetric Dyadic Infix Operators A C node has exactly 2 main op args, each of which is an C node; which function arguments get which main op args isn't significant. Examples: [ 'op', '=', [ ['$','foo'], ['$','bar'] ] ] [ 'op', '≠', [ ['$','foo'], ['$','bar'] ] ] [ 'op', 'nand', [ Bool::False, Bool::True ] ] [ 'op', 'I|-|', [ 15, 17 ] ] [ 'op', 'N|-|', [ 7.5, 9.0 ] ] =head2 Simple Non-symmetric Dyadic Infix Operators A C node has exactly 2 main op args, each of which is an C node; the first and second main op args are C and C, respectively. Examples: [ 'op', 'isa', [ ['$','bar'], :type-ref ] ] [ 'op', '!isa', [ ['$','bar'], :type-ref ] ] [ 'op', 'as', [ ['$','scalar'], :type-ref ] ] [ 'op', 'asserting', [['$','int'], [ 'op', '≠', [['$','int'], 0] ]] ] [ 'op', 'implies', [ Bool::True, Bool::False ] ] [ 'op', 'I-', [ 34, 21 ] ] [ 'op', 'I/', [ 5, 3 ] ] [ 'op', '%', [ 5, 3 ] ] [ 'op', 'I^', [ 2, 63 ] ] [ 'op', 'N-', [ 9.2, 0.1 ] ] [ 'op', 'N/', [ :2<101.01>, :2<11.0> ] ] [ 'op', 'Tx', [ '-', 80 ] ] [ 'op', '∖', [:Set(Set.new( 8, 4, 6, 7 )), :Set(Set.new( 9, 0, 7 ))] ] [ 'op', '÷', [ :Relation( => Set.new( [ 5, 6 ], [ 3, 6 ] ) ), :Relation( Set.new( { y => 6 } ) ) ] ] =head2 Simple Monadic Prefix Operators A C node has exactly 1 main op arg, which is an C node. Examples: [ 'op', 'd', :type-ref ] [ 'op', 'not', Bool::True ] [ 'op', 'I||', -23 ] [ 'op', 'N||', -4.59 ] [ 'op', 'R#', :Set(Set.new( 5, -1, 2 )) ] [ 'op', 't', [['$','relvar']] ] [ 'op', 'r', [['$','tupvar']] ] [ 'op', 's', [[ 'op', 'N+', [[ 'op', 'v', ['$','a'] ], [ 'op', 'v', ['$','b'] ]] ]] ] =head2 Simple Monadic Postfix Operators A C node has exactly 1 main op arg, which is an C node. Examples: [ 'op', '++', 13 ] [ 'op', '--', 4 ] [ 'op', 'I!', 5 ] =head2 Simple Postcircumfix Operators A C node has exactly 2-3 main op args, where the first is an C node that defines the primary input value for the operator and the other 1-2 provide attribute names that customize the operation. Note that for the C<[]> op, the C, C, C are collectively the 2nd main op arg which is an C node payload that defines an C. Examples: [ 'op', '.${}', [['$','birthday'], 'date', 'day'] ] [ 'op', '.%{}', [['$','pt'], 'city'] ] [ 'op', '%{<-}', [['$','pt'], {pnum=>'pno', locale=>'city'}] ] [ 'op', '@{<-}', [['$','pr'], {pnum=>'pno', locale=>'city'}] ] [ 'op', '${}', [['$','birthday'], 'date', ['year','month']] ] [ 'op', '%{}', [['$','pt'], ['color','city']] ] [ 'op', '@{}', [['$','pr'], ['color','city']] ] [ 'op', '%{}', [['$','pt'], []] ] # null projection # [ 'op', '@{}', [['$','pr'], []] ] # null projection # [ 'op', '${!}', [['$','rnd_rule'], ['round_meth']] ] # radix,min_exp # [ 'op', '%{!}', [['$','pt'], ['pno','pname','weight']] ] [ 'op', '@{!}', [['$','pr'], ['pno','pname','weight']] ] [ 'op', '%{%<-}', [['$','person'], 'name', ['fname','lname']] ] [ 'op', '@{%<-}', [['$','people'], 'name', ['fname','lname']] ] [ 'op', '%{%<-!}', [['$','person'],'all_but_name',['fname','lname']] ] [ 'op', '@{%<-!}', [['$','people'],'all_but_name',['fname','lname']] ] [ 'op', '%{<-%}', [['$','person'], ['fname','lname'], 'name'] ] [ 'op', '@{<-%}', [['$','people'], ['fname','lname'], 'name'] ] [ 'op', '@{@<-}', [['$','orders'], 'vendors', ['vendor']] ] [ 'op', '@{@<-!}', [['$','orders'], 'all_but_vendors', ['vendor']] ] [ 'op', '@{<-@}', [['$','orders'], ['vendor'], 'vendors'] ] [ 'op', '@{#@<-!}', [['$','people'], 'count_per_age_ctry', ['age','ctry']] ] [ 'op', '.[]', [['$','ary'], 3] ] [ 'op', '[]', [['$','ary'], 10..14] ] =head2 Rational Operators That Do Rounding A C node has exactly 2-3 main op args, each of which is an C node that defines an input value for the operator. When there are 2 main op args, the first and second args are C and C, respectively. When there are 3 main op args, the first, second and third args are C, C and C, respectively. Examples: [ 'op', 'round', [['$','foo'], :RatRoundRule[10,-2,'half_even']] ] [ 'op', 'N^', [ 2.0, 0.5, :RatRoundRule[2,-7,'to_zero'] ] ] [ 'op', 'log', [ 309.1, 5.4, :RatRoundRule[10,-4,'half_up'] ] ] [ 'op', 'e^', [ 6.3, :RatRoundRule[10,-6,'to_ceiling'] ] ] [ 'op', 'log-e', [ 17.0, :RatRoundRule[3,-5,'to_floor'] ] ] =head2 Order Comparison Operators An C node has exactly 2 or 3 or 2-N main op args, depending on the op, each of which is an C node. When the op requires exactly 2 main op args, the first and second args are C and C, respectively. When the op requires exactly 2 main op args, the first, second and third args are C, C, and C, respectively. When the op is N-adic, requiring 2-N main op args, then the order of the main op args isn't significant. Note that for an N-adic op, the I
may alternately be given as a Perl C rather than a Perl C. Details on the extra op args are pending. Examples (for now sans any use of extra op args, which are atypical): [ 'op', '<=>', [ ['$','foo'], ['$','bar'] ] ] [ 'op', 'min', [ ['$','a'], ['$','b'], ['$','c'] ] ] [ 'op', 'max', [ ['$','a'], ['$','b'], ['$','c'] ] ] [ 'op', '<', [ ['$','foo'], ['$','bar'] ] ] [ 'op', '>', [ ['$','foo'], ['$','bar'] ] ] [ 'op', '≤', [ ['$','foo'], ['$','bar'] ] ] [ 'op', '≥', [ ['$','foo'], ['$','bar'] ] ] [ 'op', 'I∈', [ ['$','a'], 1..5 ] ] [ 'op', '≤≤', [ ['$','min'], ['$','foo'], ['$','max'] ] ] [ 'op', '≤<', [ ['$','min'], ['$','foo'], ['$','max'] ] ] [ 'op', '!<≤', [ ['$','min'], ['$','foo'], ['$','max'] ] ] [ 'op', '!<<', [ ['$','min'], ['$','foo'], ['$','max'] ] ] =head1 SEE ALSO Go to L for the majority of distribution-internal references, and L for the majority of distribution-external references. =head1 AUTHOR Darren Duncan (C) =head1 LICENSE AND COPYRIGHT This file is part of the formal specification of the Muldis D language. Muldis D is Copyright © 2002-2009, Muldis Data Systems, Inc. See the LICENSE AND COPYRIGHT of L for details. =head1 TRADEMARK POLICY The TRADEMARK POLICY in L applies to this file too. =head1 ACKNOWLEDGEMENTS The ACKNOWLEDGEMENTS in L apply to this file too. =cut