[racket] Call-Site Code Replacement

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Oct 28 12:44:33 EDT 2012

Do you mean 

#lang racket

(letrec ((f (lambda (x) (displayln `(this is f with ,x)) (set! f (lambda (y) (g y))) (f x)))
         (g (lambda (z) (displayln `(this is g with ,z)) (* z 3))))
  (f 1)
  (f 2))

(Some purists would argue that this is not truly functional but programmers who want to get things done accept this form of functional programming just fine.) 

-- Matthias



On Oct 22, 2012, at 1:55 PM, Jan Burse 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4373 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20121028/16884586/attachment.p7s>

Posted on the users mailing list.