Re: wouldn't it make sense for identity to take variadic args?
The multi-arity version of your function, which I would definitely not call identity, could be something along the lines of (fn [ args] (first args)) On 27 February 2013 14:22, Jim foo.bar jimpil1...@gmail.com wrote: On 27/02/13 13:10, Marko Topolnik wrote: A side note: since spans? is a constant within the map transform, it would pay to decide up-front which function to use: nice catch! Jim ps: thanks a lot for your comments :) -- -- 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/groups/opt_out. -- -- 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/groups/opt_out.
wouldn't it make sense for identity to take variadic args?
I often find myself asking for identity of something but identity takes a single argument! Why not have it take as many as one likes but only return the identity of the first? I find that very handy...do people agree? (defn identity Returns its argument or its first argument when there are more. {:added 1.0 :static true} ([x] x) ([x more] x)) Jim -- -- 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/groups/opt_out.
Re: wouldn't it make sense for identity to take variadic args?
Can you give an example use case? Personally, I would be a little surprised to find out that identity worked like this. After all, why return the first argument, why not the last? Or a vector of all the arguments? Cheers, Chris On 27 February 2013 15:02, Jim foo.bar jimpil1...@gmail.com wrote: I often find myself asking for identity of something but identity takes a single argument! Why not have it take as many as one likes but only return the identity of the first? I find that very handy...do people agree? (defn identity Returns its argument or its first argument when there are more. {:added 1.0 :static true} ([x] x) ([x more] x)) Jim -- -- 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+unsubscribe@**googlegroups.comclojure%2bunsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/**group/clojure?hl=enhttp://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+unsubscribe@**googlegroups.comclojure%2bunsubscr...@googlegroups.com . For more options, visit https://groups.google.com/**groups/opt_outhttps://groups.google.com/groups/opt_out . -- -- 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/groups/opt_out.
Re: wouldn't it make sense for identity to take variadic args?
On 27/02/13 12:12, Chris Ford wrote: Can you give an example use case? sure... sometimes I do something this: (map (if even? (fn [num _] (identity spans)) str) some-seq1 some-seq2) but I'd like to write this instead: (map (if even? identity str) some-seq1 some-seq2) Personally, I would be a little surprised to find out that identity worked like this. After all, why return the first argument, why not the last? Or a vector of all the arguments? the idea is to we keep the same semantics as we currently have... Jim -- -- 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/groups/opt_out.
Re: wouldn't it make sense for identity to take variadic args?
thinking about it a bit more, it would certainly make sense to return a seq with all the identities. Then I can just ask for the first...hmm interesting :) Jim On 27/02/13 12:20, Jim foo.bar wrote: On 27/02/13 12:12, Chris Ford wrote: Can you give an example use case? sure... sometimes I do something this: (map (if even? (fn [num _] (identity spans)) str) some-seq1 some-seq2) but I'd like to write this instead: (map (if even? identity str) some-seq1 some-seq2) Personally, I would be a little surprised to find out that identity worked like this. After all, why return the first argument, why not the last? Or a vector of all the arguments? the idea is to we keep the same semantics as we currently have... Jim -- -- 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/groups/opt_out.
Re: wouldn't it make sense for identity to take variadic args?
Apparently you misunderstand the term *identity*. The sense is the same as in *identity transform*: it is a function that transforms its argument into itself. It is useful in the context of higher-order functions where it plays the role of a no-op. None of your uses of *identity* make sense to me. On Wednesday, February 27, 2013 1:20:56 PM UTC+1, Jim foo.bar wrote: On 27/02/13 12:12, Chris Ford wrote: Can you give an example use case? sure... sometimes I do something this: (map (if even? (fn [num _] (identity spans)) str) some-seq1 some-seq2) but I'd like to write this instead: (map (if even? identity str) some-seq1 some-seq2) Personally, I would be a little surprised to find out that identity worked like this. After all, why return the first argument, why not the last? Or a vector of all the arguments? the idea is to we keep the same semantics as we currently have... Jim -- -- 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/groups/opt_out.
Re: wouldn't it make sense for identity to take variadic args?
On 27/02/13 12:35, Marko Topolnik wrote: it is a function that transforms its argument into itself. It is useful in the context of higher-order functions where it plays the role of a no-op that is exactly what I'm trying to do..a no-op based on some condition...Though, I can see why it would be confusing to just return the first arg...what exactly makes no sense? Jim -- -- 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/groups/opt_out.
Re: wouldn't it make sense for identity to take variadic args?
In this line: (map (if even? (fn [num _] (identity spans)) str) some-seq1 some-seq2) you appear to involve *identity* in a way that makes no sense since (identity spans) is just spans. You also don't involve the *num* argument at all; but maybe you meant (map (if even? (fn [num _] num) str) some-seq1 some-seq2) Then I'd see what you mean, even though I wouldn't call that function * identity* because it clearly does something more specialized than a no-op: it *ignores* the element coming from some-seq2. It would be quite confusing to see a function named *identity* do that. On Wednesday, February 27, 2013 1:39:54 PM UTC+1, Jim foo.bar wrote: On 27/02/13 12:35, Marko Topolnik wrote: it is a function that transforms its argument into itself. It is useful in the context of higher-order functions where it plays the role of a no-op that is exactly what I'm trying to do..a no-op based on some condition...Though, I can see why it would be confusing to just return the first arg...what exactly makes no sense? Jim -- -- 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/groups/opt_out.
Re: wouldn't it make sense for identity to take variadic args?
On 27/02/13 12:52, Marko Topolnik wrote: In this line: (map (if even? (fn [num _] (identity spans)) str) some-seq1 some-seq2) you appear to involve /identity/ in a way that makes no sense since (identity spans) is just spans. You also don't involve the /num/ argument at all; but maybe you meant Ooops! I do apologize cos in my effort to provide a minimal example I copy-pasted wrongly! The actual code looks like this: (let [tok-array (into-array ^String token-seq)] (map #((if spans? (fn [span _] span) spans-strings) ;;decide what fn to use (.find this tok-array) tok-array) token-seq) As you can see I am sort of creating my own version of identity (fn [span _] span) because I cannot use 'identity' with 2 args. This is my use-case...It should make sense now yes? Jim -- -- 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/groups/opt_out.
Re: wouldn't it make sense for identity to take variadic args?
On Wednesday, February 27, 2013 2:02:36 PM UTC+1, Jim foo.bar wrote: The actual code looks like this: (let [tok-array (into-array ^String token-seq)] (map #((if spans? (fn [span _] span) spans-strings) ;;decide what fn to use (.find this tok-array) tok-array) token-seq) As you can see I am sort of creating my own version of identity (fn [span _] span) because I cannot use 'identity' with 2 args. This is my use-case...It should make sense now yes? Jim Yes, that's it. As I said, I wouldn't want *identity* to do that and find it perfectly reasonable to require a special function for this behavior. A side note: since *spans?* is a constant within the *map* transform, it would pay to decide up-front which function to use: (let [f (if spans? (fn [span _] span) spans-strings)] (map f (.find this tok-array) tok-array)) -- -- 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/groups/opt_out.
Re: wouldn't it make sense for identity to take variadic args?
On 27/02/13 13:10, Marko Topolnik wrote: A side note: since /spans?/ is a constant within the /map/ transform, it would pay to decide up-front which function to use: nice catch! Jim ps: thanks a lot for your comments :) -- -- 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/groups/opt_out.