> 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).

I'm not a Clojure expert so please correct me if I'm wrong but it
seems like you have to jump through similar hoops in Clojure?

Clojure 1.3.0
user=> (defn add1 [x] (+ x 1))
#'user/add1
user=> (add1 10)
11
user=> (binding [add1 #(+ % 2)] (add1 10))
IllegalStateException Can't dynamically bind non-dynamic var:
user/add1  clojure.lang.Var.pushThreadBindings (Var.java:339)
user=> (defn ^:dynamic add1 [x] (+ x 1))
#'user/add1
user=> (add1 10)
11
user=> (binding [add1 #(+ % 2)] (add1 10))
12


From the docs (http://clojure.org/vars):

bindings created with binding can be assigned to, which provides a
means for a nested context to communicate with code before it on the
call stack. This capability is opt-in only by setting a metadata tag
:dynamic to true as in the code block above






On Sat, Dec 22, 2012 at 4:23 AM, Cristian Esquivias
<cristian.esquiv...@gmail.com> wrote:
> Is this the general practice? It looks rather cumbersome and difficult to
> plan for.
>
>
> - Cristian
>
> On Dec 21, 2012 6:45 PM, "David Van Horn" <dvanh...@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
>>
>>
>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>

____________________
  Racket Users list:
  http://lists.racket-lang.org/users

Reply via email to