This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,6 @@
A function is a body of code that returns a value. The value returned may depend on arguments provided to the function.
Write a definition of a function called "multiply" that takes two arguments and returns their product.
(Argument types should be chosen so as not to distract from showing how functions are created and values returned).
See also:[[Function prototype]]

View file

@ -0,0 +1,4 @@
---
category:
- Functions and subroutines
note: Basic language learning

View file

@ -0,0 +1 @@
(defun multiply (a b) (* a b))

View file

@ -0,0 +1,4 @@
PROC multiply = ( LONG REAL a, b ) LONG REAL:
(
a * b
)

View file

@ -0,0 +1 @@
multiply ×

View file

@ -0,0 +1,7 @@
function multiply(a, b)
{
return a*b
}
BEGIN {
print multiply(5, 6)
}

View file

@ -0,0 +1,3 @@
function multiply(a:Number, b:Number):Number {
return a * b;
}

View file

@ -0,0 +1 @@
function Multiply (A, B : Float) return Float;

View file

@ -0,0 +1,4 @@
function Multiply (A, B : Float) return Float is
begin
return A * B;
end Multiply;

View file

@ -0,0 +1 @@
function Multiply(A, B: Float) return Float is (A * B);

View file

@ -0,0 +1,3 @@
generic
type Number is digits <>;
function Multiply (A, B : Number) return Number;

View file

@ -0,0 +1,4 @@
function Multiply (A, B : Number) return Number is
begin
return A * B;
end Multiply;

View file

@ -0,0 +1,7 @@
with Multiply;
...
function Multiply_Integer is new Multiply(Number => Integer);
use Multiply_Integer; -- If you must
type My_Integer is Range -100..100;
function Multiply_My_Integer is new Multiply(My_Integer);

View file

@ -0,0 +1,11 @@
PROC my_molt(a,b)
-> other statements if needed... here they are not
ENDPROC a*b -> return value
-> or simplier
PROC molt(a,b) IS a*b
PROC main()
WriteF('\d\n', my_molt(10,20))
ENDPROC

View file

@ -0,0 +1,3 @@
on multiply(a, b)
return a * b
end

View file

@ -0,0 +1,2 @@
10 DEF FN MULTIPLY(P) = P(P) * P(P+1)
20 P(1) = 611 : P(2) = 78 : PRINT FN MULTIPLY(1)

View file

@ -0,0 +1 @@
47658

View file

@ -0,0 +1,2 @@
use std
.: multiply <real a, real b> :. -> real {a * b}

View file

@ -0,0 +1,2 @@
use std
=: multiply <real a> [<real b>...] := -> real {Cgen a (@@1 (Cgen " * " b))}

View file

@ -0,0 +1,5 @@
MsgBox % multiply(10,2)
multiply(multiplicand, multiplier) {
Return (multiplicand * multiplier)
}

View file

@ -0,0 +1,7 @@
#AutoIt Version: 3.2.10.0
$I=11
$J=12
MsgBox(0,"Multiply", $I &" * "& $J &" = " & product($I,$J))
Func product($a,$b)
Return $a * $b
EndFunc

View file

@ -0,0 +1,5 @@
DECLARE FUNCTION multiply% (a AS INTEGER, b AS INTEGER)
FUNCTION multiply% (a AS INTEGER, b AS INTEGER)
multiply = a * b
END FUNCTION

View file

@ -0,0 +1,4 @@
PRINT FNmultiply(6,7)
END
DEF FNmultiply(a,b) = a * b

View file

@ -0,0 +1,4 @@
DEF FNmultiply(a,b)
LOCAL c
c = a * b
= c

View file

@ -0,0 +1,11 @@
@ECHO OFF
SET /A result = 0
CALL :multiply 2 3
ECHO %result%
GOTO :eof
:multiply
SET /A result = %1 * %2
GOTO :eof
:eof

View file

@ -0,0 +1,4 @@
def multiply(x as int, y as int):
return x * y
print multiply(3, 2)

View file

@ -0,0 +1,2 @@
multiply=a b.!arg:(?a.?b)&!a*!b;
out$multiply$(123456789.987654321); { writes 121932631112635269 to standard output }

View file

@ -0,0 +1,3 @@
multiply = { x, y | x * y }
p multiply 3 14 #Prints 42

View file

@ -0,0 +1,4 @@
inline double multiply(double a, double b)
{
return a*b;
}

View file

@ -0,0 +1,5 @@
template<typename Number>
Number multiply(Number a, Number b)
{
return a*b;
}

View file

@ -0,0 +1,4 @@
double multiply(double a, double b)
{
return a * b;
}

View file

@ -0,0 +1 @@
#define MULTIPLY(X, Y) ((X) * (Y))

