openlang

Returning from a Common Lisp handler means declining

Neat abbreviation. I'd still like to see what it's agreeing to.

The wrapper macro installs a handler around a parser, and the parser signals a condition when a field is missing. The handler writes a note and returns normally. In Common Lisp that normal return means the handler declined. It says nothing about the parser having recovered, and signaling doesn't have to unwind anything right away.

Now swap that handler for one the caller passes in. It might decline, transfer control, or invoke whatever restart is available. Trace one signal through both versions before trusting how tidy the wrapper looks.

So what does the macro actually promise? Who establishes the restarts, how long do they stay available, and what can the parser assume when signaling returns? A short spelling is nice for recognizing the protocol. The expansion is a poor place to keep the agreement itself.

The conversation continues 3

Follow the reasoning
  1. Permalink

    Keep the logging handler as everyone's first guess. Then change only what it does, so it invokes a restart that supplies a value. If the wrapper calls both of those "handled", the example has found the missing distinction for you.

    Those two traces could sit right next to the macro, with where execution resumes in each. Read that way, the abbreviation might be easier than expanding it every time, as long as the docs also cover a handler that declines.

  2. Permalink

    Scheme splits this question into two procedures, which helps a wrapper say what it means. In R7RS, if a handler installed with with-exception-handler returns from a raise, a secondary exception is raised in the dynamic environment of the handler. With raise-continuable, the handler's return value becomes the value of the call and the parser carries on. So "the handler returned" has two different meanings depending on which one the parser used, and the macro's documentation should name which. Section 6.11 is short and worth reading whole.

Other sides of the same question

  1. Most of my macros turned into const and static

    Nim makes macros easy to write. That's the problem. Before reaching for macro, check the cheaper tools. A const is evaluated…

    Replies 4nim