public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: kawa@sourceware.org
Subject: "define is only allowed in a <body>"
Date: Thu, 27 Jan 2022 23:58:01 +0100	[thread overview]
Message-ID: <CAMFYt2bkHOo6kCO3U=_9Z6XMR4-o__nGLFHq1Z==OG_QTe6_+w@mail.gmail.com> (raw)

Hi,
I observed that when I write macros that expand to 'define' form, I
sometimes get this error:

define is only allowed in a <body>

The error seems very fragile, and I didn't manage to find a minimal setup
to recreate it.

But I have a fairly elaborate set of modules where the error appears.

So in particular, in this folder and in this commit:

https://github.com/panicz/grasp-android/tree/d7146355a3862cf3e2aef168bc10f741915b8828/stages/retreat/GRASP/src

I have two entry points to my module.

The first one is a small test suite, namely -- the file "test-screen.scm"

When I run it,

kawa -f test-screen.scm

I get a few warnings:

primitive.scm:454:18: warning - void-valued expression where value is needed
primitive.scm:473:18: warning - void-valued expression where value is needed
primitive.scm:525:3: warning - unreachable code
primitive.scm:550:3: warning - unreachable code
test-screen.scm:110:5: warning - type Screen is incompatible with required
type Screen
test-screen.scm:139:21: warning - type Finger is incompatible with required
type Tile

But the tests run allright.

On the other hand, when I try to run the file editor.scm

CLASSPATH=./lanterna-3.1.1.jar kawa -f editor.scm

then -- in addition to those warnings -- I get an error in the module
primitive.scm:

primitive.scm:305:1: define is only allowed in a <body>
primitive.scm:454:18: warning - void-valued expression where value is needed
primitive.scm:473:18: warning - void-valued expression where value is needed
primitive.scm:525:3: warning - unreachable code
primitive.scm:550:3: warning - unreachable code
primitive.scm:310:5: warning - no declaration seen for heads

Now, the expression beginning in the line 305 of primitive.scm looks like
this:

(define-cache (heads tail)
  (cache (head)
    (cons head tail)))

where the form "define-cache" is defined in the "define-cache.scm" file as

(define-syntax-rule (define-cache (property-name object) default)
  (define property-name
    (cache (object) default)))

and define-syntax-rule is defined in the define-syntax-rule.scm file as

(define-syntax define-syntax-rule
  (syntax-rules ()

    ((define-syntax-rule (name . args) substitution)
     (define-syntax name
       (syntax-rules ()
         ((name . args)
          substitution))))

    ((define-syntax-rule (name . args) . substitution)
     (define-syntax name
       (syntax-rules ()
         ((name . args)
          (begin . substitution)))))
    ))

Now, if I substitute the usage of "define-cache" with its expansion, i.e.

(define heads
  (cache (tail)
    (cache (head)
       (cons head tail))))

the problem disappears.

Moreover, I have noticed one thing. The test-screen.scm imports a number of
modules:

(import
 (cell-display-properties)
 (define-interface)
 (define-type)
 (conversions)
 (primitive)
 (text-screen)
 (combinators)
 (parse)
 (examples)
 (assert)
 (cursor)
 (infix))

The editor.scm file imports almost the same modules and in the same order
(plus two other low-dependency modules), but using one import expression
per module, rather than one import expression containing all modules:


(import (cell-display-properties))
(import (define-interface))
(import (define-type))
(import (conversions))
(import (primitive))
(import (text-screen))
(import (combinators))
(import (parse))
(import (examples))
(import (assert))
(import (cursor))
(import (infix))
(import (match))
(import (term))

If I replace this series of single-module imports with a single import of
all those modules, then the problem disappears as well.

I have experienced the same error ("define is only allowed in a <body>")
when I had some circular dependencies between modules.

Since then, I did my best to remove any circular dependencies. I'm not 100%
sure they are all gone, but I didn't manage to find any.

How could this error (and its solutions) be explained?

             reply	other threads:[~2022-01-27 22:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-27 22:58 Panicz Maciej Godek [this message]
2022-01-27 23:57 ` Per Bothner

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='CAMFYt2bkHOo6kCO3U=_9Z6XMR4-o__nGLFHq1Z==OG_QTe6_+w@mail.gmail.com' \
    --to=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).