Re: Standard calling-a-function function?

2009-10-22 Thread Timothy Pratley



On Oct 22, 3:22 pm, John Harrop jharrop...@gmail.com wrote:
 user= (map call (map constantly [1 2 3]))
 (1 2 3)

 map call and map constantly are actually inverse operations.

:) that makes me smile!

--~--~-~--~~~---~--~~
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: Standard calling-a-function function?

2009-10-22 Thread RandyHudson

(apply arg)

On Oct 21, 7:49 pm, samppi rbysam...@gmail.com wrote:
 Is there a standard function that takes one argument and calls it?
 That is, the function equivalent to #(%). Or is that the best idiom
 there is?

--~--~-~--~~~---~--~~
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: Standard calling-a-function function?

2009-10-22 Thread samppi

That is indeed nice. Thanks for the code; I guess I don't really have
to settle for #(%) after all.

@RandyHudson: apply would work, but it's pretty slow, and not worth
switching from #(%).

On Oct 21, 11:49 pm, Timothy Pratley timothyprat...@gmail.com wrote:
 On Oct 22, 3:22 pm, John Harrop jharrop...@gmail.com wrote:

  user= (map call (map constantly [1 2 3]))
  (1 2 3)

  map call and map constantly are actually inverse operations.

 :) that makes me smile!
--~--~-~--~~~---~--~~
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: Standard calling-a-function function?

2009-10-21 Thread James Reeves

apply

On Oct 22, 12:49 am, samppi rbysam...@gmail.com wrote:
 Is there a standard function that takes one argument and calls it?
 That is, the function equivalent to #(%). Or is that the best idiom
 there is?
--~--~-~--~~~---~--~~
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: Standard calling-a-function function?

2009-10-21 Thread samppi

Ah, of course. But then I'm afraid of a time penalty cost, because
apply can take many arguments; would this be significant? Or should I
stick to #(%)?

Clojure 1.0.0-
user= (def a (constantly 55))
#'user/a
user= (time (dotimes [_ 500] (a)))
Elapsed time: 0.389 msecs
nil
user= (time (dotimes [_ 500] (apply a)))
Elapsed time: 0.923 msecs
nil

On Oct 21, 5:04 pm, James Reeves weavejes...@googlemail.com wrote:
 apply

 On Oct 22, 12:49 am, samppi rbysam...@gmail.com wrote:



  Is there a standard function that takes one argument and calls it?
  That is, the function equivalent to #(%). Or is that the best idiom
  there is?
--~--~-~--~~~---~--~~
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: Standard calling-a-function function?

2009-10-21 Thread James Reeves

I think you need to be careful not to prematurely optimise. If using
apply becomes a problem, then drop in something more efficient, but
until that point there's no reason not to use it.

- James

On Oct 22, 1:27 am, samppi rbysam...@gmail.com wrote:
 Ah, of course. But then I'm afraid of a time penalty cost, because
 apply can take many arguments; would this be significant? Or should I
 stick to #(%)?

 Clojure 1.0.0-
 user= (def a (constantly 55))
 #'user/a
 user= (time (dotimes [_ 500] (a)))
 Elapsed time: 0.389 msecs
 nil
 user= (time (dotimes [_ 500] (apply a)))
 Elapsed time: 0.923 msecs
 nil

 On Oct 21, 5:04 pm, James Reeves weavejes...@googlemail.com wrote:

  apply

  On Oct 22, 12:49 am, samppi rbysam...@gmail.com wrote:

   Is there a standard function that takes one argument and calls it?
   That is, the function equivalent to #(%). Or is that the best idiom
   there is?
--~--~-~--~~~---~--~~
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: Standard calling-a-function function?

2009-10-21 Thread John Harrop
On Wed, Oct 21, 2009 at 7:49 PM, samppi rbysam...@gmail.com wrote:

 Is there a standard function that takes one argument and calls it?
 That is, the function equivalent to #(%). Or is that the best idiom
 there is?


#(%) is only four characters. Calling apply with only one argument also does
this, and apply is five characters. Did you want a third one for some
reason? :)

--~--~-~--~~~---~--~~
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: Standard calling-a-function function?

2009-10-21 Thread samppi

Oh, no. I was just wondering if there was a standard variable devoted
to it. A symbol would be aesthetically less clutter than #(%), even if
it'd take more typing. But if there isn't any other than the slow
apply function, I'm happy with #(%) too. :)

On Oct 21, 6:33 pm, John Harrop jharrop...@gmail.com wrote:
 On Wed, Oct 21, 2009 at 7:49 PM, samppi rbysam...@gmail.com wrote:
  Is there a standard function that takes one argument and calls it?
  That is, the function equivalent to #(%). Or is that the best idiom
  there is?

 #(%) is only four characters. Calling apply with only one argument also does
 this, and apply is five characters. Did you want a third one for some
 reason? :)
--~--~-~--~~~---~--~~
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: Standard calling-a-function function?

2009-10-21 Thread John Harrop
On Wed, Oct 21, 2009 at 11:50 PM, samppi rbysam...@gmail.com wrote:

 Oh, no. I was just wondering if there was a standard variable devoted
 to it. A symbol would be aesthetically less clutter than #(%), even if
 it'd take more typing. But if there isn't any other than the slow
 apply function, I'm happy with #(%) too. :)


Why settle?

(definline call [arg] `(~arg))

user= (defn foo [] (println foo!))
#'user/foo
user= (foo)
foo!
nil
user= (call foo)
foo!
nil
user= (defn bar [] (println bar!))
#'user/bar
user= (doall (map call [foo bar]))
foo!
bar!
(nil nil)

And since it's definlined, it should be no slower to (call foo) than to
(foo) when not passing call to a higher-order function such as map, and if
you do, it should be no slower than passing #(%).

--~--~-~--~~~---~--~~
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: Standard calling-a-function function?

2009-10-21 Thread John Harrop
On Thu, Oct 22, 2009 at 12:19 AM, John Harrop jharrop...@gmail.com wrote:

 On Wed, Oct 21, 2009 at 11:50 PM, samppi rbysam...@gmail.com wrote:

 Oh, no. I was just wondering if there was a standard variable devoted
 to it. A symbol would be aesthetically less clutter than #(%), even if
 it'd take more typing. But if there isn't any other than the slow
 apply function, I'm happy with #(%) too. :)


 Why settle?

 (definline call [arg] `(~arg))


And this is especially cute:

user= (map call (map constantly [1 2 3]))
(1 2 3)

map call and map constantly are actually inverse operations.

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