I think I communicated poorly or we are talking past one another.

The standard says "it is an error for a <program> or <library> to include circular references except in literals."

That notation is referring to the formal syntax definition of <program> and <library> from section 7.1,
which means we are talking about the lexical structure of the program, not the resulting AST after macro expansion.

  '#0=(1 . #0#)

is a literal and therefore allowed, whereas

  (let-syntax ((q (syntax-rules () ((_ x) 'x))))
    (q #=0(1 . #0#)))

is not a literal but a cyclic expression passed to the macro expander which eventually gets quoted, and therefore an error.

That's pretty straightforward, I don't see much room for argument there.

If you wanted to allow more liberal use of such structures in a future standard,
you would need to provide a specification.  It seems you want to define this to
be any structure which eventually gets quoted in the AST, but I'm not sure that's
good for a standard.  The problem is it runs into too many implementation details
of both the macro expander and the macro implementation.  Thus you would
need to add some specification of what the expander is required to support, and
any macros defined in the standard or future SRFIs would need to specify
whether they are required to support cyclic arguments.  Otherwise everything
becomes (Scheme and macro) implementation-defined.

--
Alex

On Sat, Aug 29, 2020 at 12:03 AM Marc Nieper-Wißkirchen <xxxxxx@nieper-wisskirchen.de> wrote:
Am Fr., 28. Aug. 2020 um 16:24 Uhr schrieb Alex Shinn <xxxxxx@gmail.com>:
 
However, your interpretation that cyclic literals are therefore allowed in any macro that eventually quotes the cycle makes less sense.
To suggest that:

  '#=0(1 . #0#)  ; legal in R7RS

Not suggesting; this is explicitly stated as legal in R7RS.
 
  `#=0(1 . #0#)  ; illegal in R7RS

Likewise, this is explicitly stated as illegal in R7RS. And it does make sense because when quasiquote is implemented as a (syntax-rules) macro, it has to scan its template, for which it *must* be illegal for the template to contain any cyclic datums.
 
  (let-syntax ((q (syntax-rules () ((_ x) 'x))))
    (q #=0(1 . #0#)))  ; legal?

is absurd. 

Quite the opposite; I would call it absurd if the legalness of that code would be absurd (under the premise that quoted cyclic datums are allowed as in R7RS). Try to formalize the restriction you have in mind and you'll see that it doesn't play well with the rest of the language.

And again, it has nothing to do with quasiquote.

(NB In non-R7RS implementations that allow cyclic literals like Chez, this code is likewise valid. Even formalizing the restriction you have in mind )
 
Moreover beyond these simple cases there is the general problem of extending the syntax-rules pattern matching and template substitution to handle cycles in the general case, which is implied by allowing indirect quoting.

I think no one proposed to extend the syntax-rules pattern matching to be able to detect cycles. (And that's, as I wrote above, one reason why cyclic literals have to be invalid inside quasiquote.) The quote form, however, is no macro that inspects its sole argument as a syntax-rules macro. Nor does the `q` macro from above inspects its argument.
There is no mention of any of this in the spec.

And there doesn't have to be.
 
  The only reasonable assumption is that it means exactly what it says - the cyclic literal should be quoted. 

This is actually not what the spec says (fortunately!). It says: "It is an error for a program or library to include circular
references except in literals." Now, literals are a particular expression form, but not every literal appears in quoted form.
Even more can be inferred: Literals are an expression type like variable references or procedure calls. But whether a particular piece of code is a variable reference or procedure call depends on its lexical context and how it is expanded during macro expansion. The same goes for literals (as for every other expression type). So any restriction (applying to literals) can only apply to the result of the expansion.
 
 
Just for the record, here is another reason why simply skipping quoted literals by any Petrofsky-like cannot work (even if assume that all problematic literals appear in explicit quotes):

(foo (quote <datum>))

I don't know why you keep beating this dead horse.  I've already acknowledged the bug.

I didn't want to offend you; if I did so, please accept my apology (and I didn't mean you to reacknowledge whatever bug).

The misunderstanding is probably that you see the topic of discussion mostly from a practical point of view, which is all that is needed for the purposes of match-letrec, of course. My interest is probably more of a theoretical nature. Given Petrowsky's trick, I have been looking for loopholes (which all would have to be closed to make it viable). Scheme is not only a practical language but also a tool for programming language study.