<div dir="ltr"><div><div><div><div><div><div>If you are working with functions in someone else's code, you are stuck with their definition. When you write your own functions, however, you can always design them as wrappers around parameters. For instance:<br>
<br></div>(define current-add-one (make-parameter add1))<br><br></div>(define (add-one x)<br></div> ((current-add-one) x))<br><br></div><div>(add-one 4)<br></div><div><br></div>(parameterize {[current-add-one (lambda (x) (add1 (add1 x)))]}<br>
</div> (add-one 4))<br><br></div>So now the function and the parameter are separate, but calling the function is always nice and short.<br></div><div class="gmail_extra"><br clear="all"><div>Carl Eastlund</div>
<br><br><div class="gmail_quote">On Sat, Dec 22, 2012 at 4:23 AM, Cristian Esquivias <span dir="ltr"><<a href="mailto:cristian.esquivias@gmail.com" target="_blank">cristian.esquivias@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p>Is this the general practice? It looks rather cumbersome and difficult to plan for.<br></p>
<p>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).</p><span class="HOEnZb"><font color="#888888"><p>
- Cristian<br></p></font></span><div class="im">
<div class="gmail_quote">On Dec 21, 2012 6:45 PM, "David Van Horn" <<a href="mailto:dvanhorn@ccs.neu.edu" target="_blank">dvanhorn@ccs.neu.edu</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 12/21/12 9:41 PM, Cristian Esquivias wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm trying to replace a function with another using parameterize.<br>
<br>
For example, when I try:<br>
<br>
(define (add2 n)<br>
(add1 (add1 n)))<br>
<br>
(parameterize ([add1 (λ [n] (+ n 2))])<br>
(add2 2))<br>
<br>
I get an error:<br>
<br>
parameterize: contract violation<br>
expected: parameter?<br>
received: #<procedure:add1><br>
<br>
How do I re-bind functions in Racket?<br>
</blockquote>
<br>
You can only use parameterize with names bound to parameter values. Here's an example:<br>
<br>
#lang racket<br>
(define padd1 (make-parameter add1))<br>
<br>
((padd1) 4)<br>
<br>
(parameterize ([padd1 (λ (n) (+ 2 n))])<br>
((padd1) 4))<br>
<br>
David<br>
<br>
<br>
</blockquote></div>
</div></div>
<br>____________________<br>
Racket Users list:<br>
<a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br></div>