RosettaCodeData/Task/Function-definition/M2000-Interpreter/function-definition-2.m2000

66 lines
1.6 KiB
Plaintext

Module Checkit {
\\ functions can shange by using a newer definition
\\ function Multiply is local, and at the exit of Checkit, erased.
Function Multiply (a, b) {
=a*b
}
Print Multiply(10, 5)=50
Function Multiply {
=Number*Number
}
Print Multiply(10, 5)=50
Function Multiply {
If not match("NN") Then Error "I nead two numbers"
Read a, b
=a*b
}
Print Multiply(10, 5)=50
Function Multiply {
Read a as long, b as long
=a*b
}
Z=Multiply(10, 5)
Print Z=50, Type$(Z)="Long"
Function Multiply(a as decimal=1, b as decimal=2) {
=a*b
}
D=Multiply(10, 5)
Print D=50, Type$(D)="Decimal"
D=Multiply( , 50)
Print D=50, Type$(D)="Decimal"
D=Multiply( 50)
Print D=100, Type$(D)="Decimal"
\\ by reference plus using type
Function Multiply(&a as decimal, &b as decimal) {
=a*b
a++
b--
}
alfa=10@
beta=20@
D=Multiply(&alfa, &beta)
Print D=200, alfa=11,beta=19, Type$(D)="Decimal"
\\ Using Match() to identify type of items at the top of stack
Function MultiplyALot {
M=Stack
While Match("NN") {
mul=Number*Number
Stack M {
Data mul ' at the bottom
}
}
=Array(M)
}
K=MultiplyALot(1,2,3,4,5,6,7,8,9,10)
N=Each(K)
While N {
Print Array(N), ' we get 2 12 30 56 90
}
Print
}
Checkit