View file

@ -0,0 +1 @@
x = MULTIPLY(x + z, y);

View file

@ -0,0 +1 @@
x = ((x + z) * (y));

View file

@ -0,0 +1,29 @@
* Multiply in COBOL
IDENTIFICATION DIVISION.
PROGRAM-ID. myTest.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 x PIC 9(3) VALUE 3.
01 y PIC 9(3) VALUE 2.
01 z PIC 9(9).
PROCEDURE DIVISION.
CALL "myMultiply" USING
BY CONTENT x, BY CONTENT y,
BY REFERENCE z.
DISPLAY z.
STOP RUN.
END PROGRAM myTest.
IDENTIFICATION DIVISION.
PROGRAM-ID. myMultiply.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
01 x PIC 9(3).
01 y PIC 9(3).
01 z PIC 9(9).
PROCEDURE DIVISION USING x, y, z.
MULTIPLY x BY y GIVING z.
EXIT PROGRAM.
END PROGRAM myMultiply.

View file

@ -0,0 +1 @@
multiply(x,y) = x * y;

View file

@ -0,0 +1,4 @@
(defn multiply [x y]
(* x y))
(multiply 4 5)

View file

@ -0,0 +1,8 @@
(defn multiply
([] 1)
([x] x)
([x y] (* x y))
([x y & more]
(reduce * (* x y) more)))
(multiply 2 3 4 5) ; 120

View file

@ -0,0 +1 @@
multiply = (a, b) -> a * b

View file

@ -0,0 +1,5 @@
<cffunction name="multiply" returntype="numeric">
<cfargument name="a" type="numeric">
<cfargument name="b" type="numeric">
<cfreturn a * b>
</cffunction>

View file

@ -0,0 +1,4 @@
(defun multiply (a b)
(* a b))
(multiply 2 3)

View file

@ -0,0 +1,4 @@
(define-compiler-macro multiply (&whole expr a b)
(if (and (constantp a) (constantp b))
(* (eval a) (eval b))
expr)) ;; no macro recursion if we just return expr; the job is done!

View file

@ -0,0 +1 @@
;;; terrific example coming

View file

@ -0,0 +1,26 @@
// A function:
int multiply1(int a, int b) {
return a * b;
}
// Functions like "multiply1" can be evaluated at compile time if
// they are called where a compile-time constant result is asked for:
enum result = multiply1(2, 3); // Evaluated at compile time.
int[multiply1(2, 4)] array; // Evaluated at compile time.
// A templated function:
T multiply2(T)(T a, T b) {
return a * b;
}
// Compile-time multiplication can also be done using templates:
template multiply3(int a, int b) {
enum multiply3 = a * b;
}
pragma(msg, multiply3!(2, 3)); // Prints "6" during compilation.
void main() {
import std.stdio;
writeln("2 * 3 = ", result);
}

View file

@ -0,0 +1,4 @@
function Multiply(a, b : Integer) : Integer;
begin
Result := a * b;
end;

View file

@ -0,0 +1,4 @@
function Multiply(a, b: Integer): Integer;
begin
Result := a * b;
end;

View file

@ -0,0 +1,3 @@
def multiply(a, b) {
return a * b
}

View file

@ -0,0 +1 @@
def multiply := fn a, b { a * b }

View file

@ -0,0 +1,8 @@
multiply = fn (A, B) {
A * B
}
@public
run = fn () {
io.format("~p~n", [multiply(2, 5)])
}

View file

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

View file

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

View file

@ -0,0 +1 @@
multiply(A,B) -> A*B.

View file

@ -0,0 +1,3 @@
function multiply( atom a, atom b )
return a * b
end function

View file

@ -0,0 +1,12 @@
function multiply( object a, object b )
return a * b
end function
sequence a = {1,2,3,4}
sequence b = {5,6,7,8}
? multiply( 9, 9 )
? multiply( 3.14159, 3.14159 )
? multiply( a, b )
? multiply( a, 7 )
? multiply( 10.39564, b )

View file

@ -0,0 +1,3 @@
[*] {anonymous function to multiply the top two items on the stack}
m: {binding the function to one of the 26 available symbol names}
2 3m;! {executing the function, yielding 6}

View file

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

View file

@ -0,0 +1,3 @@
function sayHiTo( name )
> "Hi ", name
end

View file

@ -0,0 +1,8 @@
class FunctionDefinition
{
public static Void main ()
{
multiply := |Int a, Int b -> Int| { a * b }
echo ("Multiply 2 and 4: ${multiply(2, 4)}")
}
}

View file

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

View file

@ -0,0 +1 @@
\multiply=*

View file

