On Sun, 03 May 2026, Tomas Volf <[email protected]> wrote:
> Hello,
>
> I am trying to figure out how to define a procedure based on a list of
> fields of some record.  I know I can get list of fields for some record
> using `record-type-fields', but I do not know how to do that in a
> syntax-case, since I just see identifier <foo>, but do not know how to
> get the binding.

You need to have the record definition available at expansion time.
BLUE kinds of do something like this [0] so it can raise an exception if
a field that is not valid for a type is passed.  For this, the
definition is evaluated during the expansion.  This is necessary because
BLUE types can inherit from parent types and so fields are not just part
of the type definition itself.  Note that this is not stricly necessary
if you import the type from another module, since then the definition is
available during expansion.  But if the definition is in the same
module, you need to force evaluation during the expansion to get it
define.

I guess you could also do something similar to what define-module do :

ice-9/boot.scm:
 3978          #'(eval-when (expand load eval)
 3979              (let ((m (define-module* '(name name* ...)
 3980                         #:filename filename quoted-arg ...)))
 3981                (set-current-module m)
 3982                m)))))))

so that the defined module is available at expansion time throught 
(current-module).

[0] 
https://codeberg.org/lapislazuli/blue/src/commit/273e31d8ef3932384f11fd5ac6915c2ac8dffbed/blue/oop.scm#L303
-- 
Olivier Dion

Reply via email to