Arc Forumnew | comments | leaders | submitlogin
Arc-style Web App programming in App Engine?
1 point by jazzdev 5149 days ago | 2 comments
I've been wondering if it's possible to use the Arc-style of web application development with Google App Engine. [By the way, is there a name for this style of web development?]

I already have Jarc running on App Engine, but how to deal with the closures? Since a compiler can find all the closed-over variables, it should be possible to syntactically transform:

  (defop hello req
    (let name "Chris"
      (w/link (pr "hello there, " name) 
        (pr "here"))))
into something like:

  (def /hello (req)
    (let name "Chris"
      (setAttribute req!Session "name" name)
      (a href '/g17 (pr "here"))))

  (def /g17 (req)
    (pr "hello there, " (getAttribute req!Session "name")))
With intermediate functions this gets much harder. News does something similar to this:

  (defop h1 req
    (let x 12
      (h2 (fn (req) ... x))))

  (def h2 (f)
    (taform nil
      (fn (req) ... (f req))))
Now I can't just do a syntatic rewrite. I'd need either:

1) A function that takes a closure and returns the list of closed-over variables and their values. Then taform could find that the closure it gets passed is closed over f. And then find out that f is a closure and it is closed over x. Then it could add the appropriate setAttribute calls.

AND

1b) A way to change the closure code to replace x with (getAttribute req!Session "x")

OR

2) A way to serialize (and unserialize) closures.

I think #2 would be easier to add to Jarc. At closure time, just find all the free variables that are bound in the current environment. Then the serialized form is something like:

  (let name "Chris"
    (fn (req) (pr "hello there, " name)))
Or in the more complicated example:

  (let f (let x 12 (fn (req) ... x))
    (fn (req) ... (f req)))
I'm not sure this is worth the effort, but does this seem like it would work? Or am I missing something?


1 point by conanite 5149 days ago | link

What does App Engine do to closures that requires Jarc to deal with them differently?

-----

2 points by jazzdev 5148 days ago | link

App Engine is a distributed web server, so you can't save a closure in memory on server A and have your next request handled by server B. I believe the only options are storing the closure in the distributed memory cache (memcache) or in the distributed persistence store (datastore). In either case you need to be able to serialize the closure.

-----