public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
* "define-constant is only allowed in a <body>"
@ 2022-11-19 14:37 Panicz Maciej Godek
  2022-11-20 22:41 ` Per Bothner
  0 siblings, 1 reply; 3+ messages in thread
From: Panicz Maciej Godek @ 2022-11-19 14:37 UTC (permalink / raw)
  To: kawa

[-- Attachment #1: Type: text/plain, Size: 1010 bytes --]

I have a module named (mapping), which contains a thing that I have called
"mapping", which is a nice functional interface to mutable hash tables
(based on SRFI-17):

https://github.com/panicz/grasp-android/blob/master/stages/retreat/GRASP/src/mapping.scm

Therein, you can also find the following definition of define-mapping:

(define-syntax-rule (define-mapping (mapping-name key) default-value)
   (define-early-constant mapping-name
      (mapping (key) default-value)))

where define-syntax-rule is defined in a straightforward way in another
module.

When I try to use this code from yet another module -- more specifically,
this one:

https://github.com/panicz/grasp-android/blob/master/stages/retreat/GRASP/src/panel.scm#L130

as

(define-mapping (on-key-press code) never)

I get the error message

define-constant is only allowed in a <body>

but when I use the expanded version

(define on-key-press (mapping (code) never))

everything works.

I wonder what could be the reason of Kawa's behavior.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: "define-constant is only allowed in a <body>"
  2022-11-19 14:37 "define-constant is only allowed in a <body>" Panicz Maciej Godek
@ 2022-11-20 22:41 ` Per Bothner
  2022-11-20 23:29   ` Panicz Maciej Godek
  0 siblings, 1 reply; 3+ messages in thread
From: Per Bothner @ 2022-11-20 22:41 UTC (permalink / raw)
  To: Panicz Maciej Godek, kawa



On 11/19/22 06:37, Panicz Maciej Godek via Kawa wrote:
> When I try to use this code from yet another module -- more specifically,
> this one:
> 
> https://github.com/panicz/grasp-android/blob/master/stages/retreat/GRASP/src/panel.scm#L130
> 
> as
> 
> (define-mapping (on-key-press code) never)
> 
> I get the error message
> 
> define-constant is only allowed in a <body>
> 
> but when I use the expanded version
> 
> (define on-key-press (mapping (code) never))
> 
> everything works.
> 
> I wonder what could be the reason of Kawa's behavior.

Kawa is presumably complaining that the define-early-constant is
in a non-<body> context.

This is allowed:
   (begin (define-early-constant ...) ...)

This is not:
   (list (define-early-constant ...) ...)

One of the problems with Scheme S-expression-based syntax is that
it is sometimes tricky to tell what parenthesis does what.
For example, it is easy to end up with this after some macro-expansion:

   ((define-early-constant ...))
-- 
	--Per Bothner
per@bothner.com   http://per.bothner.com/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: "define-constant is only allowed in a <body>"
  2022-11-20 22:41 ` Per Bothner
@ 2022-11-20 23:29   ` Panicz Maciej Godek
  0 siblings, 0 replies; 3+ messages in thread
From: Panicz Maciej Godek @ 2022-11-20 23:29 UTC (permalink / raw)
  To: Per Bothner; +Cc: kawa

[-- Attachment #1: Type: text/plain, Size: 2182 bytes --]

niedz., 20 lis 2022 o 23:41 Per Bothner <per@bothner.com> napisał(a):

>
>
> On 11/19/22 06:37, Panicz Maciej Godek via Kawa wrote:
> > When I try to use this code from yet another module -- more specifically,
> > this one:
> >
> >
> https://github.com/panicz/grasp-android/blob/master/stages/retreat/GRASP/src/panel.scm#L130
> >
> > as
> >
> > (define-mapping (on-key-press code) never)
> >
> > I get the error message
> >
> > define-constant is only allowed in a <body>
> >
> > but when I use the expanded version
> >
> > (define on-key-press (mapping (code) never))
> >
> > everything works.
> >
> > I wonder what could be the reason of Kawa's behavior.
>
> Kawa is presumably complaining that the define-early-constant is
> in a non-<body> context.
>
> This is allowed:
>    (begin (define-early-constant ...) ...)
>
> This is not:
>    (list (define-early-constant ...) ...)
>
> One of the problems with Scheme S-expression-based syntax is that
> it is sometimes tricky to tell what parenthesis does what.
> For example, it is easy to end up with this after some macro-expansion:
>
>    ((define-early-constant ...))
>
>
I understand this message the way you explained it
-- it just doesn't make sense in my context.

There seems to be an issue with module dependency resolution.
The problematic expansion was in the (panel) module.
It contains a dependency on the (mapping) module.

The main module (either grasp-terminal.scm or grasp-desktop.scm)
included (import (panel)), and the compilation failed with the above
message.

But when I add (import (mapping)) to the main module -- before the
(import (panel)) clause -- the compilation succeeds. (However, if I add it
after (import (panel)) -- it still breaks).

I realized that I ran into that problem early on during my work,
but instead of reporting it, I just started including module dependencies
transitively in the "right order". This is a workaround, but I think
that there might be some issue between reflection, macro expansion
and module dependency loading.

I'll let you know if I manage to find a minimal set of modules which break
in this way.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-20 23:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-19 14:37 "define-constant is only allowed in a <body>" Panicz Maciej Godek
2022-11-20 22:41 ` Per Bothner
2022-11-20 23:29   ` Panicz Maciej Godek

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).