Re: Function syntax

2015-08-13 Thread Herwig Hochleitner
2015-08-13 10:08 GMT+02:00 Eric Le Goff eleg...@gmail.com:

 I would be curious to know if there are difference (in terms of
 performance / elegance ) between those 2 ways of expressing functions

 E.g

 *(fn [ x] (- x sort last))*

 versus

 *#(last (sort %))*

 Both are supposedly equivalent, but would you recommend one preferred
 syntax , or this just a matter of personal style ?


#() is for very short functions, mostly just one-liners, where the (fn [])
would add significant noise.
The line is blurry and a matter of taste; upper limit is when you need a
nested fn, since #(#()) is not possible.
Performance is equivalent, since #() desugars into (fn [..]).

2015-08-13 10:14 GMT+02:00 Erik Assum e...@assum.net:

 (comp last sort)


That's not the same function as #(last (sort %))
The equivalent would be (comp last sort vec)

cheers

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


Re: Function syntax

2015-08-13 Thread Erik Assum
(comp last sort)

Erik. 
-- 
i farta

 Den 13. aug. 2015 kl. 10.08 skrev Eric Le Goff eleg...@gmail.com:
 
 I would be curious to know if there are difference (in terms of performance / 
 elegance ) between those 2 ways of expressing functions
 
 E.g
 
 (fn [ x] (- x sort last))
 
 versus 
 
 #(last (sort %))
 
 Both are supposedly equivalent, but would you recommend one preferred syntax 
 , or this just a matter of personal style ?
 
 Thanks
 --
 Eric Le Goff
 http://fr.linkedin.com/in/elegoff
 @elegoff
 
 -- 
 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.

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


Re: Function syntax

2015-08-13 Thread Amith George

Hi,

That's not the same function as #(last (sort %))
 The equivalent would be (comp last sort vec)


Could you please explain why is the `vec` needed? From what I understand, 
we are expected to treat the variadic args argument as a seq, nothing more. 



On Thursday, 13 August 2015 14:02:38 UTC+5:30, Herwig Hochleitner wrote:

 2015-08-13 10:08 GMT+02:00 Eric Le Goff ele...@gmail.com javascript::

 I would be curious to know if there are difference (in terms of 
 performance / elegance ) between those 2 ways of expressing functions

 E.g

 *(fn [ x] (- x sort last))*

 versus 

 *#(last (sort %))*

 Both are supposedly equivalent, but would you recommend one preferred 
 syntax , or this just a matter of personal style ?


 #() is for very short functions, mostly just one-liners, where the (fn []) 
 would add significant noise.
 The line is blurry and a matter of taste; upper limit is when you need a 
 nested fn, since #(#()) is not possible.
 Performance is equivalent, since #() desugars into (fn [..]). 

 2015-08-13 10:14 GMT+02:00 Erik Assum er...@assum.net javascript::

 (comp last sort)


 That's not the same function as #(last (sort %))
 The equivalent would be (comp last sort vec)

 cheers


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


Re: Function syntax

2015-08-13 Thread Amith George
Hi,

I originally interpreted Erik's reply to mean - Instead of `#(last (sort 
%))` do `#((comp last sort) %)`. This works without any issue. 

Herwig's suggestion was about replacing the entire anonymous function with 
`(comp last sort vec)`. The example you gave `((comp last sort) 3 2 1)`, 
even if we make it `((comp last sort vec) 3 2 1)`, it will throw an error 
about `vec` being called with too many parameters. 

