[racket] Dynamically Bind Functions

From: Cristian Esquivias (cristian.esquivias at gmail.com)
Date: Sat Dec 22 04:23:47 EST 2012

Is this the general practice? It looks rather cumbersome and difficult to
plan for.

Is there anything that would prevent me from having to wrap functions in
make-parameter calls? Something like Clojure's binding special form (if
you're familiar with it).

- Cristian
On Dec 21, 2012 6:45 PM, "David Van Horn" <dvanhorn at ccs.neu.edu> wrote:

> On 12/21/12 9:41 PM, Cristian Esquivias wrote:
>
>> I'm trying to replace a function with another using parameterize.
>>
>> For example, when I try:
>>
>> (define (add2 n)
>>    (add1 (add1 n)))
>>
>> (parameterize ([add1 (λ [n] (+ n 2))])
>>    (add2 2))
>>
>> I get an error:
>>
>>   parameterize: contract violation
>>    expected: parameter?
>>    received: #<procedure:add1>
>>
>> How do I re-bind functions in Racket?
>>
>
> You can only use parameterize with names bound to parameter values. Here's
> an example:
>
> #lang racket
> (define padd1 (make-parameter add1))
>
> ((padd1) 4)
>
> (parameterize ([padd1 (λ (n) (+ 2 n))])
>   ((padd1) 4))
>
> David
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20121222/f542b5be/attachment.html>

Posted on the users mailing list.