Rebinding functions?

2009-06-16 Thread Michel Salim

It's currently not possible to dynamically rebind functions:

(binding [+ -] (+ 5 3)) == 8 ;; not 2

Would this be supported in the future? It would make it easier, for
example, to extend the current tracing functionality, e.g.

(trace-in-expr [f1 f2] (f1 (f2 10))) ==
(let [oldf1 f1 oldf2 f2]
  (binding [f1 (fn [ args] (trace-fn-call 'f1 oldf1 args))
f2 (fn [ args] (trace-fn-call 'f2 oldf2 args))]
(f1 (f2 10

Thanks,

--
Michel S.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Rebinding functions?

2009-06-16 Thread Paul Stadig
On Tue, Jun 16, 2009 at 1:38 PM, Michel Salim michel.syl...@gmail.comwrote:


 It's currently not possible to dynamically rebind functions:

 (binding [+ -] (+ 5 3)) == 8 ;; not 2

 Thanks,

 --
 Michel S.


It is possible to rebind (even core) functions, but there are a couple of
limitations. One of which is the fact that some functions are inlined by the
compiler. I believe the two argument case of '+ is one of those.

Paul

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Rebinding functions?

2009-06-16 Thread Sean Devlin

Yes, people have shown examples on this list where

(+ a b)

is dramatically faster than

(+ a b c)

On Jun 16, 1:42 pm, Paul Stadig p...@stadig.name wrote:
 On Tue, Jun 16, 2009 at 1:38 PM, Michel Salim michel.syl...@gmail.comwrote:



  It's currently not possible to dynamically rebind functions:

  (binding [+ -] (+ 5 3)) == 8 ;; not 2

  Thanks,

  --
  Michel S.

 It is possible to rebind (even core) functions, but there are a couple of
 limitations. One of which is the fact that some functions are inlined by the
 compiler. I believe the two argument case of '+ is one of those.

 Paul
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Rebinding functions?

2009-06-16 Thread Michel S.



On Jun 16, 1:42 pm, Paul Stadig p...@stadig.name wrote:
 On Tue, Jun 16, 2009 at 1:38 PM, Michel Salim michel.syl...@gmail.comwrote:



  It's currently not possible to dynamically rebind functions:

  (binding [+ -] (+ 5 3)) == 8 ;; not 2

  Thanks,

  --
  Michel S.

 It is possible to rebind (even core) functions, but there are a couple of
 limitations. One of which is the fact that some functions are inlined by the
 compiler. I believe the two argument case of '+ is one of those.

I just verified and it does indeed work -- thanks. Time to read up on
macros to implement this tracing construct, then.

--
Michel
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Rebinding functions?

2009-06-16 Thread Kevin Downey

you can use apply to avoid in-lining:

user= (binding [+ -] (apply + '(5 3)))
2


On Tue, Jun 16, 2009 at 11:16 AM, Michel S.michel.syl...@gmail.com wrote:



 On Jun 16, 1:42 pm, Paul Stadig p...@stadig.name wrote:
 On Tue, Jun 16, 2009 at 1:38 PM, Michel Salim michel.syl...@gmail.comwrote:



  It's currently not possible to dynamically rebind functions:

  (binding [+ -] (+ 5 3)) == 8 ;; not 2

  Thanks,

  --
  Michel S.

 It is possible to rebind (even core) functions, but there are a couple of
 limitations. One of which is the fact that some functions are inlined by the
 compiler. I believe the two argument case of '+ is one of those.

 I just verified and it does indeed work -- thanks. Time to read up on
 macros to implement this tracing construct, then.

 --
 Michel
 




-- 
And what is good, Phaedrus,
And what is not good—
Need we ask anyone to tell us these things?

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Rebinding functions?

2009-06-16 Thread Michel Salim



On Jun 16, 2:22 pm, Kevin Downey redc...@gmail.com wrote:
 you can use apply to avoid in-lining:

 user= (binding [+ -] (apply + '(5 3)))
 2

Indeed; this is what my macro ended up doing anyway, since it has to
work regardless of the arity of the functions to trace.

--
Michel
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Rebinding functions?

2009-06-16 Thread CuppoJava

This post worries me.
I've considered rewriting functions as inlining-macros for
optimization purposes. But I thought it would be a transparent change.
This post shows that it's not a transparent change, and could
potentially lead to some very odd looking bugs.

What if I wanted to optimize println by replacing it with a inlining-
macro? Now users that rebind println to do something extra will be
bewildered that the binding is not working.

Any thoughts?
-Patrick
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---