Commits

Anonymous committed 1d2821b

more and more

  • Participants
  • Parent commits 2100fc5

Comments (0)

Files changed (1)

+// from http://code.google.com/apis/v8/get_started.html
+#include <v8.h>
+
+using namespace v8;
+
+int main(int argc, char* argv[]) {
+
+  // Create a stack-allocated handle scope.
+  HandleScope handle_scope;
+
+  // Create a new context.
+  Persistent<Context> context = Context::New();
+  
+  // Enter the created context for compiling and
+  // running the hello world script. 
+  Context::Scope context_scope(context);
+
+  // Create a string containing the JavaScript source code.
+  //  Handle<String> source = String::New("'Hello' + ', World!'");
+  // Handle<String> source = String::New("[32, 234, 23/4, {asfd:\"asdf\"}, \"hello\"];");
+  //  Handle<String> source = String::New("{ someatom: 23, anotheratom: 3.3 };");
+  const char* code =
+    "function id(x){  return x; } "
+    "function add(x, y){ return x+y; } "
+    "function map(f, l){ var ret = []; for(var i=0, len=l.length; i<len; i++ ) {"
+    "   ret[i] = f(l[i]); } return ret; }"
+    "function fold(f, acc0, l){ var ret = acc0; for(var i=0, len=l.length; i<len; i++ ) {"
+    "   ret = f(l[i], ret); } return ret; }"
+    "fold(add, 0, map(id, [10, 23, 23]));"
+    ;
+  Handle<String> source = String::New(code);
+
+  // Compile the source code.
+  Handle<Script> script = Script::Compile(source);
+  
+  // Run the script to get the result.
+  Handle<Value> result = script->Run();
+  
+  // Dispose the persistent context.
+  context.Dispose();
+
+  // Convert the result to an ASCII string and print it.
+  String::AsciiValue ascii(result);
+  printf("%s\n", *ascii);
+  return 0;
+}
+
+
+// query language
+// push_back(Key, Value)
+// pop_front(Key)
+// single_query(Key, Code)
+// Code: (map :: a -> b, reduce :: b -> b -> b)
+// multi_query(Key0, Key1, Code)
+// Code: (map0 :: a -> b -> c, ...)
+