Janko, 

It's a little hard to see exactly, but you might want to have a quick 
glance at the docs for, "with-redefs" in the core library. This will give 
you a slightly more structured way to redefine vars with actual scoping, 
even if that scope is your entire app it might be a more controlled 
approach. 

On Saturday, 19 January 2019 22:15:43 UTC, Janko Muzykant wrote:
>
> Awsome! This is exactly what I was looking for :)
>
> Thanks James and thanks everyone for other suggestions.
>
>
> On Saturday, January 19, 2019 at 5:20:06 PM UTC+1, James Reeves wrote:
>>
>> Yes, the alter-var-root function allows you to change a var's definition:
>>
>>   (alter-var-root
>>    #'fetch-data
>>    (fn [original-fetch-data]
>>      (fn [& args]
>>        (let [result (apply original-fetch-data args)]
>>          (transform-result result))))))
>>
>> On Sat, 19 Jan 2019 at 14:58, Janko Muzykant <umr...@gmail.com> wrote:
>>
>>> Hi,
>>>
>>> Is there an way to replace body of existing (interned) function with own 
>>> code still being able to call original fn? 
>>> Suppose, I have a function:
>>>
>>>     (defn fetch-data [arg1 arg2]
>>>       (db/fetch-data ...))
>>>
>>> I would like to intern a slightly modified version of this fn. Something 
>>> like this:
>>>
>>>     (defn fetch-data [& args]
>>>       (let [result (apply original-fetch-data args)]
>>>         (transform-result result)))
>>>
>>> The problem I see is how to keep the reference to original fetch-data fn 
>>> (here denoted by original-fetch-data),
>>> so it could be still called in a altered version of fetch-data function.
>>>
>>> Best,
>>> JM.
>>>
>>>
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@googlegroups.com
>>> Note that posts from new members are moderated - please be patient with 
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> clojure+u...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Clojure" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to clojure+u...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>> -- 
>> James Reeves
>> booleanknot.com
>>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to