This commit is contained in:
Ingy döt Net 2013-04-10 21:29:02 -07:00
parent 764da6cbbb
commit db842d013d
19005 changed files with 197040 additions and 7 deletions

View file

@ -0,0 +1,8 @@
vect = [ 'alpha', 'beta', 'gamma' ]
vect.dump = function ()
for n in [0: self.len()]
> @"$(n): ", self[n]
end
end
vect += 'delta'
vect.dump()

View file

@ -0,0 +1,4 @@
0: alpha
1: beta
2: gamma
3: delta

View file

@ -0,0 +1,15 @@
function sub_func( value )
self['prop'] -= value
return self.prop
end
dict = bless( [
'prop' => 0,
'add' => function ( value )
self.prop += value
return self.prop
end ,
'sub' => sub_func
])
dict[ 'newVar' ] = "I'm Rich In Data"

View file

@ -0,0 +1,6 @@
class A {
final x = { it + 25 }
private map = new HashMap()
Object get(String key) { map[key] }
void set(String key, Object value) { map[key] = value }
}

View file

@ -0,0 +1,9 @@
def a = new A()
a.y = 55
a.z = { println (new Date()); Thread.sleep 5000 }
println a.x(25)
println a.y
(0..2).each(a.z)
println a.q

View file

@ -0,0 +1,27 @@
link ximage
procedure main()
c1 := foo(1,2) # instance of foo
write("c1:\n",ximage(c1))
c1 := extend(c1,["c","d"],[8,9]) # 2 new fields
write("new c1:\n",ximage(c1))
c1 := extend(c1,["e"],[7]) # 1 more
write("newest c1:\n",ximage(c1))
end
class foo(a,b) # dummy class
end
procedure extend(instance,newvars,newvals) #: extend a class instance
every put(f := [],fieldnames(instance)) # copy existing fieldnames
c := ["tempconstructor"] ||| f # new constructor
every put(c,!newvars) # append new vars
t := constructor!c # new constructor
x := t() # new instance
every x[v := !f] := instance[v] # same as old instance
x.__s := x # new self
if \newvals then
every i := 1 to min(*newvars,*newvals) do
x[newvars[i]] := newvals[i] # add new vars = values
return x
end

View file

@ -0,0 +1,4 @@
Empty := Object clone
e := Empty clone
e foo := 1

View file

@ -0,0 +1,13 @@
C=:<'exampleclass' NB. this will be our class name
V__C=: 0 NB. ensure the class exists
OBJ1=:conew 'exampleclass' NB. create an instance of our class
OBJ2=:conew 'exampleclass' NB. create another instance
V__OBJ1,V__OBJ2 NB. both of our instances exist
0
W__OBJ1 NB. instance does not have a W
|value error
W__OBJ1=: 0 NB. here, we add a W to this instance
W__OBJ1 NB. this instance now has a W
0
W__OBJ2 NB. our other instance does not
|value error

View file

@ -0,0 +1,21 @@
HAI 1.3
I HAS A object ITZ A BUKKIT
I HAS A name, I HAS A value
IM IN YR interface
VISIBLE "R U WANTIN 2 (A)DD A VAR OR (P)RINT 1? "!
I HAS A option, GIMMEH option
option, WTF?
OMG "A"
VISIBLE "NAME: "!, GIMMEH name
VISIBLE "VALUE: "!, GIMMEH value
object HAS A SRS name ITZ value, GTFO
OMG "P"
VISIBLE "NAME: "!, GIMMEH name
VISIBLE object'Z SRS name
OIC
IM OUTTA YR interface
KTHXBYE