From 2512d52dd13efd1a81a62ef7015016a45c4f6b95 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Sat, 3 Oct 2026 22:28:14 +0300 Subject: [PATCH] keep a module's public forms in declaration order read-public-interface folded with cons and never reversed, so an imported pub fn whose prototype named a type declared above it in the same module was pasted before that type, and the unit did not compile. --- sex-modules.scm | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sex-modules.scm b/sex-modules.scm index 9939bd89..744e68ad 100644 --- a/sex-modules.scm +++ b/sex-modules.scm @@ -65,12 +65,16 @@ module-path)))) (define (read-public-interface module-path) - ;; pub fns are reduced to prototypes, other pub forms are just pasted + ;; pub fns are reduced to prototypes, other pub forms are just pasted. + ;; Declaration order is kept: a module that declares a type and then a + ;; pub fn taking it has to paste them that way round, or the prototype + ;; names a type C has not seen. (let ((raw-forms (read-from-file module-path))) - (fold - process-public-interface-form - (list) - raw-forms))) + (reverse + (fold + process-public-interface-form + (list) + raw-forms)))) (define (public-fn-interface raw-form) ;; (pub fn name args ret . body) -> prototype, keeping a docstring so