• Continuations via macros (was: Resources to learn common lisp?)

    From Stefan Monnier@monnier@iro.umontreal.ca to comp.lang.lisp on Fri Aug 28 16:36:29 2026
    From Newsgroup: comp.lang.lisp

    Paul Rubin [2026-08-27 13:01:44] wrote:
    antispam@fricas.org (Waldek Hebisch) writes:
    And normally functions do not return, simply tail-call to passed
    "continuation".
    Continuations are nontrivial precisely because of the non-tail-call
    case, where the continuation is re-used. So you can use them to
    implement coroutines, multitasking, etc. If they can't do that, they're
    not "full" continuations. I don't see how to implement full
    continuations using CL macros.

    Like most cases of "impossibility" the result depends on the details of
    the question:

    AFAIK it's impossible to implement support for `call/cc` via macros in
    Common Lisp *if* you want the affected code to be able to transparently
    call arbitrary "external" functions like (say) `mapcar`.

    OTOH, you can definitely implement a Common Lisp macro that takes as
    argument code written in a DSL which happens to be a language that looks exactly like Common Lisp except it includes a `call/cc` primitive
    (and in which you can (re)implement `mapcar`).

    There is some sentiment[1] in the Scheme world that mandating full continuations in Scheme was a mistake and that it would have been
    preferable to stop with "delimited" or "one-shot" continuations. Those
    are maybe closer to catch/throw than to coroutines. I don't know if
    those can be done with CL macros but it seems more plausible.

    AFAIK they bump into the same problem as `call/cc` w.r.t implementing
    them as macros.


    === Stefan
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From steve g@Sgonedes1977@gmail.com to comp.lang.lisp on Fri Sep 4 22:01:31 2026
    From Newsgroup: comp.lang.lisp

    Stefan Monnier <monnier@iro.umontreal.ca> writes:


    AFAIK it's impossible to implement support for `call/cc` via macros in
    Common Lisp *if* you want the affected code to be able to transparently
    call arbitrary "external" functions like (say) `mapcar`.

    OTOH, you can definitely implement a Common Lisp macro that takes as
    argument code written in a DSL which happens to be a language that looks exactly like Common Lisp except it includes a `call/cc` primitive
    (and in which you can (re)implement `mapcar`).

    There is some sentiment[1] in the Scheme world that mandating full
    continuations in Scheme was a mistake and that it would have been
    preferable to stop with "delimited" or "one-shot" continuations. Those
    are maybe closer to catch/throw than to coroutines. I don't know if
    those can be done with CL macros but it seems more plausible.

    AFAIK they bump into the same problem as `call/cc` w.r.t implementing
    them as macros.


    I have always wondered if using the environment would suffice as a inter-procedural reality. common-lisp is not very informative about
    this.

    (defmacro that (&env environment)
    (push 'this-is-true environment)
    (this))

    (defmacro this (&env environmenr)
    (how to you push or pop environment)..


    I suppose you could always use &aux ?
    --- Synchronet 3.22a-Linux NewsLink 1.2