September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
12
Task/Function-prototype/C-sharp/function-prototype-1.cs
Normal file
12
Task/Function-prototype/C-sharp/function-prototype-1.cs
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
using System;
|
||||
abstract class Printer
|
||||
{
|
||||
public abstract void Print();
|
||||
}
|
||||
|
||||
class PrinterImpl : Printer
|
||||
{
|
||||
public override void Print() {
|
||||
Console.WriteLine("Hello world!");
|
||||
}
|
||||
}
|
||||
22
Task/Function-prototype/C-sharp/function-prototype-2.cs
Normal file
22
Task/Function-prototype/C-sharp/function-prototype-2.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
public delegate int IntFunction(int a, int b);
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static int Add(int x, int y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
public static int Multiply(int x, int y) {
|
||||
return x * y;
|
||||
}
|
||||
|
||||
public static void Main() {
|
||||
IntFunction func = Add;
|
||||
Console.WriteLine(func(2, 3)); //prints 5
|
||||
func = Multiply;
|
||||
Console.WriteLine(func(2, 3)); //prints 6
|
||||
func += Add;
|
||||
Console.WriteLine(func(2, 3)); //prints 5. Both functions are called, but only the last result is kept.
|
||||
}
|
||||
}
|
||||
20
Task/Function-prototype/C-sharp/function-prototype-3.cs
Normal file
20
Task/Function-prototype/C-sharp/function-prototype-3.cs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
//file1.cs
|
||||
public partial class Program
|
||||
{
|
||||
partial void Print();
|
||||
}
|
||||
|
||||
//file2.cs
|
||||
using System;
|
||||
|
||||
public partial class Program
|
||||
{
|
||||
partial void Print() {
|
||||
Console.WriteLine("Hello world!");
|
||||
}
|
||||
|
||||
static void Main() {
|
||||
Program p = new Program();
|
||||
p.Print(); //If the implementation above is not written, the compiler will remove this line.
|
||||
}
|
||||
}
|
||||
35
Task/Function-prototype/Kotlin/function-prototype.kotlin
Normal file
35
Task/Function-prototype/Kotlin/function-prototype.kotlin
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// version 1.0.6
|
||||
|
||||
interface MyInterface {
|
||||
fun foo() // no arguments, no return type
|
||||
fun goo(i: Int, j: Int) // two arguments, no return type
|
||||
fun voo(vararg v: Int) // variable number of arguments, no return type
|
||||
fun ooo(o: Int = 1): Int // optional argument with default value and return type Int
|
||||
fun roo(): Int // no arguments with return type Int
|
||||
val poo: Int // read only property of type Int
|
||||
}
|
||||
|
||||
abstract class MyAbstractClass {
|
||||
abstract fun afoo() // abstract member function, no arguments or return type
|
||||
abstract var apoo: Int // abstract read/write member property of type Int
|
||||
}
|
||||
|
||||
class Derived : MyAbstractClass(), MyInterface {
|
||||
override fun afoo() {}
|
||||
override var apoo: Int = 0
|
||||
|
||||
override fun foo() {}
|
||||
override fun goo(i: Int, j: Int) {}
|
||||
override fun voo(vararg v: Int) {}
|
||||
override fun ooo(o: Int): Int = o // can't specify default argument again here but same as in interface
|
||||
override fun roo(): Int = 2
|
||||
override val poo: Int = 3
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val d = Derived()
|
||||
println(d.apoo)
|
||||
println(d.ooo()) // default argument of 1 inferred
|
||||
println(d.roo())
|
||||
println(d.poo)
|
||||
}
|
||||
5
Task/Function-prototype/Phix/function-prototype.phix
Normal file
5
Task/Function-prototype/Phix/function-prototype.phix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
forward function noargs() -- Declare a function with no arguments
|
||||
forward procedure twoargs(integer a, integer b) -- Declare a procedure with two arguments
|
||||
forward procedure twoargs(integer, integer /*b*/) -- Parameter names are optional in forward (and actual) definitions
|
||||
forward function anyargs(sequence s) -- varargs are [best/often] handled as a (single) sequence in Phix
|
||||
forward function atleastonearg(integer a, integer b=1, ...); -- Default makes args optional (== actual defn)
|
||||
8
Task/Function-prototype/SNOBOL4/function-prototype-1.sno
Normal file
8
Task/Function-prototype/SNOBOL4/function-prototype-1.sno
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
define('multiply(a,b)') :(mul_end)
|
||||
multiply multiply = a * b :(return)
|
||||
mul_end
|
||||
|
||||
* Test
|
||||
output = multiply(10.1,12.2)
|
||||
output = multiply(10,12)
|
||||
end
|
||||
21
Task/Function-prototype/SNOBOL4/function-prototype-2.sno
Normal file
21
Task/Function-prototype/SNOBOL4/function-prototype-2.sno
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
define('multiply(a,b)')
|
||||
|
||||
*
|
||||
* Assume lots more code goes here.
|
||||
*
|
||||
:(test)
|
||||
|
||||
*
|
||||
* MORE CODE!
|
||||
*
|
||||
|
||||
multiply multiply = a * b :(return)
|
||||
|
||||
*
|
||||
* MORE CODE!
|
||||
*
|
||||
|
||||
test
|
||||
output = multiply(10.1,12.2)
|
||||
output = multiply(10,12)
|
||||
end
|
||||
10
Task/Function-prototype/SNOBOL4/function-prototype-3.sno
Normal file
10
Task/Function-prototype/SNOBOL4/function-prototype-3.sno
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
define('multiply(a,b)acc1,acc2','mult_impl') :(mult_end)
|
||||
mult_impl acc1 = a
|
||||
acc2 = b
|
||||
multiply = acc1 * acc2 :(return)
|
||||
mult_end
|
||||
|
||||
* Test
|
||||
output = multiply(10.1,12.2)
|
||||
output = multiply(10,12)
|
||||
end
|
||||
24
Task/Function-prototype/Zkl/function-prototype.zkl
Normal file
24
Task/Function-prototype/Zkl/function-prototype.zkl
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
fcn{"Hello World"} // no expected args
|
||||
fcn(){"Hello World"} // ditto
|
||||
|
||||
fcn{vm.arglist}(1,2) // ask the VM for the passed in args -->L(1,2)
|
||||
fcn f(a,b){a+b} // fcn(1,2,3) works just fine
|
||||
fcn f(args){}(1,2,3) //args = 1
|
||||
fcn(args){vm.arglist.sum()}(1,2,3) //-->6
|
||||
|
||||
fcn(a=1,b=2){vm.arglist}() //-->L(1,2)
|
||||
fcn(a=1,b=2){vm.arglist}(5) //-->L(5,2)
|
||||
fcn(a=1,b){vm.arglist}() //-->L(1), error if you try to use b
|
||||
fcn(a,b=2){vm.arglist}(5) //-->L(5,2)
|
||||
fcn(a,b=2,c){vm.arglist}(1) //-->L(1,2)
|
||||
|
||||
fcn(){vm.nthArg(1)}(5,6) //-->6
|
||||
fcn{vm.numArgs}(1,2,3,4,5,6,7,8,9) //-->9
|
||||
fcn{vm.argsMatch(...)} // a somewhat feeble attempt arg pattern matching based on type (vs value)
|
||||
|
||||
// you can do list assignment in the prototype:
|
||||
fcn(a,[(b,c)],d){vm.arglist}(1,L(2,3,4),5) //-->L(1,L(2,3,4),5)
|
||||
fcn(a,[(b,c)],d){"%s,%s,%s,%s".fmt(a,b,c,d)}(1,L(2,3,4),5) //-->1,2,3,5
|
||||
|
||||
// no type enforcement but you can give a hint to the compiler
|
||||
fcn([Int]n){n.sin()} //--> syntax error as Ints don't do sin
|
||||
Loading…
Add table
Add a link
Reference in a new issue