On Sat, Sep 7, 2024 at 7:52 PM Maxime Devos <maximede...@telenet.be> wrote:

>
>
>
> IIRC doing (set! some-variable some-variable) on the top-level on a
> variable of the module makes the module non-declarative by default, but
> please check the manual for details (there is some information on this, I
> don’t recall the name of the section).
>
>
>
> In particular, I would expect
>
>
>
> (define (foo ...) ...)
>
> (set! foo foo)
>
>
>
> to have the desired properties (at least as far as replacing ‘foo’ with an
> updated version is concerned), both in past, present and future.
>
>
>
> (No comment on what the default _*should*_ be.)
>
>
>

probably i'm a bit out of context but this make me remember some code i had
written

when doing some sort of "overloading" of procedure or operator i use
'define' instead of 'set!' i think i tried set! if i remember well but it
gave bad result, so my current code use 'define' :

(define (create-overloaded-procedure orig-funct funct pred-list)

  (display "create-overloaded-procedure")
  (display " : pred-list = ") (display pred-list) (newline)
  (define old-funct orig-funct)
  (define new-funct (lambda args ;; args is the list of arguments
     ;;(display "new-funct: ") (display new-funct) (newline)
     ;;(display "new-funct : pred-list = ") (display pred-list) (newline)
     ;;(display "new-funct : args = ") (display args) (newline)
     (if (check-arguments pred-list args)
 ;;(begin
   ;;(display "new funct :calling:") (display funct) (newline)
   (apply funct args);)
 ;;(begin
   ;;(display "new funct :calling:") (display old-funct) (newline)
   (apply old-funct args))));)

  (display "funct: ") (display funct) (newline)
  (display "orig-funct: ") (display orig-funct) (newline)
  (display "old-funct: ") (display old-funct) (newline)
  (display "new-funct: ") (display new-funct) (newline)

  new-funct)

i used (define old-funct orig-funct) to backup the function instead of set!
and the code can only called by a macro at top-level of a file and i can
not do this 'overloading' implementation with different scheme
implementation (Kawa,Racket,R6RS...) i had to store the overloading data in
an hash table in a global variable of a module that i probably export
instead of redefining an existing function.

Reply via email to