Changeset a514fed


Ignore:
Timestamp:
Apr 11, 2025, 6:40:42 PM (6 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
5ad6f0d
Parents:
30548de
Message:

update user documentation

Location:
doc/user
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • doc/user/Makefile

    r30548de ra514fed  
    4646
    4747all : ${DOCUMENT}
     48
     49INSTALLDOCDIR = /u/cforall/public_html/doc
     50install : all ${INSTALLDOCDIR}
     51        cp -f ${DOCUMENT} ${INSTALLDOCDIR}/${DOCUMENT}
    4852
    4953clean :
  • doc/user/user.tex

    r30548de ra514fed  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Fri Jan 17 14:20:39 2025
    14 %% Update Count     : 6971
     13%% Last Modified On : Fri Apr 11 18:33:42 2025
     14%% Update Count     : 7064
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    597597This extension is backwards compatible, matches with the use of underscore in variable names, and appears in \Index*{Ada} and \Index*{Java} 8.
    598598\CC uses the single quote (©'©) as a separator, restricted within a sequence of digits, \eg ©0xaa©©'©©ff©, ©3.141©©'©©592E1©©'©©1©.
    599 However, the drawback of the \CC approach is difficults parsing for IDEs between character and numeric constants, as quotes are no longer balanced (©'x'© and ©3.14©©'©©159©).
     599However, the drawback of the \CC approach is differentiating between character and numeric constants by IDEs, as quotes are no longer balanced (©'x'© and ©3.14©©'©©159©).
    600600
    601601
    602602\section{Exponentiation Operator}
    603603
    604 C, \CC, and Java (and other programming languages) have \emph{no} exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, \ie $x^y$, and instead use a routine, like \Indexc{pow(x,y)}, to perform the exponentiation operation.
    605 \CFA extends the basic operators with the exponentiation operator ©?©\R{©\\©}©?©\index{?\\?@©?@\@?©} and ©?©\R{©\\©}©=?©\index{?\\=?@©@\@=?©}, as in, ©x ©\R{©\\©}© y© and ©x ©\R{©\\©}©= y©, which means $x^y$ and $x \leftarrow x^y$.
     604Exponentiation, $x^y$, means raise $x$ to the $y$th power.
     605When $y$ is a positive integer, exponentiation corresponds to $\prod_{i=1}^{y} x$.
     606
     607C, \CC, Java and other programming languages have no exponentiation operator\index{exponentiation!operator}\index{operator!exponentiation}, using a routine like \Indexc{pow( x, y )} instead.
     608Ada, Haskell, Python and other programming languages often use operators ©^© or ©**© for exponentiation.
     609However, neither of these operators work in C as ©^© means exclusive-or and ©**© means double dereference.
     610Furthermore, using a routine for exponentiation does not match with mathematical expectation, \ie ©-x**-y© becomes ©pow( -x, -y )©.
     611
     612\CFA extends the basic C operator set with symbol \R{©\\©} (backslash) as the exponentiation operator, represented by routines ©?©\R{©\\©}©?©\index{?\\?@©?@\@?©} and ©?©\R{©\\©}©=?©\index{?\\=?@©@\@=?©}, respectively.
     613For example, ©x ©\R{©\\©}© y© and ©x ©\R{©\\©}©= y© mean $x^y$ and $x \leftarrow x^y$.
    606614The priority of the exponentiation operator is between the cast and multiplicative operators, so ©-f(x) \ -g(y)© is parenthesized as ©(-f(x)) \ (-g(y))©.
    607 
    608 There are exponentiation operators for integral and floating types, including the builtin \Index{complex} types.
    609 Integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication ($O(\log y)$ or shifting if the exponent is 2).
     615The C ©pow© routines continues to be available for backwards compatibility.
     616
     617Exponentiation is overloaded for integral and floating types, including the builtin \Index{complex} types.
     618Integral exponentiation\index{exponentiation!unsigned integral} is performed with repeated multiplication ($O(\log y)$ or shifting if the exponent is 2.
    610619Overflow for a large exponent or negative exponent returns zero.
    611620Floating exponentiation\index{exponentiation!floating} is performed using \Index{logarithm}s\index{exponentiation!logarithm}, so the exponent cannot be negative.
     
    615624\end{cfa}
    616625Note, ©5 \ 32© and ©5L \ 64© overflow, and ©-4 \ -3© is a fraction but stored in an integer so all three computations generate an integral zero.
    617 Because exponentiation has higher priority than ©+©, parenthesis are necessary for exponentiation of \Index{complex constant}s or the expression is parsed as ©1.0f+©\R{©(©}©2.0fi \ 3.0f©\R{©)©}©+2.0fi©, requiring \R{©(©}©1.0f+2.0fi©\R{©)©}© \ ©\R{©(©}©3.0f+2.0fi©\R{©)©}.
     626Because exponentiation has higher priority than ©+©, parenthesis are required for exponentiation of \Index{complex constant}s or the expression is parsed as ©1.0f+©\R{©(©}©2.0fi \ 3.0f©\R{©)©}©+2.0fi©, requiring \R{©(©}©1.0f+2.0fi©\R{©)©}© \ ©\R{©(©}©3.0f+2.0fi©\R{©)©}.
    618627
    619628The exponentiation operator is available for all the basic types, but for user-defined types, only the integral-computation version is available.
     
    624633T ?®\®?( T ep, unsigned long int y );
    625634\end{cfa}
    626 A user type ©T© must define one (©1©), and multiplication (©*©) \see{\VRef{s:Operator}}.
     635A user type ©T© must define one (©1©) and multiplication (©*©) \see{\VRef{s:Operator}}.
    627636
    628637
     
    638647Declarations in the \Indexc{do}-©while© condition are not useful because they appear after the loop body.}
    639648\begin{cfa}
    640 if ( ®int x = f()® ) ...                        §\C{// x != 0}§
     649if ( ®int x = f()® ) ...                        §\C[2.75in]{// x != 0}§
    641650if ( ®int x = f(), y = g()® ) ...       §\C{// x != 0 \&\& y != 0}§
    642651if ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
     
    646655while ( ®int x = f(), y = g()® ) ... §\C{// x != 0 \&\& y != 0}§
    647656while ( ®int x = f(), y = g(); x < y® ) ... §\C{// relational expression}§
    648 while ( ®struct S { int i; } x = { f() }; x.i < 4® ) ... §\C{// relational expression}§
     657while ( ®struct S { int i; } x = { f() }; x.i < 4® ) ... §\C{// relational expression}\CRT§
    649658\end{cfa}
    650659Unless a relational expression is specified, each variable is compared not equal to 0, which is the standard semantics for the ©if©/©while© expression, and the results are combined using the logical \Indexc{&&} operator.
     
    692701\end{tabular}
    693702\end{cquote}
    694 In addition, subranges are allowed to specify a contiguous set of case values.
     703In addition, inclusive ranges are allowed using symbol ©~© to specify a contiguous set of case values, both positive and negative.
    695704\begin{cquote}
    696 \begin{tabular}{@{}l@{\hspace{3em}}l@{\hspace{2em}}l@{\hspace{2em}}l@{}}
    697 \multicolumn{1}{c@{\hspace{3em}}}{\textbf{C}}   & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{\CFA}}      & \multicolumn{1}{c@{\hspace{2em}}}{\textbf{©gcc©}}     \\
     705\setlength{\tabcolsep}{15pt}
     706\begin{tabular}{@{}llll@{}}
     707\multicolumn{1}{c}{\textbf{C}}  & \multicolumn{1}{c}{\textbf{\CFA}}     & \multicolumn{1}{c}{\textbf{©gcc©}}    \\
    698708\begin{cfa}
    699709switch ( i ) {
    700   case 1: case 2: case 3: case 4:
     710  case -4: case -3: case -2: case -1:
    701711        ...
    702712  case 10: case 11: case 12: case 13:
     
    707717\begin{cfa}
    708718switch ( i ) {
    709   case ®1~4
     719  case ®-4~-1
    710720        ...
    711721  case ®10~13:®
     
    716726\begin{cfa}
    717727switch ( i ) {
    718   case 1§\R{\textvisiblespace}§®...®4:
     728  case -4§\R{\textvisiblespace}§®...®-1:
    719729        ...
    720730  case 10§\R{\textvisiblespace}§®...®13:
     
    725735\begin{cfa}
    726736
    727 // 1, 2, 3, 4
     737// -4, -3, -2, -1
    728738
    729739// 10, 11, 12, 13
     
    733743\end{tabular}
    734744\end{cquote}
    735 While ©gcc© has the same range mechanism, it has an awkward syntax, ©2©\R{\textvisiblespace}©...42©, because a space is required after a number, otherwise the period is a decimal point.
     745While ©gcc© has the same range mechanism, it has an awkward syntax, ©2©\R{\textvisiblespace}©...42©, because a space is required after the lower bound, otherwise the period is a decimal point.
    736746
    737747\CFA also allows lists of subranges.
    738748\begin{cfa}
    739 case ®1~5, 12~21, 35~42®:
     749case ®-5~-1, 12~21, 35~42®:
    740750\end{cfa}
    741751
     
    807817
    808818While fall-through itself is not a problem, the problem occurs when fall-through is the default, as this semantics is unintuitive for many programmers and is different from most programming languages with a ©switch© statement.
    809 Hence, default fall-through semantics results in programming errors as programmers often \emph{forget} the ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through.
     819Hence, default fall-through semantics results in errors as programmers often \emph{forget} the ©break© statement at the end of a ©case© clause, resulting in inadvertent fall-through.
    810820
    811821\item
     
    820830        } // if
    821831\end{cfa}
    822 This usage branches into control structures, which is known to cause both comprehension and technical difficulties.
     832This usage branches into control structures, which causes comprehension and technical difficulties.
    823833The comprehension problem results from the inability to determine how control reaches a particular point due to the number of branches leading to it.
    824834The technical problem results from the inability to ensure declaration and initialization of variables when blocks are not entered at the beginning.
    825835There are few arguments for this kind of control flow, and therefore, there is a strong impetus to eliminate it.
    826 This C idiom is known as ``\Index*{Duff's device}''~\cite{Duff83}, from this example:
     836This C idiom is known as ``\Index*{Duff's device}''~\cite{Duff83}, from the example:
    827837\begin{cfa}
    828838register int n = (count + 7) / 8;
     
    10561066That is, the optional low set value, the optional scan direction (ascending/descending), the (possibly) required range character, the optional include last-scan value, the required high set value, and the optional range character and step value.
    10571067\R{Warning}: the regular expression allows the form ©~H©, but this syntax has a preexisting meaning in C: complement the bits of ©H©, \eg ©for ( ~5 )© meaning ©for ( -6 )©, as ©-6© is the complement of ©5©.
    1058 This anomaly is unlikely to cause problems because programers will write the shorter ©for ( 5 )©.
     1068This anomaly is unlikely to cause problems because programers should write the shorter ©for ( 5 )©.
    10591069
    10601070The previous ©for© loops have an anonymous loop index in which the range iteration is computed.
     
    29482958Specifically, the inheritance relationship for ©Name©s is:
    29492959\begin{cfa}
    2950 Name $\(\subseteq\)$ Name2 $\(\subseteq\)$ Name3 $\(\subseteq\)$ const char * // enum type of Name
     2960Name §\(\subseteq\)§ Name2 §\(\subseteq\)§ Name3 §\(\subseteq\)§ const char * // enum type of Name
    29512961\end{cfa}
    29522962Hence, given
     
    39904000\subsection{Casting}
    39914001
    3992 In C, the cast operator is used to explicitly convert between types.
     4002Casting is a mechanism to explicitly change the type and representation of a value.
     4003If the type and representation are changed, the cast is a \newterm{conversion};
     4004if only the type is changed but not the value representation, the cast is a \newterm{coercion}.
     4005For example, in:
     4006\begin{cfa}
     4007int i, *ip;
     4008double d;
     4009d = (double)i; §\C{// conversion}§
     4010ip = (int *)d; §\C{// coercion}§
     4011\end{cfa}
     4012the conversion cast implicitly runs code that transforms an integer representation into the best-effort floating-point representation.
     4013Another conversion case exists in object-oriented programming-languages to walk an inheritence hierarchy looking for specific types along the path.
     4014The coercion cast lies about the representation of the value as the integer point is actually pointing at a floating-point value;
     4015indirect operations through ©ip© are as odds with direct operations on ©d©.
     4016In general, coercion casts are only necessary for systems programming, like building a memory allocator, where raw storage is typed and returned for use by the language or the runtime system to access storage in special ways.
     4017
     4018For coercion casts, there are often fine-grain variations to precisely expalin how the storage is to be typed.
     4019\CC and \CFA have a number specialized casts., there are four types of explicit casting operators.
     4020\begin{enumerate}
     4021\item
     4022©dynamic_cast© Used for conversion of polymorphic types.
     4023\item
     4024©static_cast© Used for conversion of nonpolymorphic types.
     4025\item
     4026©const_cast© Used to remove the type qualifiers and possibly attributes.
     4027\item
     4028©reinterpret_cast© Used for simple reinterpretation of bits.
     4029\end{enumerate}
     4030
     4031\begin{cfa}
     4032        '(' type_no_function ')' cast_expression
     4033        '(' aggregate_control '&' ')' cast_expression           // CFA
     4034        '(' aggregate_control '*' ')' cast_expression           // CFA
     4035        '(' VIRTUAL ')' cast_expression                                 // CFA
     4036        '(' VIRTUAL type_no_function ')' cast_expression        // CFA
     4037        '(' RETURN type_no_function ')' cast_expression // CFA (ASCRIPTION)
     4038        '(' COERCE type_no_function ')' cast_expression // CFA (COERCION)
     4039        '(' qualifier_cast_list ')' cast_expression             // CFA, (modify CVs of cast_expression)
     4040\end{cfa}
     4041
     4042
     4043Specialized Casts
     4044
     4045There is some use in Cforall for cast operators with semantics other than the standard C cast.
     4046To make these alternate casts look like the familiar C cast, this proposal follows the example of the virtual proposal's virtual cast `(virtual Foo)x` and uses an added (pseudo-)keyword inside the cast parens.
     4047
     4048C (Conversion) Cast
     4049
     4050The standard C cast performs conversions, transformations between types which may make a new object with a different in-memory representation.
     4051Cforall maintains these semantics in a backward-compatible way while accounting for name overloading by choosing the lowest-cost interpretation of the argument expression which is convertable to the target type, breaking ties by conversion cost.
     4052
     4053The C cast must be maintained for backward-compatibility, and developing a second cast operator with identical semantics seems an undesirable multiplication of language features, but `(convert Foo)` or `(to Foo)` would be reasonable options for a keyword.
     4054An alternate semantics for a Cforall-specific conversion cast would be to choose the cast interpretation with the lowest sum of conversion cost and interpretation cost, which aligns better with Cforall function call resolution algorithm.
     4055
     4056Ascription Cast
     4057
     4058Using casts in Cforall for type ascription ("select the interpretation of this type") works by the conversion-cost tiebreaker behaviour of the cast operator.
     4059However, the ascription interpretation of casts is prioritized less than the conversion interpretation of casts, sometimes resulting in some surprising results, as in the following example:
     4060\begin{cfa}
     4061int f(int);      // f1
     4062int f(double);   // f2
     4063int g(int);      // g1
     4064double g(long);  // g2
     4065
     4066f((double)42);   // selects f2 by cast on argument
     4067(double)g(42);   // does NOT select g2, argument conversion cost results in g1
     4068\end{cfa}
     4069An ascription cast which reversed the priorities of the C cast would be useful for selecting expressions based on their return type; a reversal of the priorities of the standard C cast would work for this (that is, select the lowest-cost conversion, breaking ties based on argument cost).
     4070A plausible stricter semantics would be to select the cheapest interpretation with a zero-cost conversion to the target type, reporting a compiler error otherwise (this semantics would make ascription a solely compile-time phenomenon, rather than relying on possible runtime conversions).
     4071A resonable keyword would be `(as Foo)`, which is short, evocative, and echos "ascription"; `(return Foo)` would not introduce new keywords, and speaks to its use in return-type selection, as in the following corrected version of the example above:
     4072\begin{cfa}
     4073(as double)g(42);  // selects g2, as expected (under either presented ascription semantics)
     4074\end{cfa}
     4075
     4076Coercion Cast
     4077
     4078Some of the explict conversions in C are defined to be a coercions (reinterpret the bits of this value as another type).
     4079Use of coercions often relies on non-standard implementation details of the provided environment, and as such is discouraged, but is sometimes necessary.
     4080Since all explicit pointer casts in C are coercions, any lvalue ©x© in C/Cforall can be coerced with the pattern ©*(Foo*)&x©, but this is complex and doesn't extend to rvalues.
     4081\begin{cfa}
     4082int i = 5;
     4083double d = *(double*)&i; // value coercion
     4084printf( "%g %g %x\n", d, *(double *)&i, *(int *)&d );
     4085
     4086int i = 5; // pointer coercion
     4087double d = *(double*)&i; // value coercion
     4088\end{cfa}
     4089A dedicated coercion cast would solve these issues; ©(reinterpret Foo)© (from C++), ©(transmute Foo)© (from Rust), or ©(coerce Foo)© would be reasonable keywords.
     4090
     4091Qualifier Cast
     4092
     4093A more restricted (and thus safer) form of coercion is modifiying the qualifiers of a type; C++ has ©const_cast© for this purpose, and a similar feature would be useful for Cforall.
     4094With regard to syntax, ©(requalify const Foo)©/©(requalify Foo)© to add/strip ©const© would echo C++, but given that the vast majority of uses are stripping const-qualfiers, ©(non const)© would be shorter, clearer, easily searchable, and not require the programmer to exactly match the argument type.
     4095In this syntax, coercion casts could be used to add qualifiers, or another cast type (say ©(with const)©) could be introduced to add qualfiers.
     4096
     4097Virtual Cast
     4098see virtual.txt; semantics equivalent to C++ dynamic cast
     4099
     4100
    39934101In \CFA, the cast operator has a secondary use, which is type ascription, since it forces the expression resolution algorithm to choose the lowest cost conversion to the target type.
    39944102That is, a cast can be used to select the type of an expression when it is ambiguous, as in the call to an overloaded function.
     
    40374145If ©g© is free of side effects, this is equivalent to ©[(int)(g().0), (int)(g().1.0), (int)(g().2)]©.
    40384146Since ©void© is effectively a 0-element tuple, (3) discards the first and third return values, which is effectively equivalent to ©[(int)(g().1.0), (int)(g().1.1)]©).
    4039 % will this always hold true? probably, as constructors should give all of the conversion power we need. if casts become function calls, what would they look like? would need a way to specify the target type, which seems awkward. Also, C++ basically only has this because classes are closed to extension, while we don't have that problem (can have floating constructors for any type).
     4147% will this always hold true? probably, as constructors should give all of the conversion power we need.
     4148if casts become function calls, what would they look like? would need a way to specify the target type, which seems awkward.
     4149Also, C++ basically only has this because classes are closed to extension, while we don't have that problem (can have floating constructors for any type).
    40404150Note that a cast is not a function call in \CFA, so flattening and structuring conversions do not occur for cast expressions.
    40414151As such, (4) is invalid because the cast target type contains 4 components, while the source type contains only 3.
     
    41934303g( w2 );
    41944304\end{cfa}
    4195 Note, in all cases 3 arguments are supplied even though the syntax may appear to supply less than 3. As mentioned, a
    4196 tuple does not have structure like a record; a tuple is simply converted into a list of components.
     4305Note, in all cases 3 arguments are supplied even though the syntax may appear to supply less than 3.
     4306As mentioned, a tuple does not have structure like a record; a tuple is simply converted into a list of components.
    41974307\begin{rationale}
    41984308The present implementation of \CFA does not support nested routine calls when the inner routine returns multiple values; \ie a statement such as ©g( f() )© is not supported.
     
    53005410
    53015411\item
    5302 \Indexc{quoted}( ©char & ch©, ©const char Ldelimiter = '\''©, ©const char Rdelimiter = '\0'© )\index{manipulator!quoted@©quoted©}
     5412\Indexc{quote}( ©char & ch©, ©const char Ldelimiter = '\''©, ©const char Rdelimiter = '\0'© )\index{manipulator!quote@©quote©}
    53035413consumes the string ©"LCR"©, where ©L© is the left ©delimiter© character, ©C© is the value in ©ch©, and ©R© is the right delimiter character, which skips whitespace, consumes and ignores the left delimiter, reads a single character into ©ch©, and consumes and ignores the right delimiter (3 characters).
    53045414If the delimit character is omitted, it defaults to ©'\''© (single quote).
    53055415\begin{cfa}[belowskip=0pt]
    53065416char ch;
    5307 sin | quoted( ch );   sin | quoted( ch, '"' );   sin | quoted( ch, '[', ']' );
     5417sin | quote( ch );   sin | quote( ch, '"' );   sin | quote( ch, '[', ']' );
    53085418\end{cfa}
    53095419\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    53135423\item
    53145424\begin{sloppypar}
    5315 \Indexc{quoted}( $wdi\ manipulator$, ©const char Ldelimiter = '\''©, ©const char Rdelimiter = '\0'© )\index{manipulator!quoted@©quoted©}
     5425\Indexc{quote}( $wdi\ manipulator$, ©const char Ldelimiter = '\''©, ©const char Rdelimiter = '\0'© )\index{manipulator!quote@©quote©}
    53165426consumes the scanset ©"L[^R]R"©, where ©L© is the left ©delimiter© character and ©R© is the right delimiter character, which skips whitespace, consumes and ignores the left delimiter, reads characters until the right-delimiter into the string variable (null terminated), and consumes and ignores the right delimiter.
    5317 If the delimit character is omitted, it defaults to ©'\''© (single quote).
     5427If the delimit character is omitted, it defaults to ©'"'© (double quote).
    53185428\end{sloppypar}
    53195429\begin{cfa}[belowskip=0pt]
    53205430char cs[10];
    5321 sin | quoted( wdi( sizeof(cs), cs ) ); §\C[3in]{// " is the start/end delimiter}§
    5322 sin | quoted( wdi( sizeof(cs), cs ), '\'' ); §\C{// ' is the start/end delimiter}§
    5323 sin | quoted( wdi( sizeof(cs), cs ), '[', ']' ); §\C{// [ is the start and ] is the end delimiter}\CRT§
     5431sin | quote( wdi( sizeof(cs), cs ) ); §\C[3in]{// " is the start/end delimiter}§
     5432sin | quote( wdi( sizeof(cs), cs ), '\'' ); §\C{// ' is the start/end delimiter}§
     5433sin | quote( wdi( sizeof(cs), cs ), '[', ']' ); §\C{// [ is the start and ] is the end delimiter}\CRT§
    53245434\end{cfa}
    53255435\begin{cfa}[showspaces=true]
     
    53575467sin | ignore( d );                                              §\C{// d is unchanged}§
    53585468sin | ignore( cs );                                             §\C{// cs is unchanged, no wdi required}§
    5359 sin | ignore( quoted( wdi( sizeof(cs), cs ) ) ); §\C{// cs is unchanged}§
     5469sin | ignore( quote( wdi( sizeof(cs), cs ) ) ); §\C{// cs is unchanged}§
    53605470\end{cfa}
    53615471\begin{cfa}[showspaces=true,aboveskip=0pt,belowskip=0pt]
     
    57945904In \CFA, as in C, all scalar types can be incremented and
    57955905decremented, which is defined in terms of adding or subtracting 1.
    5796 The operations ©&&©, ©||©, and ©!© can be applied to any scalar arguments and are defined in terms of comparison against 0 (ex. ©(a && b)© becomes ©(a != 0 && b != 0)©).
     5906The operations ©&&©, ©||©, and ©!© can be applied to any scalar arguments and are defined in terms of comparison against 0 (\eg ©(a && b)© becomes ©(a != 0 && b != 0)©).
    57975907
    57985908In C, the integer constants 0 and 1 suffice because the integer promotion rules can convert them to any arithmetic type, and the rules for pointer expressions treat constant expressions evaluating to 0 as a special case.
     
    58005910Defining special constants for a user-defined type is more efficient than defining a conversion to the type from ©bool©.
    58015911
    5802 Why just 0 and 1? Why not other integers? No other integers have special status in C.
    5803 A facility that let programmers declare specific constants..const Rational 12., for instance. would not be much of an improvement.
     5912Why just 0 and 1?
     5913Why not other integers?
     5914No other integers have special status in C.
     5915A facility that let programmers declare specific constants ©const Rational 12©, for instance. would not be much of an improvement.
    58045916Some facility for defining the creation of values of programmer-defined types from arbitrary integer tokens would be needed.
    58055917The complexity of such a feature does not seem worth the gain.
    58065918
    58075919For example, to define the constants for a complex type, the programmer would define the following:
    5808 
    58095920\begin{cfa}
    58105921struct Complex {
     
    65256636For example, container/vector is a valid module name, where container is the parent module name, and vector is the sub-module under container.
    65266637
    6527 Only the interfaces of a module are visible from outside, when the module is imported. export is a type decorator to declare a module interface.
     6638Only the interfaces of a module are visible from outside, when the module is imported, export is a type decorator to declare a module interface.
    65286639A method, a global variable or a type can be declared as a module interface.
    65296640Types defined in a module and referenced by an exported function or a variable must be exported, too.
     
    65586669All of the exported names are visible in the file that imports the module.
    65596670The exported names can be accessed within a namespace based on the module name in the first syntax (ex moduleName.foo).
    6560 If moduleName has several elements separated by '/' to describe a sub-module (ex. import container/vector;), the last element in the moduleName is used as the namespace to access the visible names in that module (ex vector.add(...);).
    6561 The as keyword is used to confine the imported names in a unique namespace (ex. anotherName.foo). anotherName must be a valid identifier (same rules as a variable name) which means it cannot have '/' in it.
     6671If moduleName has several elements separated by '/' to describe a sub-module (\eg import container/vector;), the last element in the moduleName is used as the namespace to access the visible names in that module (ex vector.add(...);).
     6672The as keyword is used to confine the imported names in a unique namespace (\eg anotherName.foo). anotherName must be a valid identifier (same rules as a variable name) which means it cannot have '/' in it.
    65626673Conflicts in namespaces will be reported by the compiler.
    65636674The second method can be used to solve conflicting name problems.
     
    65826693
    65836694Additionally, using the .as. syntax, a user can force the compiler to add the imported names into the current namespace using .as ..With these module rules, the following module definitions and imports can be achieved without any problem.
    6584 
    65856695\begin{cfa}
    65866696module M1;
Note: See TracChangeset for help on using the changeset viewer.