Just fyi: The latest guile  3.0.10 has definitions in almost all definition 
contexts. If i recall correctly I didnt add it to one of the old looping 
constructs.
-- 
  Linus Björnstam

On Sat, 5 Jul 2025, at 20:15, 胡峻豪 wrote:
> I'm a newcomer to Guile and am currently using Guile to bind some C++ 
> functions for users. Users already have many Scheme scripts, but their 
> scripts don't comply with standards—for example, using define in 
> expression contexts, which causes Guile to throw errors. I tried 
> writing a code snippet with Claude to improve this, as shown below
>
>
> (use-modules (ice-9 regex))
>
>
> (define-syntax original-define
>   (identifier-syntax define))
>
>
> ;; Redefine define to avoid recursive calls
> (define-syntax define
>   (lambda (stx)
>     (syntax-case stx ()
>       ((_ var val)
>        #'(begin
>            (module-define! (current-module) 'var val)
>            var))
>       ((_ (name . args) . body)
>        #'(begin
>            (module-define! (current-module) 'name (lambda args . body))
>            name)))))
>
>
> But this makes the definitions module-level. If I define the same 
> variable at the top level and inside a lambda, they overwrite each 
> other. Scheme is too difficult for me. Is there any way to achieve this 
> functionality without modifying the scripts? I would appreciate your 
> help.

Reply via email to