@ -0,0 +1,2 @@
: fmultiply ( F: a b -- F: c ) F* ;
: multiply ( a b -- c ) * ;

View file

@ -0,0 +1,4 @@
FUNCTION MULTIPLY(X,Y)
REAL MULTIPLY, X, Y
MULTIPLY = X * Y
END

View file

@ -0,0 +1,8 @@
module elemFunc
contains
elemental function multiply(x, y)
real, intent(in) :: x, y
real :: multiply
multiply = x * y
end function multiply
end module elemFunc

View file

@ -0,0 +1,10 @@
program funcDemo
use elemFunc
real :: a = 20.0, b = 30.0, c
real, dimension(5) :: x = (/ 1.0, 2.0, 3.0, 4.0, 5.0 /), y = (/ 32.0, 16.0, 8.0, 4.0, 2.0 /), z
c = multiply(a,b) ! works with either function definition above
z = multiply(x,y) ! element-wise invocation only works with elemental function
end program funcDemo

View file

@ -0,0 +1,2 @@
c = multiply(y=b, x=a) ! the same as multiply(a, b)
z = multiply(y=x, x=y) ! the same as multiply(y, x)

View file

@ -0,0 +1,8 @@
module elemFunc
contains
elemental function multiply(x, y) result(z)
real, intent(in) :: x, y
real :: z
z = x * y
end function multiply
end module elemFunc

View file

@ -0,0 +1 @@
multiply[x,y] := x*y

View file

@ -0,0 +1,4 @@
#define multiply
a = argument0
b = argument1
return(a * b)

View file

@ -0,0 +1,3 @@
func multiply(a, b float64) float64 {
return a * b
}

View file

@ -0,0 +1,4 @@
func multiply(a, b float64) (z float64) {
z = a * b
return
}

View file

@ -0,0 +1 @@
{*}:multiply;

View file

@ -0,0 +1 @@
def multiply = { x, y -> x * y }

View file

@ -0,0 +1 @@
println "x * y = 20 * 50 = ${multiply 20, 50}"

View file

@ -0,0 +1 @@
multiply = (*)

View file

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

View file

@ -0,0 +1,3 @@
function multiply(x:Float, y:Float):Float{
return x * y;
}

View file

@ -0,0 +1,3 @@
FUNCTION multiply(a, b)
multiply = a * b
END

View file

@ -0,0 +1,3 @@
function multiply ,a,b
return, a* b
end

View file

@ -0,0 +1,3 @@
function multiply ,a,b
return, product([a, b])
end

View file

@ -0,0 +1,3 @@
function multiply ,a,b
return, a # b
end

View file

@ -0,0 +1,3 @@
procedure multiply(a,b)
return a * b
end

View file

@ -0,0 +1,3 @@
[ multiply a b;
return a * b;
];

View file

@ -0,0 +1,2 @@
To decide which number is (A - number) multiplied by (B - number):
decide on A * B.

View file

@ -0,0 +1 @@
multiply := method(a,b,a*b)

View file

@ -0,0 +1 @@
multiply=: *

View file

@ -0,0 +1,3 @@
multiply=: dyad define
x * y
)

View file

@ -0,0 +1,5 @@
public class Math
{
public static int multiply( int a, int b) { return a*b; }
public static double multiply(double a, double b) { return a*b; }
}

View file

@ -0,0 +1 @@
function multiply(a,b) { return a*b }

View file

@ -0,0 +1,3 @@
var multiply = function (a, b) {
return a * b;
};

View file

@ -0,0 +1 @@
DEFINE multiply == * .

View file

@ -0,0 +1,3 @@
function multiply(a::Number,b::Number)
return a*b
end

View file

@ -0,0 +1,11 @@
program test;
// A function definition in Kaya:
Int multiply(Int a, Int b) {
return a * b;
}
// And calling a function:
Void main() {
putStrLn(string( multiply(2, 3) ));
}

View file

@ -0,0 +1,2 @@
multiply : *
multiply. : *. # floating point

View file

@ -0,0 +1,11 @@
' define & call a function
print multiply( 3, 1.23456)
wait
function multiply( m1, m2)
multiply =m1 *m2
end function
end

View file

@ -0,0 +1,2 @@
10 DEF FNmultiply(x,y)=x*y
20 PRINT FNmultiply(2,PI)

View file

@ -0,0 +1,3 @@
to multiply :x :y
output :x * :y
end

View file

@ -0,0 +1,3 @@
function multiply( a, b )
return a * b
end

View file

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

View file

@ -0,0 +1,3 @@
define(`multiply',`eval($1*$2)')
multiply(2,3)

View file

@ -0,0 +1,3 @@
function C = multiply(A,B)
C = A*B;
end

Some files were not shown because too many files have changed in this diff Show more