Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
6
Task/Function-definition/00-META.yaml
Normal file
6
Task/Function-definition/00-META.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
category:
|
||||
- Functions and subroutines
|
||||
- Simple
|
||||
from: http://rosettacode.org/wiki/Function_definition
|
||||
note: Basic language learning
|
||||
15
Task/Function-definition/00-TASK.txt
Normal file
15
Task/Function-definition/00-TASK.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
A function is a body of code that returns a value.
|
||||
|
||||
The value returned may depend on arguments provided to the function.
|
||||
|
||||
|
||||
;Task:
|
||||
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).
|
||||
|
||||
|
||||
;Related task:
|
||||
* [[Function prototype]]
|
||||
<br><br>
|
||||
|
||||
2
Task/Function-definition/11l/function-definition-1.11l
Normal file
2
Task/Function-definition/11l/function-definition-1.11l
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
F multiply(a, b)
|
||||
R a * b
|
||||
1
Task/Function-definition/11l/function-definition-2.11l
Normal file
1
Task/Function-definition/11l/function-definition-2.11l
Normal file
|
|
@ -0,0 +1 @@
|
|||
V multiply = (a, b) -> a * b
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
DEFFUN CSECT
|
||||
USING DEFFUN,R13
|
||||
SAVEAREA B PROLOG-SAVEAREA(R15)
|
||||
DC 17F'0'
|
||||
PROLOG STM R14,R12,12(R13)
|
||||
ST R13,4(R15)
|
||||
ST R15,8(R13)
|
||||
LR R13,R15 set base register
|
||||
BEGIN L R2,=F'13'
|
||||
ST R2,X X=13
|
||||
L R2,=F'17'
|
||||
ST R2,Y Y=17
|
||||
LA R1,PARMLIST R1->PARMLIST
|
||||
B SKIPPARM
|
||||
PARMLIST DS 0F
|
||||
DC A(X)
|
||||
DC A(Y)
|
||||
SKIPPARM BAL R14,MULTPLIC call MULTPLIC
|
||||
ST R0,Z Z=MULTPLIC(X,Y)
|
||||
RETURN L R13,4(0,R13) epilog
|
||||
LM R14,R12,12(R13)
|
||||
XR R15,R15 set return code
|
||||
BR R14 return to caller
|
||||
*
|
||||
MULTPLIC EQU * function MULTPLIC(X,Y)
|
||||
L R2,0(R1) R2=(A(X),A(Y))
|
||||
XR R4,R4 R4=0
|
||||
L R5,0(R2) R5=X
|
||||
L R6,4(R2) R6=Y
|
||||
MR R4,R6 R4R5=R4R5*R6
|
||||
LR R0,R5 R0=X*Y (R0 return value)
|
||||
BR R14 end function MULTPLIC
|
||||
*
|
||||
X DS F
|
||||
Y DS F
|
||||
Z DS F
|
||||
YREGS
|
||||
END DEFFUN
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
MULTIPLY: STX MULN ; 6502 has no "acc += xreg" instruction,
|
||||
TXA ; so use a memory address
|
||||
MULLOOP: DEY
|
||||
CLC ; remember to clear the carry flag before
|
||||
ADC MULN ; doing addition or subtraction
|
||||
CPY #$01
|
||||
BNE MULLOOP
|
||||
RTS
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
; https://skilldrick.github.io/easy6502/
|
||||
; Multiplies A by X
|
||||
|
||||
define memory 1040
|
||||
|
||||
JMP MAIN
|
||||
|
||||
MULTIPLY: STA memory ; memory = A
|
||||
BEQ MUL_END ; A = 0
|
||||
TXA ; A = X
|
||||
BEQ MUL_END ; X = 0 -> A = 0
|
||||
LDA memory
|
||||
CLC
|
||||
MUL_LOOP: DEX ; X -= 1
|
||||
BEQ MUL_END ; X = 0 -> A = A * X
|
||||
ADC memory ; A += memory
|
||||
JMP MUL_LOOP
|
||||
MUL_END: RTS
|
||||
|
||||
MAIN: LDA #50
|
||||
LDX #5
|
||||
JSR MULTIPLY
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
MOVE.L D0,#$0200
|
||||
MOVE.L D1,#$0400
|
||||
|
||||
JSR doMultiply
|
||||
;rest of program
|
||||
|
||||
JMP $ ;halt
|
||||
|
||||
;;;;; somewhere far away from the code above
|
||||
doMultiply:
|
||||
MULU D0,D1
|
||||
RTS
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
ORG RESET
|
||||
mov a, #100
|
||||
mov b, #10
|
||||
call multiply
|
||||
; at this point, the result of 100*10 = 1000 = 03e8h is stored in registers a and b
|
||||
; a = e8
|
||||
; b = 03
|
||||
jmp $
|
||||
|
||||
multiply:
|
||||
mul ab
|
||||
ret
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
start:
|
||||
mov al, 0x04
|
||||
mov bl, 0x05
|
||||
call multiply
|
||||
;at this point in execution, the AX register contains 0x0900.
|
||||
;more code goes here, ideally with some sort of guard against "fallthrough" into multiply.
|
||||
|
||||
; somewhere far away from start
|
||||
multiply:
|
||||
mul bl ;outputs 0x0014 to ax
|
||||
ret
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
/* ARM assembly AARCH64 Raspberry PI 3B */
|
||||
/* program functMul64.s */
|
||||
|
||||
/*******************************************/
|
||||
/* Constantes file */
|
||||
/*******************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly*/
|
||||
.include "../includeConstantesARM64.inc"
|
||||
|
||||
/***********************/
|
||||
/* Initialized data */
|
||||
/***********************/
|
||||
.data
|
||||
szRetourLigne: .asciz "\n"
|
||||
szMessResult: .asciz "Resultat : @ \n" // message result
|
||||
/***********************
|
||||
/* No Initialized data */
|
||||
/***********************/
|
||||
.bss
|
||||
sZoneConv: .skip 24
|
||||
.text
|
||||
.global main
|
||||
main:
|
||||
// function multiply
|
||||
mov x0,8
|
||||
mov x1,50
|
||||
bl multiply // call function
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl conversion10S // call function with 2 parameter (x0,x1)
|
||||
ldr x0,qAdrszMessResult
|
||||
ldr x1,qAdrsZoneConv
|
||||
bl strInsertAtCharInc // insert result at @ character
|
||||
bl affichageMess // display message
|
||||
|
||||
mov x0,0 // return code
|
||||
|
||||
100: // end of program
|
||||
mov x8,EXIT // request to exit program
|
||||
svc 0 // perform the system call
|
||||
qAdrsZoneConv: .quad sZoneConv
|
||||
qAdrszMessResult: .quad szMessResult
|
||||
/******************************************************************/
|
||||
/* Function multiply */
|
||||
/******************************************************************/
|
||||
/* x0 contains value 1 */
|
||||
/* x1 contains value 2 */
|
||||
/* x0 return résult */
|
||||
multiply:
|
||||
mul x0,x1,x0
|
||||
ret // return function
|
||||
/********************************************************/
|
||||
/* File Include fonctions */
|
||||
/********************************************************/
|
||||
/* for this file see task include a file in language AArch64 assembly */
|
||||
.include "../includeARM64.inc"
|
||||
1
Task/Function-definition/ACL2/function-definition.acl2
Normal file
1
Task/Function-definition/ACL2/function-definition.acl2
Normal file
|
|
@ -0,0 +1 @@
|
|||
(defun multiply (a b) (* a b))
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
PROC multiply = ( LONG REAL a, b ) LONG REAL:
|
||||
(
|
||||
a * b
|
||||
)
|
||||
5
Task/Function-definition/ALGOL-M/function-definition.alg
Normal file
5
Task/Function-definition/ALGOL-M/function-definition.alg
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
INTEGER FUNCTION MULTIPLY( A, B );
|
||||
INTEGER A, B;
|
||||
BEGIN
|
||||
MULTIPLY := A * B;
|
||||
END;
|
||||
4
Task/Function-definition/ALGOL-W/function-definition.alg
Normal file
4
Task/Function-definition/ALGOL-W/function-definition.alg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
long real procedure multiply( long real value a, b );
|
||||
begin
|
||||
a * b
|
||||
end
|
||||
2
Task/Function-definition/ANT/function-definition-1.ant
Normal file
2
Task/Function-definition/ANT/function-definition-1.ant
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
multiply: * /`*' is a normal function
|
||||
multiply: {x * y}
|
||||
1
Task/Function-definition/ANT/function-definition-2.ant
Normal file
1
Task/Function-definition/ANT/function-definition-2.ant
Normal file
|
|
@ -0,0 +1 @@
|
|||
{expr-or-def1; expr-or-def2; ..; return-expr}
|
||||
8
Task/Function-definition/APL/function-definition-1.apl
Normal file
8
Task/Function-definition/APL/function-definition-1.apl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
⍝⍝ APL2 'tradfn' (traditional function)
|
||||
⍝⍝ This syntax works in all dialects including GNU APL and Dyalog.
|
||||
∇ product ← a multiply b
|
||||
product ← a × b
|
||||
∇
|
||||
|
||||
⍝⍝ A 'dfn' or 'lambda' (anonymous function)
|
||||
multiply ← {⍺×⍵}
|
||||
2
Task/Function-definition/APL/function-definition-2.apl
Normal file
2
Task/Function-definition/APL/function-definition-2.apl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
⍝⍝ Dyalog dfn (lambda) syntax
|
||||
multiply ← ×
|
||||
134
Task/Function-definition/ARM-Assembly/function-definition.arm
Normal file
134
Task/Function-definition/ARM-Assembly/function-definition.arm
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
/* ARM assembly Raspberry PI */
|
||||
/* program functMul.s */
|
||||
/* Constantes */
|
||||
.equ STDOUT, 1
|
||||
.equ WRITE, 4
|
||||
.equ EXIT, 1
|
||||
|
||||
/***********************/
|
||||
/* Initialized data */
|
||||
/***********************/
|
||||
.data
|
||||
szRetourLigne: .asciz "\n"
|
||||
szMessResult: .ascii "Resultat : " @ message result
|
||||
sMessValeur: .fill 12, 1, ' '
|
||||
.asciz "\n"
|
||||
/***********************
|
||||
/* No Initialized data */
|
||||
/***********************/
|
||||
.bss
|
||||
|
||||
.text
|
||||
.global main
|
||||
main:
|
||||
push {fp,lr} /* save 2 registers */
|
||||
|
||||
@ function multiply
|
||||
mov r0,#8
|
||||
mov r1,#50
|
||||
bl multiply @ call function
|
||||
ldr r1,iAdrsMessValeur
|
||||
bl conversion10S @ call function with 2 parameter (r0,r1)
|
||||
ldr r0,iAdrszMessResult
|
||||
bl affichageMess @ display message
|
||||
|
||||
mov r0, #0 @ return code
|
||||
|
||||
100: /* end of program */
|
||||
mov r7, #EXIT @ request to exit program
|
||||
swi 0 @ perform the system call
|
||||
iAdrsMessValeur: .int sMessValeur
|
||||
iAdrszMessResult: .int szMessResult
|
||||
/******************************************************************/
|
||||
/* Function multiply */
|
||||
/******************************************************************/
|
||||
/* r0 contains value 1 */
|
||||
/* r1 contains value 2 */
|
||||
/* r0 return résult */
|
||||
multiply:
|
||||
mul r0,r1,r0
|
||||
bx lr /* return function */
|
||||
|
||||
/******************************************************************/
|
||||
/* display text with size calculation */
|
||||
/******************************************************************/
|
||||
/* r0 contains the address of the message */
|
||||
affichageMess:
|
||||
push {fp,lr} /* save registres */
|
||||
push {r0,r1,r2,r7} /* save others registers */
|
||||
mov r2,#0 /* counter length */
|
||||
1: /* loop length calculation */
|
||||
ldrb r1,[r0,r2] /* read octet start position + index */
|
||||
cmp r1,#0 /* if 0 its over */
|
||||
addne r2,r2,#1 /* else add 1 in the length */
|
||||
bne 1b /* and loop */
|
||||
/* so here r2 contains the length of the message */
|
||||
mov r1,r0 /* address message in r1 */
|
||||
mov r0,#STDOUT /* code to write to the standard output Linux */
|
||||
mov r7, #WRITE /* code call system "write" */
|
||||
swi #0 /* call systeme */
|
||||
pop {r0,r1,r2,r7} /* restaur others registers */
|
||||
pop {fp,lr} /* restaur des 2 registres */
|
||||
bx lr /* return */
|
||||
|
||||
|
||||
/***************************************************/
|
||||
/* conversion register in string décimal signed */
|
||||
/***************************************************/
|
||||
/* r0 contains the register */
|
||||
/* r1 contains address of conversion area */
|
||||
conversion10S:
|
||||
push {fp,lr} /* save registers frame and return */
|
||||
push {r0-r5} /* save other registers */
|
||||
mov r2,r1 /* early storage area */
|
||||
mov r5,#'+' /* default sign is + */
|
||||
cmp r0,#0 /* négatif number ? */
|
||||
movlt r5,#'-' /* yes sign is - */
|
||||
mvnlt r0,r0 /* and inverse in positive value */
|
||||
addlt r0,#1
|
||||
mov r4,#10 /* area length */
|
||||
1: /* conversion loop */
|
||||
bl divisionpar10 /* division */
|
||||
add r1,#48 /* add 48 at remainder for conversion ascii */
|
||||
strb r1,[r2,r4] /* store byte area r5 + position r4 */
|
||||
sub r4,r4,#1 /* previous position */
|
||||
cmp r0,#0
|
||||
bne 1b /* loop if quotient not equal zéro */
|
||||
strb r5,[r2,r4] /* store sign at current position */
|
||||
subs r4,r4,#1 /* previous position */
|
||||
blt 100f /* if r4 < 0 end */
|
||||
/* else complete area with space */
|
||||
mov r3,#' ' /* character space */
|
||||
2:
|
||||
strb r3,[r2,r4] /* store byte */
|
||||
subs r4,r4,#1 /* previous position */
|
||||
bge 2b /* loop if r4 greather or equal zero */
|
||||
100: /* standard end of function */
|
||||
pop {r0-r5} /*restaur others registers */
|
||||
pop {fp,lr} /* restaur des 2 registers frame et return */
|
||||
bx lr
|
||||
|
||||
|
||||
/***************************************************/
|
||||
/* division par 10 signé */
|
||||
/* Thanks to http://thinkingeek.com/arm-assembler-raspberry-pi/*
|
||||
/* and http://www.hackersdelight.org/ */
|
||||
/***************************************************/
|
||||
/* r0 contient le dividende */
|
||||
/* r0 retourne le quotient */
|
||||
/* r1 retourne le reste */
|
||||
divisionpar10:
|
||||
/* r0 contains the argument to be divided by 10 */
|
||||
push {r2-r4} /* save autres registres */
|
||||
mov r4,r0
|
||||
ldr r3, .Ls_magic_number_10 /* r1 <- magic_number */
|
||||
smull r1, r2, r3, r0 /* r1 <- Lower32Bits(r1*r0). r2 <- Upper32Bits(r1*r0) */
|
||||
mov r2, r2, ASR #2 /* r2 <- r2 >> 2 */
|
||||
mov r1, r0, LSR #31 /* r1 <- r0 >> 31 */
|
||||
add r0, r2, r1 /* r0 <- r2 + r1 */
|
||||
add r2,r0,r0, lsl #2 /* r2 <- r0 * 5 */
|
||||
sub r1,r4,r2, lsl #1 /* r1 <- r4 - (r2 * 2) = r4 - (r0 * 10) */
|
||||
pop {r2-r4}
|
||||
bx lr /* leave function */
|
||||
.align 4
|
||||
.Ls_magic_number_10: .word 0x66666667
|
||||
7
Task/Function-definition/AWK/function-definition.awk
Normal file
7
Task/Function-definition/AWK/function-definition.awk
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
function multiply(a, b)
|
||||
{
|
||||
return a*b
|
||||
}
|
||||
BEGIN {
|
||||
print multiply(5, 6)
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
function multiply(a:Number, b:Number):Number {
|
||||
return a * b;
|
||||
}
|
||||
1
Task/Function-definition/Ada/function-definition-1.ada
Normal file
1
Task/Function-definition/Ada/function-definition-1.ada
Normal file
|
|
@ -0,0 +1 @@
|
|||
function Multiply (A, B : Float) return Float;
|
||||
4
Task/Function-definition/Ada/function-definition-2.ada
Normal file
4
Task/Function-definition/Ada/function-definition-2.ada
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
function Multiply (A, B : Float) return Float is
|
||||
begin
|
||||
return A * B;
|
||||
end Multiply;
|
||||
1
Task/Function-definition/Ada/function-definition-3.ada
Normal file
1
Task/Function-definition/Ada/function-definition-3.ada
Normal file
|
|
@ -0,0 +1 @@
|
|||
function Multiply(A, B: Float) return Float is (A * B);
|
||||
3
Task/Function-definition/Ada/function-definition-4.ada
Normal file
3
Task/Function-definition/Ada/function-definition-4.ada
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
generic
|
||||
type Number is digits <>;
|
||||
function Multiply (A, B : Number) return Number;
|
||||
4
Task/Function-definition/Ada/function-definition-5.ada
Normal file
4
Task/Function-definition/Ada/function-definition-5.ada
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
function Multiply (A, B : Number) return Number is
|
||||
begin
|
||||
return A * B;
|
||||
end Multiply;
|
||||
7
Task/Function-definition/Ada/function-definition-6.ada
Normal file
7
Task/Function-definition/Ada/function-definition-6.ada
Normal 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);
|
||||
5
Task/Function-definition/Aime/function-definition.aime
Normal file
5
Task/Function-definition/Aime/function-definition.aime
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
real
|
||||
multiply(real a, real b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
11
Task/Function-definition/AmigaE/function-definition.amiga
Normal file
11
Task/Function-definition/AmigaE/function-definition.amiga
Normal 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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
to multiply(a as number, b as number)
|
||||
return a * b
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
on multiply(a, b)
|
||||
return a * b
|
||||
end multiply
|
||||
|
||||
multiply(2, 3)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
on multiplication of a by b
|
||||
return a * b
|
||||
end multiplication
|
||||
|
||||
multiplication of 2 by 3 -- Or: (multiplication by 3) of 2, or: 2's (multiplication by 3)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
on multiply:a |by|:b -- 'by' is "barred" here because otherwise it's a reserved word.
|
||||
return a * b
|
||||
end multiply:|by|:
|
||||
|
||||
my multiply:2 |by|:3
|
||||
|
|
@ -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)
|
||||
|
|
@ -0,0 +1 @@
|
|||
47658
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
use std
|
||||
.: multiply <real a, real b> :. -> real {a * b}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
use std
|
||||
=: multiply <real a> [<real b>...] := -> real {Cgen a (@@1 (Cgen " * " b))}
|
||||
12
Task/Function-definition/ArnoldC/function-definition.arnoldc
Normal file
12
Task/Function-definition/ArnoldC/function-definition.arnoldc
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
LISTEN TO ME VERY CAREFULLY multiply
|
||||
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE a
|
||||
I NEED YOUR CLOTHES YOUR BOOTS AND YOUR MOTORCYCLE b
|
||||
GIVE THESE PEOPLE AIR
|
||||
HEY CHRISTMAS TREE product
|
||||
YOU SET US UP @I LIED
|
||||
GET TO THE CHOPPER product
|
||||
HERE IS MY INVITATION a
|
||||
YOU'RE FIRED b
|
||||
ENOUGH TALK
|
||||
I'LL BE BACK product
|
||||
HASTA LA VISTA, BABY
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
multiply: $[x,y][x*y]
|
||||
|
||||
print multiply 3 7
|
||||
|
||||
multiply2: function [x,y][
|
||||
return x*y
|
||||
]
|
||||
|
||||
print multiply2 3 7
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
MsgBox % multiply(10,2)
|
||||
|
||||
multiply(multiplicand, multiplier) {
|
||||
Return (multiplicand * multiplier)
|
||||
}
|
||||
|
|
@ -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
|
||||
3
Task/Function-definition/Axe/function-definition.axe
Normal file
3
Task/Function-definition/Axe/function-definition.axe
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Lbl MULT
|
||||
r₁*r₂
|
||||
Return
|
||||
5
Task/Function-definition/BASIC/function-definition.basic
Normal file
5
Task/Function-definition/BASIC/function-definition.basic
Normal 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
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
function multiply(a, b)
|
||||
return a * b
|
||||
end function
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
PRINT FNmultiply(6,7)
|
||||
END
|
||||
|
||||
DEF FNmultiply(a,b) = a * b
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
DEF FNmultiply(a,b)
|
||||
LOCAL c
|
||||
c = a * b
|
||||
= c
|
||||
1
Task/Function-definition/BCPL/function-definition-1.bcpl
Normal file
1
Task/Function-definition/BCPL/function-definition-1.bcpl
Normal file
|
|
@ -0,0 +1 @@
|
|||
let multiply(a, b) = a * b
|
||||
4
Task/Function-definition/BCPL/function-definition-2.bcpl
Normal file
4
Task/Function-definition/BCPL/function-definition-2.bcpl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
let multiply(a, b) = valof
|
||||
$( // any imperative statements could go here
|
||||
resultis a * b
|
||||
$)
|
||||
1
Task/Function-definition/BQN/function-definition-1.bqn
Normal file
1
Task/Function-definition/BQN/function-definition-1.bqn
Normal file
|
|
@ -0,0 +1 @@
|
|||
Multiply ← ×
|
||||
1
Task/Function-definition/BQN/function-definition-2.bqn
Normal file
1
Task/Function-definition/BQN/function-definition-2.bqn
Normal file
|
|
@ -0,0 +1 @@
|
|||
Multiply ← {𝕨×𝕩}
|
||||
11
Task/Function-definition/Batch-File/function-definition.bat
Normal file
11
Task/Function-definition/Batch-File/function-definition.bat
Normal 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
|
||||
3
Task/Function-definition/Bc/function-definition.bc
Normal file
3
Task/Function-definition/Bc/function-definition.bc
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
define multiply(a, b) { return a*b }
|
||||
|
||||
print multiply(2, 3)
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
function multiply:float( a:float, b:float )
|
||||
return a*b
|
||||
end function
|
||||
|
||||
print multiply(3.1416, 1.6180)
|
||||
4
Task/Function-definition/Boo/function-definition.boo
Normal file
4
Task/Function-definition/Boo/function-definition.boo
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
def multiply(x as int, y as int):
|
||||
return x * y
|
||||
|
||||
print multiply(3, 2)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
multiply=a b.!arg:(?a.?b)&!a*!b;
|
||||
out$multiply$(123456789.987654321); { writes 121932631112635269 to standard output }
|
||||
3
Task/Function-definition/Brat/function-definition.brat
Normal file
3
Task/Function-definition/Brat/function-definition.brat
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
multiply = { x, y | x * y }
|
||||
|
||||
p multiply 3 14 #Prints 42
|
||||
4
Task/Function-definition/C++/function-definition-1.cpp
Normal file
4
Task/Function-definition/C++/function-definition-1.cpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
inline double multiply(double a, double b)
|
||||
{
|
||||
return a*b;
|
||||
}
|
||||
5
Task/Function-definition/C++/function-definition-2.cpp
Normal file
5
Task/Function-definition/C++/function-definition-2.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
template<typename Number>
|
||||
Number multiply(Number a, Number b)
|
||||
{
|
||||
return a*b;
|
||||
}
|
||||
4
Task/Function-definition/C++/function-definition-3.cpp
Normal file
4
Task/Function-definition/C++/function-definition-3.cpp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
auto multiply(auto a, auto b)
|
||||
{
|
||||
return a*b;
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
static double multiply(double a, double b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Func<double, double, double> multiply = ((a,b) => a*b);
|
||||
4
Task/Function-definition/C/function-definition-1.c
Normal file
4
Task/Function-definition/C/function-definition-1.c
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
double multiply(double a, double b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
1
Task/Function-definition/C/function-definition-2.c
Normal file
1
Task/Function-definition/C/function-definition-2.c
Normal file
|
|
@ -0,0 +1 @@
|
|||
#define MULTIPLY(X, Y) ((X) * (Y))
|
||||
1
Task/Function-definition/C/function-definition-3.c
Normal file
1
Task/Function-definition/C/function-definition-3.c
Normal file
|
|
@ -0,0 +1 @@
|
|||
x = MULTIPLY(x + z, y);
|
||||
1
Task/Function-definition/C/function-definition-4.c
Normal file
1
Task/Function-definition/C/function-definition-4.c
Normal file
|
|
@ -0,0 +1 @@
|
|||
x = ((x + z) * (y));
|
||||
3
Task/Function-definition/CLU/function-definition-1.clu
Normal file
3
Task/Function-definition/CLU/function-definition-1.clu
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
multiply = proc (a, b: int) returns (int)
|
||||
return(a * b)
|
||||
end multiply
|
||||
6
Task/Function-definition/CLU/function-definition-2.clu
Normal file
6
Task/Function-definition/CLU/function-definition-2.clu
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
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
|
||||
26
Task/Function-definition/COBOL/function-definition-1.cobol
Normal file
26
Task/Function-definition/COBOL/function-definition-1.cobol
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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.
|
||||
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.
|
||||
26
Task/Function-definition/COBOL/function-definition-2.cobol
Normal file
26
Task/Function-definition/COBOL/function-definition-2.cobol
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
IDENTIFICATION DIVISION.
|
||||
PROGRAM-ID. myTest.
|
||||
ENVIRONMENT DIVISION.
|
||||
CONFIGURATION SECTION.
|
||||
REPOSITORY.
|
||||
FUNCTION myMultiply.
|
||||
DATA DIVISION.
|
||||
WORKING-STORAGE SECTION.
|
||||
01 x PIC 9(3) VALUE 3.
|
||||
01 y PIC 9(3) VALUE 2.
|
||||
PROCEDURE DIVISION.
|
||||
DISPLAY myMultiply(x, y).
|
||||
STOP RUN.
|
||||
END PROGRAM myTest.
|
||||
|
||||
IDENTIFICATION DIVISION.
|
||||
FUNCTION-ID. myMultiply.
|
||||
DATA DIVISION.
|
||||
LINKAGE SECTION.
|
||||
01 x PIC 9(3).
|
||||
01 y PIC 9(3).
|
||||
01 z pic 9(9).
|
||||
PROCEDURE DIVISION USING x, y RETURNING z.
|
||||
MULTIPLY x BY y GIVING z.
|
||||
EXIT FUNCTION.
|
||||
END FUNCTION myMultiply.
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
10 rem Function definition
|
||||
|
||||
20 rem ** 1. Function defined as formula. An obsolete way - does not work properly with integer formal parameters (e.g. x%).
|
||||
30 def fnmultiply(a, b) = a * b
|
||||
|
||||
40 rem ** Call the functions
|
||||
50 print multiply(3,1.23456)
|
||||
60 print fn multiply(3,1.23456)
|
||||
70 end
|
||||
|
||||
200 rem ** 2. Function defined as subroutine returning a value
|
||||
210 sub multiply(a,b)
|
||||
220 multiply = a*b
|
||||
230 end sub
|
||||
6
Task/Function-definition/ChucK/function-definition.chuck
Normal file
6
Task/Function-definition/ChucK/function-definition.chuck
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
fun float multiply (float a, float b)
|
||||
{
|
||||
return a * b;
|
||||
}
|
||||
// uncomment next line and change values to test
|
||||
//<<< multiply(16,4) >>>;
|
||||
1
Task/Function-definition/Clay/function-definition.clay
Normal file
1
Task/Function-definition/Clay/function-definition.clay
Normal file
|
|
@ -0,0 +1 @@
|
|||
multiply(x,y) = x * y;
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(defn multiply [x y]
|
||||
(* x y))
|
||||
|
||||
(multiply 4 5)
|
||||
|
|
@ -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
|
||||
1
Task/Function-definition/Coco/function-definition-1.coco
Normal file
1
Task/Function-definition/Coco/function-definition-1.coco
Normal file
|
|
@ -0,0 +1 @@
|
|||
multiply = -> @@0 * @@1
|
||||
1
Task/Function-definition/Coco/function-definition-2.coco
Normal file
1
Task/Function-definition/Coco/function-definition-2.coco
Normal file
|
|
@ -0,0 +1 @@
|
|||
double = -> 2 * it
|
||||
|
|
@ -0,0 +1 @@
|
|||
multiply = (a, b) -> a * b
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<cffunction name="multiply" returntype="numeric">
|
||||
<cfargument name="a" type="numeric">
|
||||
<cfargument name="b" type="numeric">
|
||||
<cfreturn a * b>
|
||||
</cffunction>
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
numeric function multiply(required numeric a, required numeric b){
|
||||
return a * b;
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
10 DEF FN MULT(X) = X*Y
|
||||
20 Y = 4 : REM VALUE OF SECOND ARGUMENT MUST BE ASSIGNED SEPARATELY
|
||||
30 PRINT FN MULT(3)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(defun multiply (a b)
|
||||
(* a b))
|
||||
|
||||
(multiply 2 3)
|
||||
|
|
@ -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!
|
||||
|
|
@ -0,0 +1 @@
|
|||
;;; terrific example coming
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
sub multiply(a: int32, b: int32): (rslt: int32) is
|
||||
rslt := a * b;
|
||||
end sub
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
DECLARE Multiply(N1:INT,N2:INT)
|
||||
|
||||
DEF A,B:INT
|
||||
|
||||
A=2:B=2
|
||||
|
||||
OPENCONSOLE
|
||||
|
||||
PRINT Multiply(A,B)
|
||||
|
||||
PRINT:PRINT"Press any key to close."
|
||||
|
||||
DO:UNTIL INKEY$<>""
|
||||
|
||||
CLOSECONSOLE
|
||||
|
||||
END
|
||||
|
||||
SUB Multiply(N1:INT,N2:INT)
|
||||
|
||||
DEF Product:INT
|
||||
|
||||
Product=N1*N2
|
||||
|
||||
RETURN Product
|
||||
|
||||
'Can also be written with no code in the subroutine and just RETURN N1*N2.
|
||||
24
Task/Function-definition/D/function-definition.d
Normal file
24
Task/Function-definition/D/function-definition.d
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// 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:
|
||||
enum multiply3(int a, int b) = a * b;
|
||||
|
||||
pragma(msg, multiply3!(2, 3)); // Prints "6" during compilation.
|
||||
|
||||
void main() {
|
||||
import std.stdio;
|
||||
writeln("2 * 3 = ", result);
|
||||
}
|
||||
2
Task/Function-definition/DM/function-definition.dm
Normal file
2
Task/Function-definition/DM/function-definition.dm
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
proc/multiply(a, b)
|
||||
return a * b
|
||||
4
Task/Function-definition/DWScript/function-definition.dw
Normal file
4
Task/Function-definition/DWScript/function-definition.dw
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
function Multiply(a, b : Integer) : Integer;
|
||||
begin
|
||||
Result := a * b;
|
||||
end;
|
||||
17
Task/Function-definition/Dart/function-definition.dart
Normal file
17
Task/Function-definition/Dart/function-definition.dart
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
main(){
|
||||
print(multiply(1,2));
|
||||
print(multiply2(1,2));
|
||||
print(multiply3(1,2));
|
||||
}
|
||||
|
||||
// the following definitions are equivalent
|
||||
// arrow syntax without type annotations
|
||||
multiply(num1, num2) => num1 * num2;
|
||||
|
||||
// arrow syntax with type annotations
|
||||
int multiply2(int num1, int num2) => num1 * num2;
|
||||
|
||||
// c style with curly braces
|
||||
int multiply3(int num1, int num2){
|
||||
return num1 * num2;
|
||||
}
|
||||
1
Task/Function-definition/Dc/function-definition-1.dc
Normal file
1
Task/Function-definition/Dc/function-definition-1.dc
Normal file
|
|
@ -0,0 +1 @@
|
|||
[*] sm
|
||||
2
Task/Function-definition/Dc/function-definition-2.dc
Normal file
2
Task/Function-definition/Dc/function-definition-2.dc
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
3 4 lm x f
|
||||
= 12
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
function multiply(a, b: integer): integer;
|
||||
begin
|
||||
result := a * b;
|
||||
end;
|
||||
5
Task/Function-definition/Diego/function-definition.diego
Normal file
5
Task/Function-definition/Diego/function-definition.diego
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
begin_funct({number}, multiply)_param({number}, a, b);
|
||||
with_funct[]_calc([a]*[b]);
|
||||
end_funct[];
|
||||
|
||||
me_msg()_funct(multiply)_param(1,2);
|
||||
3
Task/Function-definition/Draco/function-definition.draco
Normal file
3
Task/Function-definition/Draco/function-definition.draco
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
proc multiply(word a, b) word:
|
||||
a * b
|
||||
corp
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
func multiply(a, b) {
|
||||
return a*b
|
||||
}
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
func multiply(a, b) {
|
||||
a * b
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
let multiply = (a, b) => a * b
|
||||
3
Task/Function-definition/E/function-definition-1.e
Normal file
3
Task/Function-definition/E/function-definition-1.e
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
def multiply(a, b) {
|
||||
return a * b
|
||||
}
|
||||
1
Task/Function-definition/E/function-definition-2.e
Normal file
1
Task/Function-definition/E/function-definition-2.e
Normal file
|
|
@ -0,0 +1 @@
|
|||
def multiply := fn a, b { a * b }
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue