TyOverby / ares

A Lisp made for easy integration with Rust.
9 stars 1 forks source link

Add debugger user-function #17

Closed TyOverby closed 9 years ago

TyOverby commented 9 years ago

As a demo of how powerful user-functions are, I think a "debugger" function could be added as an optional part of the standard library.

How it would work:

*Hitting the debugger user function would effectively "pause" the execution of the program and drop into a "mini-repl" which would have access to the surrounding scope and a few other debugger-based functions.

These functions are only valid inside of the debugger repl

bwo commented 9 years ago

Seems very much like part of a condition system.

On Saturday, October 3, 2015, Ty Overby notifications@github.com wrote:

As a demo of how powerful user-functions are, I think a "debugger" function could be added as an optional part of the standard library. How it would work:

*Hitting the debugger user function would effectively "pause" the execution of the program and drop into a "mini-repl" which would have access to the surrounding scope and a few other debugger-based functions.

  • While inside of the debugger, the repl would execute just like a regular repl would, despite being inside of a larger executing function.

Added Functions:

These functions are only valid inside of the debugger repl

  • (debugger-close valule) closes the debugger with a value to return to the running program.
  • (debugger-env) prints the environment to standard-out

— Reply to this email directly or view it on GitHub https://github.com/TyOverby/ares/issues/17.

Ben Wolfson "Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure." [Larousse, "Drink" entry]

TyOverby commented 9 years ago

Huh. I'll have to refresh myself on those. In the meantime, I just landed a commit adding a first-draft debugger in only 50 lines of code (implemented as a user-function too!).

Here's a snippit of a session from the repl:

repl> (define f (lambda () 
          (define b false) 
          (debugger) 
          b))
Lambda(<lambda>)
repl> (f)
debugger> (set b true)
Bool(true)
debugger> (debugger-close 0)
Bool(true) <-- this is the changed "b" value

In this case, we entered the debugger in the middle of the lambda - rewrote a local variable in the debugger-repl - and returned that modified value.

bwo commented 9 years ago

Basically they're exceptions that are handled at the place where the error condition arises, rather than where the handler is declared, which lets you do things like inspect the local environment and resume the computation. So the default, outermost handler could be like this debugger function, asking the user what to do, letting him/her poke around, etc. Not really feasible in general at this point since we'd need lisp-level datatypes to act as the error values. But given such types the implementation is pretty simple, you basically just need dynamic scopes or something like it, as in http://okmij.org/ftp/ML/resumable.ml