I thought I'd post an explanation of this error in case anyone else ran into it and was googling for it. In my case I have a web application that is parsing a bunch of request arguments and constructing an object out of them. If one of the arguments is invalid in some way, I want to return a 404 or similar HTTP response with an error code. A convenient way for me to program this is to use catch/throw, so that if an argument is invalid I break out of all the argument processing: (def parse-a (req throw)
(if ...a is invalid... (do ...return 404 response... (throw nil)))
...parse and return a...)
(catch
(let foo (obj a (parse-a req throw)
b (parse-b req throw)
...)
...process foo...
...return 200 OK response...))
However, when running in arc2, I get an MzScheme error when throw is called: Error: "continuation application: attempted to cross a continuation barrier"
Why? Here's the essence of the problem: arc> (catch (obj a (throw nil)))
Error: "continuation application: attempted to cross a continuation barrier"
which happens because (obj a x) expands into (let tmp (table)
(= (tmp 'a) x)
tmp)
and Arc expands some complex invocations of = into code that uses atwith, the version of with wrapped in atomic. And MzScheme doesn't allow you to escape out of atomic with a continuation: arc> (catch (atomic (throw nil)))
Error: "continuation application: attempted to cross a continuation barrier"
Here's the code in arc2/arc.arc that is expanding =: (def expand= (place val)
(if (and (isa place 'sym) (~ssyntax place))
`(set ,place ,val)
(let (vars prev setter) (setforms place)
(w/uniq g
`(atwith ,(+ vars (list g val))
(,setter ,g))))))
One option naturally is to avoid using Arc forms which invoke atomic when I'm using continuation escapes. But this isn't very pleasant, to have code that works fine until I start using catch/throw. Another fix is to replace the atwith in expand= with a plain with, and then my code starts working fine: arc> (catch (obj a (throw nil)))
nil
Presumably this has a good chance of breaking something in Hacker News which is relying on the more complex setters to be atomic, but I haven't yet grokked the design of which Arc forms are made atomic. |