Family Day update
This commit is contained in:
parent
aac6731f2c
commit
9ad63ea473
2442 changed files with 39761 additions and 8255 deletions
|
|
@ -1,2 +1,2 @@
|
|||
var c0 := (){ console.writeLine("No argument provided") };
|
||||
var c0 := { console.writeLine("No argument provided") };
|
||||
var c2 := (int a, int b){ console.printLine("Arguments ",a," and ",b," provided") };
|
||||
|
|
|
|||
2
Task/Call-a-function/Go/call-a-function-10.go
Normal file
2
Task/Call-a-function/Go/call-a-function-10.go
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
list = append(list, a, d, e, i)
|
||||
i = len(list)
|
||||
21
Task/Call-a-function/Go/call-a-function-11.go
Normal file
21
Task/Call-a-function/Go/call-a-function-11.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
// int parameter, so arguments will be passed to it by value.
|
||||
func zeroval(ival int) {
|
||||
ival = 0
|
||||
}
|
||||
// has an *int parameter, meaning that it takes an int pointer.
|
||||
func zeroptr(iptr *int) {
|
||||
*iptr = 0
|
||||
}
|
||||
func main() {
|
||||
i := 1
|
||||
fmt.Println("initial:", i) // prt initial: 1
|
||||
zeroval(i)
|
||||
fmt.Println("zeroval:", i) // prt zeroval: 1
|
||||
zeroptr(&i)
|
||||
fmt.Println("zeroptr:", i) // prt zeroptr: 0
|
||||
fmt.Println("pointer:", &i) // prt pointer: 0xc0000140b8
|
||||
}
|
||||
27
Task/Call-a-function/Go/call-a-function-12.go
Normal file
27
Task/Call-a-function/Go/call-a-function-12.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func mkAdd(a int) func(int) int {
|
||||
return func(b int) int {
|
||||
return a + b
|
||||
}
|
||||
}
|
||||
func sum(x, y int) int {
|
||||
return x + y
|
||||
}
|
||||
|
||||
func partialSum(x int) func(int) int {
|
||||
return func(y int) int {
|
||||
return sum(x, y)
|
||||
}
|
||||
}
|
||||
func main() {
|
||||
// Is partial application possible and how
|
||||
add2 := mkAdd(2)
|
||||
add3 := mkAdd(3)
|
||||
fmt.Println(add2(5), add3(6)) // prt 7 9
|
||||
// Currying functions in go
|
||||
partial := partialSum(13)
|
||||
fmt.Println(partial(5)) //prt 18
|
||||
}
|
||||
|
|
@ -1 +1,14 @@
|
|||
if 2*g(1, 3.0)+4 > 0 {}
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Params struct {
|
||||
a, b, c int
|
||||
}
|
||||
func doIt(p Params) int {
|
||||
return p.a + p.b + p.c
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Println(doIt(Params{a: 1, c: 9})) // prt 10
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,15 @@
|
|||
fn := func(r rune) rune {
|
||||
if unicode.IsSpace(r) {
|
||||
return -1
|
||||
}
|
||||
return r
|
||||
}
|
||||
strings.Map(fn, "Spaces removed")
|
||||
strings.Map(unicode.ToLower, "Test")
|
||||
strings.Map(func(r rune) rune { return r + 1 }, "shift")
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func bar(a, b, c int) {
|
||||
fmt.Printf("%d, %d, %d", a, b, c)
|
||||
}
|
||||
|
||||
func main() {
|
||||
args := make(map[string]int)
|
||||
args["a"] = 3
|
||||
args["b"] = 2
|
||||
args["c"] = 1
|
||||
bar(args["a"], args["b"], args["c"]) // prt 3, 2, 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1 @@
|
|||
a, b := f() // multivalue return
|
||||
_, c := f() // only some of a multivalue return
|
||||
d := g(a, c) // single return value
|
||||
e, i := g(d, b), g(d, 2) // multiple assignment
|
||||
if 2*g(1, 3.0)+4 > 0 {}
|
||||
|
|
|
|||
|
|
@ -1,2 +1,9 @@
|
|||
list = append(list, a, d, e, i)
|
||||
i = len(list)
|
||||
fn := func(r rune) rune {
|
||||
if unicode.IsSpace(r) {
|
||||
return -1
|
||||
}
|
||||
return r
|
||||
}
|
||||
strings.Map(fn, "Spaces removed")
|
||||
strings.Map(unicode.ToLower, "Test")
|
||||
strings.Map(func(r rune) rune { return r + 1 }, "shift")
|
||||
|
|
|
|||
4
Task/Call-a-function/Go/call-a-function-9.go
Normal file
4
Task/Call-a-function/Go/call-a-function-9.go
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
a, b := f() // multivalue return
|
||||
_, c := f() // only some of a multivalue return
|
||||
d := g(a, c) // single return value
|
||||
e, i := g(d, b), g(d, 2) // multiple assignment
|
||||
|
|
@ -64,13 +64,13 @@
|
|||
; ==> a: 3
|
||||
; ==> b: 13
|
||||
; or nicer (and shorter) form available from ol version 2.1
|
||||
(named-args-function '{(a . 3)})
|
||||
(named-args-function '{a 3})
|
||||
; ==> a: 3
|
||||
; ==> b: 13
|
||||
(named-args-function '{(b . 7)})
|
||||
(named-args-function '{b 7})
|
||||
; ==> a: 8
|
||||
; ==> b: 7
|
||||
(named-args-function '{(a . 3) (b . 7)})
|
||||
(named-args-function '{a 3 b 7})
|
||||
; ==> a: 3
|
||||
; ==> b: 7
|
||||
|
||||
|
|
|
|||
91
Task/Call-a-function/Perl-6/call-a-function-11.pl6
Normal file
91
Task/Call-a-function/Perl-6/call-a-function-11.pl6
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
{
|
||||
state $n;
|
||||
|
||||
multi f () { print ' f' ~ ++$n }
|
||||
multi f ($a) { die if 1 != $a; print ' f' ~ ++$n }
|
||||
multi f ($a,$b) { die if 3 != $a+$b; print ' f' ~ ++$n }
|
||||
multi f (@a) { die if @a != [2,3,4]; print ' f' ~ ++$n }
|
||||
multi f ($a,$b,$c) { die if 2 != $a || 4 != $c; print ' f' ~ ++$n }
|
||||
sub g ($a,*@b) { die if @b != [2,3,4] || 1 != $a; print ' g' ~ ++$n }
|
||||
|
||||
my \i = -> { print ' i' ~ ++$n }
|
||||
my \l = -> $a { die if 1 != $a; print ' l' ~ ++$n }
|
||||
my \m = -> $a,$b { die if 1 != $a || 2 != $b; print ' m' ~ ++$n }
|
||||
my \n = -> @a { die if @a != [2,3,4]; print ' n' ~ ++$n }
|
||||
|
||||
Int.^add_method( 'j', method ()
|
||||
{ die if 1 != self; print ' j' ~ ++$n } );
|
||||
Int.^add_method( 'k', method ($a)
|
||||
{ die if 1 != self || 2 != $a; print ' k' ~ ++$n } );
|
||||
Int.^add_method( 'h', method (@a)
|
||||
{ die if @a != [2,3,4] || 1 != self; print ' h' ~ ++$n } );
|
||||
|
||||
my $ref = &f; # soft ref
|
||||
my $f := &f; # hard ref
|
||||
my $g := &g; # hard ref
|
||||
my $f-sym = '&f'; # symbolic ref
|
||||
my $g-sym = '&g'; # symbolic ref
|
||||
my $j-sym = 'j'; # symbolic ref
|
||||
my $k-sym = 'k'; # symbolic ref
|
||||
my $h-sym = 'h'; # symbolic ref
|
||||
|
||||
# Calling a function with no arguments:
|
||||
|
||||
f; # 1 as list operator
|
||||
f(); # 2 as function
|
||||
i.(); # 3 as function, explicit postfix form # defined via pointy-block
|
||||
$ref(); # 4 as object invocation
|
||||
$ref.(); # 5 as object invocation, explicit postfix
|
||||
&f(); # 6 as object invocation
|
||||
&f.(); # 7 as object invocation, explicit postfix
|
||||
::($f-sym)(); # 8 as symbolic ref
|
||||
|
||||
# Calling a function with exactly one argument:
|
||||
|
||||
f 1; # 9 as list operator
|
||||
f(1); # 10 as named function
|
||||
l.(1); # 11 as named function, explicit postfix # defined via pointy-block
|
||||
$f(1); # 12 as object invocation (must be hard ref)
|
||||
$ref.(1); # 13 as object invocation, explicit postfix
|
||||
1.$f; # 14 as pseudo-method meaning $f(1) (hard ref only)
|
||||
1.$f(); # 15 as pseudo-method meaning $f(1) (hard ref only)
|
||||
1.&f; # 16 as pseudo-method meaning &f(1) (is hard f)
|
||||
1.&f(); # 17 as pseudo-method meaning &f(1) (is hard f)
|
||||
1.j; # 18 as method via dispatcher # requires custom method, via 'Int.^add_method'
|
||||
1.j(); # 19 as method via dispatcher
|
||||
1."$j-sym"(); # 20 as method via dispatcher, symbolic
|
||||
|
||||
# Calling a function with exactly two arguments:
|
||||
|
||||
f 1,2; # 21 as list operator
|
||||
f(1,2); # 22 as named function
|
||||
m.(1,2); # 23 as named function, explicit postfix # defined via pointy-block
|
||||
$ref(1,2); # 24 as object invocation (must be hard ref)
|
||||
$ref.(1,2); # 25 as object invocation, explicit postfix
|
||||
1.$f: 2; # 26 as pseudo-method meaning $f(1,2) (hard ref only)
|
||||
1.$f(2); # 27 as pseudo-method meaning $f(1,2) (hard ref only)
|
||||
1.&f: 2; # 28 as pseudo-method meaning &f(1,2) (is hard f)
|
||||
1.&f(2); # 29 as pseudo-method meaning &f(1,2) (is hard f)
|
||||
1.k: 2; # 30 as method via dispatcher # requires custom method, via 'Int.^add_method'
|
||||
1.k(2); # 31 as method via dispatcher
|
||||
1."$k-sym"(2); # 32 as method via dispatcher, symbolic
|
||||
|
||||
# Calling a function with a variable number of arguments (varargs):
|
||||
|
||||
my @args = 2,3,4;
|
||||
|
||||
f @args; # 33 as list operator
|
||||
f(@args); # 34 as named function
|
||||
n.(@args); # 35 as named function, explicit postfix # defined via pointy-block
|
||||
$ref(@args); # 36 as object invocation (must be hard ref)
|
||||
$ref.(@args); # 37 as object invocation, explicit postfix
|
||||
1.$g: @args; # 38 as pseudo-method meaning $f(1,@args) (hard ref)
|
||||
1.$g(@args); # 39 as pseudo-method meaning $f(1,@args) (hard ref)
|
||||
1.&g: @args; # 40 as pseudo-method meaning &f(1,@args)
|
||||
1.&g(@args); # 41 as pseudo-method meaning &f(1,@args)
|
||||
1.h: @args; # 42 as method via dispatcher # requires custom method, via 'Int.^add_method'
|
||||
1.h(@args); # 43 as method via dispatcher
|
||||
1."$h-sym"(@args); # 44 as method via dispatcher, symbolic
|
||||
f(|@args); # 45 equivalent to f(1,2,3)
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue