[racket] Search & wrap

From: Jukka Tuominen (jukka.tuominen at finndesign.fi)
Date: Tue Feb 24 17:39:04 EST 2015


For example, if I had definitions spread across two files like follows...

File1:

(require file2)

(define (times2 x)
  (* 2 x))


(define (my-times2power3+5 x)
  (+ 5 (times2 (power3 x))))



File2:

(define (power3 x)
  (* x x x))


---


Now calling the function (search&wrap 'my-times2power3+5) would output

(define (my-times2power3+5 x)
  (define (power3 x)
    (* x x x))
  (define (times2 x)
    (* 2 x))
  (+ 5 (power3 (times2 x))))


So, now id have all the definitions that my-times2power3+5 needs within it
as local definitions

I understand that in many cases this might grow up to be unpractical or
otherwise problematic, but in some cases it would be a great timesaver.

I hope this explains it a bit better(?)

br, jukka


> You say "wrap" but in your example you replace the call of function b with
> another function.
>
> Without a specific use-case I'm not sure about the use of speculating on
> your meaning.
>
> Would you be satisfied with
> (search&wrap function-b
>    (define (function-a ...) ...))
> or
> (define (function-a ...)
>    (with-function-wrapper ([function-b ...]) ...))
> ?
>
> Otherwise it seems like you are asking for something that precludes
> separate compilation and has effects that cross module boundaries...
> sounds
> unpleasant if not terrible.
>
>
> Andrew Mauer-Oats
> Mathematics Ph.D.
> Chicago Public Schools: Whitney Young
>
> On Tue, Feb 24, 2015 at 6:52 AM, Jukka Tuominen <
> jukka.tuominen at finndesign.fi> wrote:
>
>>
>> This is something I've been wondering for years and always ended up
>> doing
>> it manually. So, why not ask it out loud...
>>
>> I wonder whether it would be possible to search and wrap all definitions
>> that reside outside a specified function, other than those contained in
>> #lang racket?
>>
>> Say, (search&wrap 'function-a)  would start in the situation like
>>
>> (define (function-a x y z)
>>    (function-b x y z))
>>
>> It would then search the definition for 'function-b and would output
>> something like
>>
>> (define (function-a x y z)
>>    (define function-b +)
>>    (function-b x y z))
>>
>> It does not have to search through unintroduced library files (though it
>> would be even cooler), only starting in a situation where all the needed
>> definitions can be found within the same level or 'required' from other
>> files.
>>
>> It should also work recursively, so that eventually no library calls
>> would
>> be needed to run the function-a.
>>
>> Any idea whether this is feasible?
>>
>> br, jukka
>>
>>
>>
>> ____________________
>>   Racket Users list:
>>   http://lists.racket-lang.org/users
>>
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users
>



Posted on the users mailing list.