Skip to content

Instantly share code, notes, and snippets.

@cthom06
Created July 21, 2011 12:19
Show Gist options
  • Save cthom06/1097077 to your computer and use it in GitHub Desktop.
Save cthom06/1097077 to your computer and use it in GitHub Desktop.
========= ./examples/1linefac.pet =========
fac:=|x{if(x|{x*fac(x-1)}|{1})}main:=|{x:=2*2y:=6+1print("fac(x)"fac(x)"fac(y)"fac(y))}main()
--------------------------------------
fac(x) 24 fac(y) 5040
========= ./examples/badscope.pet =========
bad := | {
i = i + 3
}
main := | {
i := 4
bad()
print("i =" i)
}
main()
--------------------------------------
i = 7
========= ./examples/fac.pet =========
n! := | x {
if( x
| { x * n!(x - 1) }
| { 1 }
)
}
main := | {
print("n!(3) =" n!(3))
print("n!(4) =" n!(4))
print("n!(5) =" n!(5))
}
main()
--------------------------------------
n!(3) = 6
n!(4) = 24
n!(5) = 120
========= ./examples/hello.pet =========
main := | {
print("Hello, world")
}
main()
--------------------------------------
Hello, world
========= ./examples/noterm.pet =========
main := | {
print(3 + 3 1 + 1 + 2 + 4 5 * 5 6 - 6 7 + (2 * 2))
print("That shouldve been 6 8 25 0 11")
}
main()
--------------------------------------
6 8 25 0 11
That shouldve been 6 8 25 0 11
========= ./examples/point.pet =========
point := [
x 0
y 0
combine |self p2 {
self.x = self.x + p2.x
self.y = self.y + p2.y
}
]
main := | {
r := new(point)
r.x = 3 r.y = 2
point.x = 7
r2 := new(point)
r2.y = 1
r.combine(r2)
print("r x:" r.x "y:" r.y)
print("r2 x:" r2.x "y:" r2.y)
}
main()
--------------------------------------
r x: 10 y: 3
r2 x: 7 y: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment