Function prototype: Difference between revisions
m
→{{header|Phix}}: added syntax colouring the hard way, phix/basics
MaiconSoft (talk | contribs) (Added Delphi example) |
m (→{{header|Phix}}: added syntax colouring the hard way, phix/basics) |
||
Line 1,186:
=={{header|Phix}}==
{{libheader|Phix/basics}}
Should be identical to the actual definition, but preceded by "forward" and with no body.
<!--<lang Phix>-->
<span style="color: #008080;">forward</span> <span style="color: #008080;">function</span> <span style="color: #000000;">noargs</span><span style="color: #0000FF;">()</span> <span style="color: #000080;font-style:italic;">-- Declare a function with no arguments</span>
<span style="color: #008080;">forward</span> <span style="color: #008080;">procedure</span> <span style="color: #000000;">twoargs</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- Declare a procedure with two arguments</span>
<span style="color: #008080;">forward</span> <span style="color: #008080;">procedure</span> <span style="color: #000000;">twoargs</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000080;font-style:italic;">/*b*/</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- Parameter names are optional in forward (and actual) definitions</span>
<span style="color: #008080;">forward</span> <span style="color: #008080;">function</span> <span style="color: #000000;">anyargs</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- varargs are [best/often] handled as a (single) sequence in Phix</span>
<span style="color: #008080;">forward</span> <span style="color: #008080;">function</span> <span style="color: #000000;">atleastonearg</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">a</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">b</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">...);</span> <span style="color: #000080;font-style:italic;">-- Default makes args optional (== actual defn)</span>
<!--</lang>-->
No special syntax is needed on actual or forward function definitions for named parameters, and calls are identical whether still forward or now fully defined.<br>
Defaults on optional parameters in forward definitions can also be dummy (but type compatible) values should the actual not yet be defined.
|