Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,29 @@
type Foo int // some custom type
// method on the type itself; can be called on that type or its pointer
func (self Foo) ValueMethod(x int) { }
// method on the pointer to the type; can be called on pointers
func (self *Foo) PointerMethod(x int) { }
var myValue Foo
var myPointer *Foo = new(Foo)
// Calling value method on value
myValue.ValueMethod(someParameter)
// Calling pointer method on pointer
myPointer.PointerMethod(someParameter)
// Value methods can always be called on pointers
// equivalent to (*myPointer).ValueMethod(someParameter)
myPointer.ValueMethod(someParameter)
// In a special case, pointer methods can be called on values that are addressable (i.e. lvalues)
// equivalent to (&myValue).PointerMethod(someParameter)
myValue.PointerMethod(someParameter)
// You can get the method out of the type as a function, and then explicitly call it on the object
Foo.ValueMethod(myValue, someParameter)
(*Foo).PointerMethod(myPointer, someParameter)
(*Foo).ValueMethod(myPointer, someParameter)

View file

@ -0,0 +1,29 @@
package box
import "sync/atomic"
var sn uint32
type box struct {
Contents string
secret uint32
}
func New() (b *box) {
b = &box{secret: atomic.AddUint32(&sn, 1)}
switch sn {
case 1:
b.Contents = "rabbit"
case 2:
b.Contents = "rock"
}
return
}
func (b *box) TellSecret() uint32 {
return b.secret
}
func Count() uint32 {
return atomic.LoadUint32(&sn)
}

View file

@ -0,0 +1,16 @@
package main
import "box"
func main() {
// Call constructor. Technically it's just an exported function,
// but it's a Go idiom to naming a function New that serves the purpose
// of a constructor.
b := box.New()
// Call instance method. In Go terms, simply a method.
b.TellSecret()
// Call class method. In Go terms, another exported function.
box.Count()
}

View file

@ -0,0 +1,23 @@
procedure main()
bar := foo() # create instance
bar.m2() # call method m2 with self=bar, an implicit first parameter
foo_m1( , "param1", "param2") # equivalent of static class method, first (self) parameter is null
end
class foo(cp1,cp2)
method m1(m1p1,m1p2)
local ml1
static ms1
ml1 := m1p1
# do something
return
end
method m2(m2p1)
# do something else
return
end
initially
L := [cp1]
end