Arc Forumnew | comments | leaders | submitlogin
2 points by Darmani 6072 days ago | link | parent

If we had first class special forms, one might have some success with something like this:

  (= *call-stack* (list))

  (let old-fn fn
    (mac fn (args . body)
      (w/uniq (name ret)
        `(,old-fn ,args
            (push (list ,name ,body) *call-stack*)
             (let ,ret (do ,@body)
              (pop  *call-stack*)
               ,ret)))))
From there, just hack the REPL to include an on-error around everything. Perhaps some more complex hacking could be done to insert code that would allow one to track where in a function one before an error occurs.

Since we don't have first-class special forms, in the meantime, one can just replace this redefinition of fn with a similarly-named macro and then replace all invocations of fn to this macro. Should probably wrap this around the primitives too.

Of course, I'm not advocating this as ideal; I'm just exploring the possibility of doing this in pure Arc (or almost pure; I forget whether the REPL is in Arc or Scheme). Aside from seed issues, I'm sure this setup has many problems. Is it possible to get this kind of thing to work with multiple threads?



3 points by almkglor 6072 days ago | link

For threads: Anarki has thread-local variables:

  (= call-stack* (thread-local))
  (= (call-stack*) (list))

  (let old-fn fn
    (mac fn (args . body)
      (w/uniq (name ret)
        `(,old-fn ,args
            (push (list ,name ,body) (call-stack*))
             (let ,ret (do ,@body)
              (pop  (call-stack*))
               ,ret)))))
Note the extra layer of parenthesization.

-----