Named parameters: Difference between revisions
Content added Content deleted
Drkameleon (talk | contribs) (Added Arturo implementation) |
m (→{{header|Phix}}: added syntax colouring the hard way, phix/basics) |
||
Line 1,193: | Line 1,193: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{libheader|Phix/basics}} |
|||
Phix supports named and optional parameters in a very simple, natural, and intuitive way, erring on the side of caution when faced with any potential ambiguity.<br> |
Phix supports named and optional parameters in a very simple, natural, and intuitive way, erring on the side of caution when faced with any potential ambiguity.<br> |
||
Optional parameters are specified simply by providing a default, any non-defaulted parameters must occur before (to the left of) any defaulted parameters.<br> |
Optional parameters are specified simply by providing a default, any non-defaulted parameters must occur before (to the left of) any defaulted parameters.<br> |
||
Named parameters can be given (when invoking a routine) in any order, but must be grouped together after (to the right of) any non-named parameters.<br> |
Named parameters can be given (when invoking a routine) in any order, but must be grouped together after (to the right of) any non-named parameters.<br> |
||
Note that low-level builtins (those defined using AutoAsm() in psym.e/syminit()) do not support named parameters (maybe one day..), but everything else does. |
Note that low-level builtins (those defined using AutoAsm() in psym.e/syminit()) do not support named parameters (maybe one day..), but everything else does. |
||
<lang Phix>global function timedelta(atom weeks=0, atom days=0, atom hours=0, atom minutes=0, atom seconds=0, atom milliseconds=0, atom microseconds=0) |
|||
<!--<lang Phix>--> |
|||
-- can be invoked as: |
|||
<span style="color: #008080;">global</span> <span style="color: #008080;">function</span> <span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #004080;">atom</span> <span style="color: #000000;">weeks</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">days</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">hours</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">minutes</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">seconds</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">milliseconds</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">microseconds</span><span style="color: #0000FF;">=</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> |
|||
constant fourdays = timedelta(days:=4) |
|||
<span style="color: #000080;font-style:italic;">-- can be invoked as:</span> |
|||
⚫ | |||
<span style="color: #008080;">constant</span> <span style="color: #000000;">fourdays</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">4</span><span style="color: #0000FF;">)</span> |
|||
⚫ | |||
⚫ | |||
constant oneday = timedelta(days=1) -- equivalent to timedelta([weeks:=]iff((equal(days,1)?true:false)) |
|||
⚫ | |||
⚫ | |||
<span style="color: #008080;">constant</span> <span style="color: #000000;">oneday</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #000000;">days</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- equivalent to timedelta([weeks:=]iff((equal(days,1)?true:false)) |
|||
constant shift = timedelta(hours:=hours) -- perfectly valid (param hours:=local hours) |
|||
⚫ | |||
⚫ | |||
<span style="color: #008080;">constant</span> <span style="color: #000000;">shift</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">timedelta</span><span style="color: #0000FF;">(</span><span style="color: #000000;">hours</span><span style="color: #0000FF;">:=</span><span style="color: #000000;">hours</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- perfectly valid (param hours:=local hours) |
|||
⚫ | |||
<!--</lang>--> |
|||
=={{header|PHP}}== |
=={{header|PHP}}== |