Changeset bb20aa6


Ignore:
Timestamp:
Jul 26, 2024, 7:01:17 AM (2 hours ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Parents:
fd4df379
Message:

small updates to the default/named parameter section

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    rfd4df379 rbb20aa6  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Thu Jul 25 16:53:43 2024
    14 %% Update Count     : 6945
     13%% Last Modified On : Fri Jul 26 06:56:11 2024
     14%% Update Count     : 6955
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    33263326\subsection{Default}
    33273327
    3328 A default parameter provides the ability to associate a default value with a parameter so it can be optionally specified in the argument list.
     3328A default parameter associates a default value with a parameter so it can be optionally specified in the argument list.
    33293329For example, given the routine prototype:
    33303330\begin{cfa}
     
    33373337\textbf{positional arguments} & \textbf{empty arguments} \\
    33383338\begin{cfa}
    3339 f(); §\C[0.75in]{// rewrite \(\Rightarrow\) f( 1, 2, 3 )}§
    3340 f( 4 ); §\C{// rewrite \(\Rightarrow\) f( 4, 2, 3 )}§
    3341 f( 4, 4 ); §\C{// rewrite \(\Rightarrow\) f( 4, 4, 3 )}§
    3342 f( 4, 4, 4 ); §\C{// rewrite \(\Rightarrow\) f( 4, 4, 4 )}\CRT§
     3339f();                    §\C[0.75in]{// rewrite \(\Rightarrow\) f( 1, 2, 3 )}§
     3340f( 4 );                 §\C{// rewrite \(\Rightarrow\) f( 4, 2, 3 )}§
     3341f( 4, 4 );              §\C{// rewrite \(\Rightarrow\) f( 4, 4, 3 )}§
     3342f( 4, 4, 4 );   §\C{// rewrite \(\Rightarrow\) f( 4, 4, 4 )}\CRT§
    33433343
    33443344
     
    33473347&
    33483348\begin{cfa}
    3349 f( ?, 4, 4 ); §\C[1.0in]{// rewrite \(\Rightarrow\) f( 1, 4, 4 )}§
    3350 f( 4, ?, 4 ); §\C{// rewrite \(\Rightarrow\) f( 4, 2, 4 )}§
    3351 f( 4, 4, ? ); §\C{// rewrite \(\Rightarrow\) f( 4, 4, 3 )}§
    3352 f( 4, ?, ? ); §\C{// rewrite \(\Rightarrow\) f( 4, 2, 3 )}§
    3353 f( ?, 4, ? ); §\C{// rewrite \(\Rightarrow\) f( 1, 4, 3 )}§
    3354 f( ?, ?, 4 ); §\C{// rewrite \(\Rightarrow\) f( 1, 2, 4 )}§
    3355 f( ?, ?, ? ); §\C{// rewrite \(\Rightarrow\) f( 1, 2, 3 )}\CRT§
     3349f( ®?®, 4, 4 );         §\C[1.0in]{// rewrite \(\Rightarrow\) f( 1, 4, 4 )}§
     3350f( 4, ®?®, 4 );         §\C{// rewrite \(\Rightarrow\) f( 4, 2, 4 )}§
     3351f( 4, 4, ®?® );         §\C{// rewrite \(\Rightarrow\) f( 4, 4, 3 )}§
     3352f( 4, ®?®, ®?® );       §\C{// rewrite \(\Rightarrow\) f( 4, 2, 3 )}§
     3353f( ®?®, 4, ®?® );       §\C{// rewrite \(\Rightarrow\) f( 1, 4, 3 )}§
     3354f( ®?®, ®?®, 4 );       §\C{// rewrite \(\Rightarrow\) f( 1, 2, 4 )}§
     3355f( ®?®, ®?®, ®?® );     §\C{// rewrite \(\Rightarrow\) f( 1, 2, 3 )}\CRT§
    33563356\end{cfa}
    33573357\end{tabular}
    33583358\end{cquote}
     3359where the ©?© selects the default value as the argument.
    33593360Here the missing arguments are inserted from the default values in the parameter list.
    33603361The compiler rewrites missing default values into explicit positional arguments.
     
    34063407the number of required overloaded routines is linear in the number of default values, which is unacceptable growth.
    34073408In general, overloading is used over default parameters, if the body of the routine is significantly different.
    3408 Furthermore, overloading cannot handle accessing default arguments in the middle of a positional list, via a missing argument, such as:
    3409 \begin{cfa}
    3410 f( 1, ?, 5 );                                                   §\C{// rewrite \(\Rightarrow\) f( 1, 2, 5 )}§
     3409Furthermore, overloading cannot handle accessing default arguments in the middle of a positional list.
     3410\begin{cfa}
     3411f( 1, ®?®, 5 );                                                 §\C{// rewrite \(\Rightarrow\) f( 1, 2, 5 )}§
    34113412\end{cfa}
    34123413
     
    34493450
    34503451The named parameter is not part of type resolution;
    3451 the type of the expression assigned to the named parameter affects type resolution.
     3452only the type of the expression assigned to the named parameter affects type resolution.
    34523453\begin{cfa}
    34533454int f( int ?i, int ?j );
     
    34803481
    34813482\CFA named and default arguments are backwards compatible with C.
    3482 \Index*[C++]{\CC{}} only supports default arguments;
    3483 \Index*{Ada} supports both named and default arguments.
     3483\Index*[C++]{\CC{}} only supports default parameters;
     3484\Index*{Ada} supports both named and default parameters.
    34843485
    34853486
Note: See TracChangeset for help on using the changeset viewer.