September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,10 @@
|
|||
f(1) /* First output line */
|
||||
define f(x) {
|
||||
return(x)
|
||||
}
|
||||
f(3) /* Second output line */
|
||||
|
||||
define f(x) {
|
||||
return(x - 1)
|
||||
}
|
||||
f(3) /* Third output line */
|
||||
|
|
@ -14,7 +14,7 @@ int main(void)
|
|||
int x;
|
||||
|
||||
printf("This will demonstrate function and label scopes.\n");
|
||||
printf("All output is happening throung printf(), a function declared in the header stdio.h, which is external to this program.\n");
|
||||
printf("All output is happening through printf(), a function declared in the header stdio.h, which is external to this program.\n");
|
||||
printf("Enter a number: ");
|
||||
if (scanf("%d", &x) != 1)
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
add3 :: Int -> Int-> Int-> Int
|
||||
add3 x y z = add2 x y + z
|
||||
|
||||
add2 :: Int -> Int -> Int
|
||||
add2 x y = x + y
|
||||
|
||||
main :: putStrLn(show (add3 5 6 5))
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
getSquaredSum :: Int-> Int-> Int
|
||||
getSquaredSum x y = g x + h y
|
||||
where
|
||||
g a = a*a
|
||||
h b = b*b
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
// version 1.1.2
|
||||
|
||||
// top level function visible anywhere within the current module
|
||||
internal fun a() = println("calling a")
|
||||
|
||||
object B {
|
||||
// object level function visible everywhere, by default
|
||||
fun f() = println("calling f")
|
||||
}
|
||||
|
||||
open class C {
|
||||
// class level function visible everywhere, by default
|
||||
fun g() = println("calling g")
|
||||
|
||||
// class level function only visible within C
|
||||
private fun h() = println("calling h")
|
||||
|
||||
// class level function only visible within C and its subclasses
|
||||
protected fun i() {
|
||||
println("calling i")
|
||||
println("calling h") // OK as h within same class
|
||||
// nested function in scope until end of i
|
||||
fun j() = println("calling j")
|
||||
j()
|
||||
}
|
||||
}
|
||||
|
||||
class D : C(), E {
|
||||
// class level function visible anywhere within the same module
|
||||
fun k() {
|
||||
println("calling k")
|
||||
i() // OK as C.i is protected
|
||||
m() // OK as E.m is public and has a body
|
||||
}
|
||||
}
|
||||
|
||||
interface E {
|
||||
fun m() {
|
||||
println("calling m")
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
a() // OK as a is internal
|
||||
B.f() // OK as f is public
|
||||
val c = C()
|
||||
c.g() // OK as g is public but can't call h or i via c
|
||||
val d = D()
|
||||
d.k() // OK as k is public
|
||||
// labelled lambda expression assigned to variable 'l'
|
||||
val l = lambda@ { ->
|
||||
outer@ for (i in 1..3) {
|
||||
for (j in 1..3) {
|
||||
if (i == 3) break@outer // jumps out of outer loop
|
||||
if (j == 2) continue@outer // continues with next iteration of outer loop
|
||||
println ("i = $i, j = $j")
|
||||
}
|
||||
if (i > 1) println ("i = $i") // never executed
|
||||
}
|
||||
val n = 1
|
||||
if (n == 1) return@lambda // returns from lambda
|
||||
println("n = $n") // never executed
|
||||
}
|
||||
l() // invokes lambda
|
||||
println("Good-bye!") // will be executed
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
def welcome(name)
|
||||
puts "hello #{name}"
|
||||
end
|
||||
puts "What is your name?"
|
||||
$name = STDIN.gets
|
||||
welcome($name)
|
||||
return
|
||||
|
|
@ -0,0 +1 @@
|
|||
class C{ fcn [private] f{} }
|
||||
Loading…
Add table
Add a link
Reference in a new issue