Changeset 9d7a19f


Ignore:
Timestamp:
Jun 23, 2026, 9:09:53 PM (107 minutes ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Parents:
366f5cd
Message:

update Default and Named Parameter section

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/user/user.tex

    r366f5cd r9d7a19f  
    1111%% Created On       : Wed Apr  6 14:53:29 2016
    1212%% Last Modified By : Peter A. Buhr
    13 %% Last Modified On : Mon May  4 12:09:44 2026
    14 %% Update Count     : 7440
     13%% Last Modified On : Tue Jun 23 20:56:16 2026
     14%% Update Count     : 7474
    1515%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1616
     
    36613661allowable calls are:
    36623662\begin{cquote}
    3663 \begin{tabular}{@{}ll@{}}
     3663\begin{tabular}{@{}l@{\hspace{80pt}}l@{}}
    36643664\textbf{positional arguments} & \textbf{empty arguments} \\
    36653665\begin{cfa}
     
    36873687Here the missing arguments are inserted from the default values in the parameter list.
    36883688The compiler rewrites missing default values into explicit positional arguments.
     3689While it is possible to put default parameters before positional, it is always necessary to use the ©?© for ommision.
     3690\begin{cfa}
     3691void f( int x ®= 10®, int y );
     3692f( 4, 4 );
     3693f( ?, 4 )
     3694\end{cfa}
     3695
     3696The parameter default-expression can be evaluated at compile (C) or runtime time (\CC) in the declaration context.
     3697\begin{cfa}
     3698enum { y = 10 };
     3699void f( int x ®= y / 2® );              §\C{// C static declaration-site expression-computation}§
     3700f();                                                    §\C{// rewrite \(\Rightarrow\) f( 5 )}§
     3701int y = 200, z = 100;
     3702void g( int x ®= y / z® );              §\C{// \CFA/\,\CC dynamic declaration-site expression-computation}§
     3703g();                                                    §\C{// rewrite \(\Rightarrow\) g( 2 )}§
     3704\end{cfa}
     3705In \CFA, it is possible to have the default-expression evaluated at the call site using a trait.
     3706\begin{cfa}
     3707forall( | { int y; int z; } )   §\C{// define local trait for h}§
     3708void h( int x = y / z );                §\C{// \CFA dynamic call-site expression-computation}§
     3709void foo() {
     3710        h();                                            §\C{// rewrite using globals \(\Rightarrow\) h( 2 )}§
     3711        int y = 50, z = 5;
     3712        h();                                            §\C{// rewrite using locals \(\Rightarrow\) h( 10 )}§
     3713        y = 25;
     3714        h();                                            §\C{// rewrite using locals \(\Rightarrow\) h( 5 )}§
     3715}
     3716\end{cfa}
     3717Routine ©h©'s trait requires variables ©y© and ©z© in the call environment, which are used to compute the default initialization.
     3718
    36893719The advantages of default values are:
    36903720\begin{itemize}
     
    38083838
    38093839\CFA named and default arguments are backwards compatible with C.
    3810 \Index*[C++]{\CC{}} only supports default parameters;
     3840\Index*[C++]{\CC{}} only supports left to right default parameters;
    38113841\Index*{Ada} supports both named and default parameters.
    38123842
Note: See TracChangeset for help on using the changeset viewer.