Function prototype: Difference between revisions
Content added Content deleted
Line 61: | Line 61: | ||
N := Pull; |
N := Pull; |
||
end Main;</lang> |
end Main;</lang> |
||
=={{header|ALGOL 68}}== |
|||
{{works with|ALGOL 68|Revision 1.}} |
|||
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.8 algol68g-2.8].}} |
|||
{{works with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d]}} |
|||
'''File: Function_prototype.a68'''<lang algol68>#!/usr/bin/a68g --script # |
|||
# -*- coding: utf-8 -*- # |
|||
# An explanation of any placement restrictions for prototype declarations # |
|||
PROC VOID no args; # Declare a function with no argument that returns an INTeger # |
|||
PROC (INT #a#,INT #b#)VOID two args; # Declare a function with two arguments that returns an INTeger # |
|||
MODE VARARGS = UNION(INT,REAL,COMPL); |
|||
PROC ([]VARARGS)VOID var args; # An empty parameter list can be used to declare a function that accepts varargs # |
|||
PROC (INT, []VARARGS)VOID at least one args; # One mandatory INTeger argument followed by varargs # |
|||
MODE OPTINT = UNION(VOID,INT), OPTSTRING=UNION(VOID,STRING); # a function that utilizes optional arguments # |
|||
PROC (OPTINT, OPTSTRING)VOID optional arguments; |
|||
# A prototype declaration for a function that utilizes named parameters # |
|||
MODE KWNAME = STRUCT(STRING name), |
|||
KWSPECIES = STRUCT(STRING species), |
|||
KWBREED = STRUCT(STRING breed), |
|||
OWNER=STRUCT(STRING first name, middle name, last name); |
|||
# due to the "Yoneda ambiguity" simple arguments must have an unique operator defined # |
|||
OP NAME = (STRING name)KWNAME: (KWNAME opt; name OF opt := name; opt), |
|||
SPECIES = (STRING species)KWSPECIES: (KWSPECIES opt; species OF opt := species; opt), |
|||
BREED = (STRING breed)KWBREED: (KWBREED opt; breed OF opt := breed; opt); |
|||
PROC ([]UNION(KWNAME,KWSPECIES,KWBREED,OWNER) #options#)VOID print pet; |
|||
# subroutines, and fuctions are procedures, so have the same prototype declarations # |
|||
# An explanation and example of any special forms of prototyping not covered by the above: # |
|||
COMMENT |
|||
If a function has no arguments, eg f, |
|||
then it is not requied to pass it a "vacuum()" to call it, eg "f()" not correct! |
|||
Rather is can be called without the () vacuum. eg "f" |
|||
A GOTO "label" is equivalent to "PROC VOID label". |
|||
END COMMENT |
|||
SKIP</lang> |
|||
=={{header|Aime}}== |
=={{header|Aime}}== |