This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -1,4 +1,4 @@
* Multiply in COBOL
* Multiply in COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. myTest.

View file

@ -14,9 +14,7 @@ T multiply2(T)(T a, T b) {
}
// Compile-time multiplication can also be done using templates:
template multiply3(int a, int b) {
enum multiply3 = a * b;
}
enum multiply3(int a, int b) = a * b;
pragma(msg, multiply3!(2, 3)); // Prints "6" during compilation.

View file

@ -1 +1 @@
multiply = (*)
multiply x y = x * y

View file

@ -1 +1 @@
multiply = \ x y -> x*y
multiply = (*)

View file

@ -0,0 +1 @@
multiply = \ x y -> x*y

View file

@ -0,0 +1 @@
f(a, b):= a*b;

View file

@ -0,0 +1,3 @@
% Module ceremony elided...
:- func multiply(integer, integer) = integer.
multiply(A, B) = A * B.

View file

@ -0,0 +1,5 @@
public Multiply (a : int, b : int) : int // this is either a class or module method
{
def multiply(a, b) { return a * b } // this is a local function, can take advantage of type inference
return multiply(a, b)
}

View file

@ -0,0 +1,3 @@
function multiply returns dec (a as dec , b as dec ):
return a * b .
end.

View file

@ -0,0 +1 @@
multiply(A, B, P) :- P is A * B.

View file

@ -0,0 +1,3 @@
go :-
multiply(5, 2, P),
format("The product is ~d.~n", [P]).

View file

@ -0,0 +1,3 @@
test_multiply :-
multiply(5, 2, 10), % this will pass
multiply(3, 4, 11). % this will not pass

View file

@ -0,0 +1,6 @@
:- use_module(library(function_expansion)).
user:function_expansion(multiply(A, B), P, P is A * B). % "function" definition
go :-
format("The product is ~d.~n", [multiply(5, 2)]).

View file

@ -0,0 +1,3 @@
go :-
A is 5*2,
format('The product is ~d.~n', [A]).