Function definition: Difference between revisions

Add CLU
(Add BCPL)
(Add CLU)
Line 774:
 
(multiply 2 3 4 5) ; 120</lang>
 
=={{header|CLU}}==
The following is a function that multiplies two integers and ignores any error conditions
(as most examples do).
<lang clu>multiply = proc (a, b: int) returns (int)
return(a * b)
end multiply</lang>
 
The following is a type-parameterized function that wraps the built-in multiplication operator
faithfully, rethrows any exceptions, and works for any type that supports multiplication.
It also shows the complete syntax of a function definition (type parameterization,
signals, and a <code>where</code> clause).
<lang clu>multiply = proc [T: type] (a, b: T) returns (T)
signals (overflow, underflow)
where T has mul: proctype (T, T) returns (T)
signals (overflow, underflow)
return(a * b) resignal overflow, underflow
end multiply</lang>
 
=={{header|COBOL}}==
2,114

edits