From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-vs1-xe2d.google.com (mail-vs1-xe2d.google.com [IPv6:2607:f8b0:4864:20::e2d]) by sourceware.org (Postfix) with ESMTPS id 80F9C3858430 for ; Thu, 27 Jan 2022 22:58:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 80F9C3858430 Received: by mail-vs1-xe2d.google.com with SMTP id l14so882371vsm.3 for ; Thu, 27 Jan 2022 14:58:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=zPD4XemjC2dJP+SJzD/ZiB6AZLq3nvyC2obCwRWsAX0=; b=uR7JDQNYlLJFvSjgK6FTtzn81p//VIPNPqAGtxyBbv2SYv3OyEgBy/J8hbIxWfKngQ Jg0uQkEm8kYrP+RAuaDFT8Y4/l8ixTD+Cvw3o02CP30HaBVFf2TdsbmMKv+8C4/NV0eu XBLjtnSUy31exXIQL7idvE5IXKNGwnpghJW+ii1FB8IrU4edYAlVKUn/2lZymf4AuoW8 xFLZN3KWJ3qcP+/dp5ah4EJqv1/RrwpklxZOFAaggRCe6Ybk6V9fS0wXhbFRV+HTNq6U Pec+AcGR2Cl2TVz6/rqxqDhh1ULsp7wdR6bBvJpeFk1Si7vT2cHyzPogixm+CjbBHLqX v7NA== X-Gm-Message-State: AOAM533IUK+OwG/qpxe8dvs8YdBlunJiM7TxJzQi6hDHCuJ7khrIBPaX FA7GvbdpaQbDnU8ONLcEQ6ByRQWWd6btS0So/FoV4/zWYms= X-Google-Smtp-Source: ABdhPJyZ58DA1LgrP/lPMG2QzRbRkuNegu2rRkc4GAv7wxdE+MUKSMulRb2JpRn2ZrgPT5Nr+stpXwY2sg8yCFLnpXc= X-Received: by 2002:a05:6102:5593:: with SMTP id dc19mr2942250vsb.78.1643324300904; Thu, 27 Jan 2022 14:58:20 -0800 (PST) MIME-Version: 1.0 From: Panicz Maciej Godek Date: Thu, 27 Jan 2022 23:58:01 +0100 Message-ID: Subject: "define is only allowed in a " To: kawa@sourceware.org X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: kawa@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Kawa mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 Jan 2022 22:58:23 -0000 Hi, I observed that when I write macros that expand to 'define' form, I sometimes get this error: define is only allowed in a 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 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 ") 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?