Permalink
Browse files

Added example programs.

  • Loading branch information...
1 parent 6af837f commit 14483008a69e826b547453d6f083b84a9703ca30 @aarongough committed Sep 1, 2010
Showing with 48 additions and 0 deletions.
  1. +13 −0 examples/blast_off.koi
  2. +10 −0 examples/high_order_functions.koi
  3. +25 −0 examples/iterator.koi
@@ -0,0 +1,13 @@
+countdown = function( count )
+ print( to_string( count ))
+ print( ", " )
+ if( count == 0 )
+ return()
+ end
+ count = count - 1
+ call( countdown, count )
+end
+
+call( countdown, 10 )
+
+print( "Blast Off!" )
@@ -0,0 +1,10 @@
+new_function = function(arg)
+ func = function(arg)
+ print("Dynamically created function")
+ end
+ return( func )
+end
+
+func = call( new_function, nil )
+
+call( func, nil )
View
@@ -0,0 +1,25 @@
+test = { 0 => "element 1", 1 => "element 1", 2 => "element 3", 3 => "element 4" }
+
+iterator = function(hash)
+ index = hash["counter"]
+
+ if( index == nil )
+ hash["counter"] = 0
+ index = 0
+ end
+
+ content = hash[index]
+
+ if( type_of(content) == "string")
+ print( content )
+ end
+
+ if( content == nil )
+ return()
+ end
+
+ hash[counter] = index + 1
+ call( iterator, hash )
+end
+
+call( iterator, test )

0 comments on commit 1448300

Please sign in to comment.