From: Per Bothner <per@bothner.com>
To: Panicz Maciej Godek <godek.maciek@gmail.com>, kawa@sourceware.org
Subject: Re: "define is only allowed in a <body>"
Date: Thu, 27 Jan 2022 15:57:07 -0800 [thread overview]
Message-ID: <eedb77bf-5b49-1b09-0bfb-52574382deaa@bothner.com> (raw)
In-Reply-To: <CAMFYt2bkHOo6kCO3U=_9Z6XMR4-o__nGLFHq1Z==OG_QTe6_+w@mail.gmail.com>
I don't know the actual problem, but the following explains the error message.
Syntax expansion (translating of S-expressions to Expression objects)
is done in two interleaved phases:
(1) The "scan" phase is primarily about collecting the set of names
bound in a <body>. So given something like:
(define name expr)
it will make a note of 'name' but it will leave 'expr' for the next phase.
(2) The rewrite phase expands a single expression in the context of existing
definitions.
Macro expansion may happen in either phase, as needed.
For example 'define' is actually a macro that expands into the more primitive '%define'.
Forms at the the top-level of a <body> have to be expanded at scan time -
thus 'define' gets expanded at scan time to '%define' which then gets further processed.
The 'let' form does not define new non-local identifiers, so 'let' is processed at
rewrite time - and does not need any processing at scan time.
'define' (or rather '%define') needs processing at both scan and rewrite times:
scan makes a note of the defined name, and converts it to a simpler form
that is later processed by rewrite.
It is an error for 'define' to appear in expression context, such as the following:
(list (define x 10) x)
That is what the error message means. Kawa will complain if rewrite is asked to
process a 'define' (or '%define') form that has not been previously processed by scan.
Basically, one of your macros expands to a 'define' in expression context.
--
--Per Bothner
per@bothner.com http://per.bothner.com/
prev parent reply other threads:[~2022-01-27 23:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-27 22:58 Panicz Maciej Godek
2022-01-27 23:57 ` Per Bothner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=eedb77bf-5b49-1b09-0bfb-52574382deaa@bothner.com \
--to=per@bothner.com \
--cc=godek.maciek@gmail.com \
--cc=kawa@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).