Just another update

This commit is contained in:
Ingy döt Net 2015-02-20 00:35:01 -05:00
parent a25938f123
commit 00a190b0a6
6591 changed files with 94363 additions and 23227 deletions

View file

@ -0,0 +1,21 @@
--assume A, B and C to be valid classes
class X
feature -- alias for "feature {ANY}"
-- ANY is the class at the top of the class hierarchy and all classes inherit from it
-- features following this clause are given "global" scope: these features are visible to every class
feature {A, B, C, X}
-- features following this clause are only visible to the specified classes (and their descendants)
-- classes not in this set do not even know of the existence of these features
feature {A, B, C}
-- similar to above, except other instances of X cannot access these features
feature {X}
-- features following this clause are only visible to instances of X (and its descendants)
feature {NONE}
-- NONE is the class at the bottom of the class hierarchy and inherits from every class
-- features following this clause are only visible to this particular instance of X
end

View file

@ -0,0 +1,24 @@
package main
import (
"fmt"
"runtime"
"ex"
)
func main() {
// func nested() { ... not allowed here
// this is okay, variable f declared and assigned a function literal.
f := func() {
// this mess prints the name of the function to show that it's an
// anonymous function defined in package main
pc, _, _, _ := runtime.Caller(0)
fmt.Println(runtime.FuncForPC(pc).Name(), "here!")
}
ex.X(f) // function value passed to exported function
// ex.x() non-exported function not visible here
}

View file

@ -0,0 +1,17 @@
package ex
import (
"fmt"
"runtime"
)
// X is exported.
func X(x func()) {
pc, _, _, _ := runtime.Caller(0)
fmt.Println(runtime.FuncForPC(pc).Name(), "calling argument x...")
x()
}
func x() { // not exported, x not upper case.
panic("top level x")
}

View file

@ -0,0 +1,29 @@
package main
import "fmt"
func main() {
// labels loop and y both in scope of main
loop:
for false {
continue loop
}
goto y
y:
y := 0 // variable namespace is separate from label namespace
func() {
// goto loop ...loop not visible from this literal
// label y in outer scope not visible so it's okay to define a label y
// here too.
y:
for {
break y
}
y++ // regular lexical scoping applies to variables.
}()
fmt.Println(y)
}
// end: // labels not allowed outside function blocks

View file

@ -1,13 +1,17 @@
/*REXX program demonstrates use of labels and a CALL. */
/*REXX program demonstrates use of labels and a CALL statement. */
zz=4
signal do_add
ttt=sinD(30) /*this REXX statement is never executed.*/
signal do_add /*transfer program control to a label.*/
ttt=sinD(30) /*this REXX statement is never executed.*/
/* [↓] Note the case doesn't matter. */
do_Add: /*coming here from the SIGNAL statement.*/
do_add: /*coming here from the SIGNAL statement.*/
say 'calling the sub: add.2.args'
call add.2.args 1,7 /*pass two arguments: 1 and a 7 */
say 'sum =' result
exit /*stick a fork in it, 'cause we're done.*/
/*────────────────────────────────subroutines (or functions)────────────*/
add.2.args: procedure; parse arg x,y; return x+y
say 'calling the sub add.2.args'
call add.2.args 1,7
say 'sum=' result
exit /*stick a fork in it, 'cause we're done.*/
add.2.args: procedure; parse arg x,y; return x+y
add.2.args: say 'Whoa Nelly!! Has the universe run amok?'
/* [↑] dead code, never XEQed*/
add.2.args: return arg(1) + arg(2) /*concise, but never executed.*/