Variadic function: Difference between revisions

Content added Content deleted
Line 21: Line 21:
''However'' a flexible array of tagged types (union) <u>is</u> permitted. This effectively
''However'' a flexible array of tagged types (union) <u>is</u> permitted. This effectively
allows the passing of strongly typed variable arguments to procedures.
allows the passing of strongly typed variable arguments to procedures.
MODE STRINT = UNION(STRING, INT, PROC(REF FILE)VOID, VOID);
main:(
PROC print strint = (FLEX[]STRINT argv)VOID: (
MODE STRINT = UNION(STRING, INT, PROC(REF FILE)VOID);
PROC print strint = (FLEX[]STRINT argv)VOID: (
FOR i TO UPB argv DO
FOR i TO UPB argv DO
CASE argv[i] IN
CASE argv[i] IN
(INT i):printf(($d$,i)),
(INT i):printf(($x1d$,i)),
(STRING s):print(s),
(STRING s):printf(($xg$,s)),
(PROC(REF FILE)VOID f):f(stand out),
(PROC(REF FILE)VOID f):f(stand out)
(VOID):print(error char) # print a "*" #
ESAC
ESAC;
IF i NE UPB argv THEN print((space)) FI
OD
);
OD
);
print strint((new page,"Mary","had",1,"little","lamb",new line))
print strint((new page, "Mary", "had", 1, "little", EMPTY, "...", new line))
)
Output:
Output:
<newpage>
<newpage>
Mary had 1 little lamb
Mary had 1 little * ...
Also note that EMPTY (of type VOID) can be used to indicate missing or optional arguments.

'''ALGOL 68''' does not have anything similar the keyword argument found in python.


=={{header|Common Lisp}}==
=={{header|Common Lisp}}==