[racket] Call-Site Code Replacement
Only this particular call site? Because in general, it would be simple to do:
#lang racket/base
(define (f a)
(printf "(f ~a)\n" a)
(set! the-f g)
0)
(define the-f f)
(define (g a)
(printf "(g ~a)\n" a)
(set! the-f f)
1)
(module+ main
(for ([i (in-range 10)])
(the-f i)))
OUTPUT:
(f 0)
(g 1)
(f 2)
(g 3)
(f 4)
(g 5)
(f 6)
(g 7)
(f 8)
(g 9)
On Mon, Oct 22, 2012 at 11:55 AM, Jan Burse <janburse at fastmail.fm> wrote:
> Dear All,
>
> I just wonder whether it is possible in a functional
> language to do call site replacement. I envision this
> as a special form of lazyness.
>
> Basically I would call somewhere a function f
> with an argument a:
>
> ... (f a) ...
>
> The function would then manage to replace itself
> by a function g with an argument b:
>
> ... (g b) ...
>
> So that the next time the original call site of (f a)
> is invoked in fact (g b) is invoked.
>
> Hints welcome.
>
> Bye
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
--
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://faculty.cs.byu.edu/~jay
"The glory of God is Intelligence" - D&C 93