Finish up old example that shows off basic expressions and funcalls
The VM now supports the various int comparison methods. An example of a "pow" method is given to show off recursion, which means we're now TURING COMPLETE! Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
# pow = fn (n, p) {
|
||||
# if p == 0 {
|
||||
# 1
|
||||
# } else {
|
||||
# n * pow(n, p - 1)
|
||||
# }
|
||||
# }
|
||||
pow = fn (n, p) {
|
||||
if p <= 0 {
|
||||
return 1
|
||||
} el {
|
||||
return n * pow(n, p - 1)
|
||||
}
|
||||
}
|
||||
|
||||
kilo = pow(2, 10)
|
||||
mega = pow(2, 20)
|
||||
giga = pow(2, 30)
|
||||
tera = pow(2, 40)
|
||||
peta = pow(2, 50)
|
||||
|
||||
println(kilo)
|
||||
println(mega)
|
||||
println(giga)
|
||||
|
||||
Reference in New Issue
Block a user