For it to work with variable args, as Herwig said in his reply to me, we 
need a function that can return a sequence from a varargs. `vector` or 
`list would work, not `vec`. It should be `((comp last sort list) 3 2 1)`. 
Please correct me if I am understanding this wrong.



On Thursday, 13 August 2015 16:13:24 UTC+5:30, Tassilo Horn wrote:

 Amith George strid...@gmail.com javascript: writes: 

  That's not the same function as #(last (sort %)) 
  The equivalent would be (comp last sort vec) 
  
  Could you please explain why is the `vec` needed?  From what I 
  understand, we are expected to treat the variadic args argument as a 
  seq, nothing more. 

 With ((comp last sort) 3 2 1), sort will be called as 

   (apply sort (list 3 2 1)) 

 which essentially is 

   (sort 3 2 1). 

 Hovever, sort is no varargs function but wants a collection. 

 Bye, 
 Tassilo 


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


Re: Function syntax

2015-08-13 Thread Tassilo Horn
Amith George strider...@gmail.com writes:

 That's not the same function as #(last (sort %))
 The equivalent would be (comp last sort vec)

 Could you please explain why is the `vec` needed?  From what I
 understand, we are expected to treat the variadic args argument as a
 seq, nothing more.

With ((comp last sort) 3 2 1), sort will be called as

  (apply sort (list 3 2 1))

which essentially is

  (sort 3 2 1).

Hovever, sort is no varargs function but wants a collection.

Bye,
Tassilo

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


Re: Function syntax

2015-08-13 Thread Amith George
Maybe you meant to use `vector` instead of `vec`? `vec` doesn't accept 
variable args. Hence my original question. 

On Thursday, 13 August 2015 16:24:43 UTC+5:30, Herwig Hochleitner wrote:

 2015-08-13 11:13 GMT+02:00 Amith George strid...@gmail.com javascript:
 :


 Could you please explain why is the `vec` needed? From what I understand, 
 we are expected to treat the variadic args argument as a seq, nothing more. 


 What Tassilo said.
 Also, it's not nessecary to use `vec`, but you need a function that 
 creates a seqable from varargs, like vec, list, ... .
 That's what the  rest argument syntax does for you: create a collection 
 object from a variable number of arguments.
 ​


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


Re: Function syntax

2015-08-13 Thread Herwig Hochleitner
2015-08-13 11:13 GMT+02:00 Amith George strider...@gmail.com:


 Could you please explain why is the `vec` needed? From what I understand,
 we are expected to treat the variadic args argument as a seq, nothing more.


What Tassilo said.
Also, it's not nessecary to use `vec`, but you need a function that creates
a seqable from varargs, like vec, list, ... .
That's what the  rest argument syntax does for you: create a collection
object from a variable number of arguments.
​

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


Re: Function syntax

2015-08-13 Thread Herwig Hochleitner
Yep, I meant the thing, `vector` is doing. Thanks!

2015-08-13 13:36 GMT+02:00 Amith George strider...@gmail.com:

 Maybe you meant to use `vector` instead of `vec`? `vec` doesn't accept
 variable args. Hence my original question.

 On Thursday, 13 August 2015 16:24:43 UTC+5:30, Herwig Hochleitner wrote:

 2015-08-13 11:13 GMT+02:00 Amith George strid...@gmail.com:


 Could you please explain why is the `vec` needed? From what I
 understand, we are expected to treat the variadic args argument as a seq,
 nothing more.


 What Tassilo said.
 Also, it's not nessecary to use `vec`, but you need a function that
 creates a seqable from varargs, like vec, list, ... .
 That's what the  rest argument syntax does for you: create a collection
 object from a variable number of arguments.
 ​

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


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


Re: Function syntax

2015-08-13 Thread Leon Grapenthin
It is a matter of personal style.

Note that there is a max function.

On Thursday, August 13, 2015 at 1:53:23 PM UTC+2, Herwig Hochleitner wrote:

 Yep, I meant the thing, `vector` is doing. Thanks!

 2015-08-13 13:36 GMT+02:00 Amith George strid...@gmail.com javascript:
 :

 Maybe you meant to use `vector` instead of `vec`? `vec` doesn't accept 
 variable args. Hence my original question. 

 On Thursday, 13 August 2015 16:24:43 UTC+5:30, Herwig Hochleitner wrote:

 2015-08-13 11:13 GMT+02:00 Amith George strid...@gmail.com:


 Could you please explain why is the `vec` needed? From what I 
 understand, we are expected to treat the variadic args argument as a seq, 
 nothing more. 


 What Tassilo said.
 Also, it's not nessecary to use `vec`, but you need a function that 
 creates a seqable from varargs, like vec, list, ... .
 That's what the  rest argument syntax does for you: create a collection 
 object from a variable number of arguments.
 ​

 -- 
 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 
 javascript:
 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 javascript:
 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 javascript:.
 For more options, visit https://groups.google.com/d/optout.




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