# Commits

committed 7a8c0bb

Fix example programs' syntax. Add another exciting example.

• Participants
• Parent commits 2b11fb4

# Files changed (4)

`+fun main() {`
`+  var a = 0;`
`+  var c = "";`
`+  while true {`
`+    if a == 256 or a < 0 {`
`+	a = 0;`
`+    }`
`+    c = input(">> ");`
`+    if c == "i" {`
`+        a = a + 1;`
`+    } else if c == "d" {`
`+        a = a - 1;`
`+    } else if c == "s" {`
`+        a = a * a;`
`+    } else if c == "o" {`
`+        print(str(a));`
`+    }`
`+  }`
`+}`

# File eg/factorial.castile

`-factorial: function(integer): integer`
`+factorial: integer -> integer`
` fun factorial(a) {`
`   if (a == 0) {`
`     return 1`
` }`
` `
` fun main() {`
`-  var n = 0 as integer in union(integer, void);`
`+  var n = 0 as integer|void;`
`   var s = "";`
`   print("Enter integer to obtain factorial of it, or 'q' to quit.");`
`   while true {`

` struct list {`
`   value: string;`
`-  next: union(list, void);`
`+  next: list|void;`
` }`
` `
` fun empty() {`
`-  return null as void in union(list, void)`
`+  return null as list|void`
` }`
` `
`-fun cons(v: string, l: union(list, void)) {`
`-  make list(value:v, next:l) as list in union(list, void)`
`+fun cons(v: string, l: list|void) {`
`+  make list(value:v, next:l) as list|void`
` }`
` `
` main = fun() {`

# File eg/typecase.castile

`-fun foo(a, b: union(integer, string)) {`
`+fun foo(a, b: integer|string) {`
`   var r = a;`
`   typecase b is integer {`
`     r = r + b;`
` }`
` main = fun() {`
`   var a = 0;`
`-  a = foo(a, 333 as integer in union(integer, string));`
`-  a = foo(a, "hiya" as string in union(integer, string));`
`-  a`
`+  a = foo(a, 333 as integer|string);`
`+  a = foo(a, "hiya" as integer|string);`
`+  a /* should output 337 */`
` }`