Permalink
Browse files

First version of satisfying samples

  • Loading branch information...
1 parent b3eeb37 commit 2b03aa1bb95f745667a44eb9faf8c69eb245f6e4 Amos Wenger committed Jun 7, 2012
Showing with 101 additions and 13 deletions.
  1. +27 −0 samples/arraylist-vanilla.ooc
  2. +7 −12 samples/jar.ooc
  3. +16 −1 samples/list.ooc
  4. +51 −0 samples/tuple.ooc
@@ -0,0 +1,27 @@
+import structs/ArrayList
+
+#specialize ArrayList<Char>
+
+test1: func {
+ ar := ArrayList<Int> new()
+ ar add(1). add(2). add(3)
+
+ for (i in 0..ar size) {
+ printf("%d", ar get(i))
+ }
+}
+
+test2: func {
+ ar := ArrayList<Char> new()
+ ar add('a'). add('b'). add('c')
+
+ for (i in 0..ar size) {
+ printf("%c", ar get(i))
+ }
+}
+
+main: func {
+ test1()
+ test2()
+}
+
View
@@ -1,25 +1,20 @@
Jar: class <X> {
- cookie: X
+ _cookie: X
- //ostracize: func (=cookie) { }
-
- ostracize: func (cookie: X) {
- this cookie = cookie
- }
-
- getCookie: func -> X { cookie }
+ cookie: func -> X { _cookie }
+ cookie: func ~set (=_cookie)
}
#specialize Jar<Char> // binks
main: func {
j := Jar<Int> new()
- j ostracize(99)
- printf("j's cookie = %d\n", j getCookie())
+ j cookie(99)
+ printf("j's cookie = %d\n", j cookie())
k := Jar<Char> new()
- k ostracize('c')
- printf("k's cookie = %d\n", k getCookie())
+ k cookie('c')
+ printf("k's cookie = %d\n", k cookie())
}
View
@@ -16,7 +16,9 @@ List: class <X> {
}
}
-#specialize List<Char>
+Letter: cover from Char { }
+
+#specialize List<Letter>
test1: func {
l := List<Char> new(3)
@@ -30,6 +32,19 @@ test1: func {
println()
}
+test2: func {
+ l := List<Letter> new(3)
+ l set(0, 'f' as Letter)
+ l set(1, 'a' as Letter)
+ l set(2, 'q' as Letter)
+
+ for (i in 0..l size) {
+ printf("%c", l get(i))
+ }
+ println()
+}
+
main: func {
test1()
+ test2()
}
View
@@ -0,0 +1,51 @@
+
+Tuple: class <G, H> {
+ _car: G
+ _cdr: H
+
+ car: func -> G { _car }
+ cdr: func -> H { _cdr }
+
+ init: func (=_car, =_cdr)
+}
+
+Vector3: cover {
+ x, y, z: Float
+
+ init: func@ (=x, =y, =z)
+
+ repr: func -> String {
+ "(%.2f, %.2f, %.2f)" format(x, y, z)
+ }
+}
+
+#specialize Tuple<String, Char>
+#specialize Tuple<String, Int>
+#specialize Tuple<String, Vector3>
+
+test1: func {
+ t := Tuple<String, Char> new("initial", 'a')
+ "%s = %c" printfln(t car(), t cdr())
+}
+
+test2: func {
+ t := Tuple<String, Int> new("age", 21 as Int)
+ "%s = %d" printfln(t car(), t cdr())
+}
+
+test3: func {
+ t := Tuple<String, Vector3> new("size", Vector3 new(0.4, 0.25, 1.93))
+ "%s = %s" printfln(t car(), t cdr() repr())
+}
+
+test4: func {
+ t := Tuple<String, String> new("name", "John Doe")
+ "%s = %s" printfln(t car(), t cdr())
+}
+
+main: func {
+ test1()
+ test2()
+ test3()
+ test4()
+}

0 comments on commit 2b03aa1

Please sign in to comment.