Re: [racket] Dynamically Bind Functions

2012-12-22 Thread Stephen Bloch
On Dec 22, 2012, at 4:52 PM, Cristian Esquivias wrote: > For example, I have a function that takes a filename and spits out a data > structure. I wanted to create some unit tests and this mock the > open-input-file function (with a open-input-string implementation). > > I originally thought pa

Re: [racket] Dynamically Bind Functions

2012-12-22 Thread Cristian Esquivias
My original plan was to try to do some kind of mocking and unit testing in racket. For example, I have a function that takes a filename and spits out a data structure. I wanted to create some unit tests and this mock the open-input-file function (with a open-input-string implementation). I origin

Re: [racket] Dynamically Bind Functions

2012-12-22 Thread Carl Eastlund
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: (define current-add-one (make-parameter add1)) (define (add-one x) ((current-add-o

Re: [racket] Dynamically Bind Functions

2012-12-22 Thread Stephen Chang
> 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 Cl

Re: [racket] Dynamically Bind Functions

2012-12-22 Thread Grant Rettke
On Sat, Dec 22, 2012 at 3:23 AM, Cristian Esquivias wrote: > Is this the general practice? It looks rather cumbersome and difficult to > plan for. Are you wanting to change the behavior of some code that you don't have the code for? Racket Users list: http://lists.racket-

Re: [racket] Dynamically Bind Functions

2012-12-22 Thread Stephen Bloch
On Dec 22, 2012, at 4:23 AM, Cristian Esquivias wrote: > 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

Re: [racket] Dynamically Bind Functions

2012-12-22 Thread Cristian Esquivias
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

Re: [racket] Dynamically Bind Functions

2012-12-21 Thread David Van Horn
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: p