Re: - operator and monads
Yes, I said that it's *like *function composition in reverse order. And only if you apply the function returned by comp, as I did in my example. It's not to be taken too literally, but it is perhaps helpful for people coming from language that have function composition but no analogue to -. On Sunday, 14 April 2013 21:03:20 UTC+1, Marko Topolnik wrote: On Sunday, April 14, 2013 7:51:10 PM UTC+2, Matthew Hill wrote: Function composition is done via comp. Using - and - is like function composition in reverse order (though there's a difference between how the two thread return values), and often it reads more naturally. - applies the functions immediately whereas comp returns a new function that is the composition of its arguments. - works with functions of any arity; comp only with unary functions. As pointed out above, - merely combines the unevaluated forms it is given, and only if they happen to be function application forms will the result be similar to function composition. -marko -- -- 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: - operator and monads
Function composition is done via comp. Using - and - is like function composition in reverse order (though there's a difference between how the two thread return values), and often it reads more naturally. user (- [1 2 5] rest first) 2 user ((comp first rest) [1 2 5]) 2 On Wednesday, 3 April 2013 19:21:43 UTC+1, Plinio Balduino wrote: Hi there Is it correct to say that - operator is a kind of monad in Clojure? Thank you in advance. Plínio Balduino -- -- 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: - operator and monads
On Sunday, April 14, 2013 7:51:10 PM UTC+2, Matthew Hill wrote: Function composition is done via comp. Using - and - is like function composition in reverse order (though there's a difference between how the two thread return values), and often it reads more naturally. - applies the functions immediately whereas comp returns a new function that is the composition of its arguments. - works with functions of any arity; comp only with unary functions. As pointed out above, - merely combines the unevaluated forms it is given, and only if they happen to be function application forms will the result be similar to function composition. -marko -- -- 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: - operator and monads
On Sun, Apr 14, 2013 at 1:03 PM, Marko Topolnik marko.topol...@gmail.comwrote: On Sunday, April 14, 2013 7:51:10 PM UTC+2, Matthew Hill wrote: Function composition is done via comp. Using - and - is like function composition in reverse order (though there's a difference between how the two thread return values), and often it reads more naturally. - applies the functions immediately whereas comp returns a new function that is the composition of its arguments. - works with functions of any arity; comp only with unary functions. As pointed out above, - merely combines the unevaluated forms it is given, and only if they happen to be function application forms will the result be similar to function composition. Even that's somewhat misleading. user= (defn make-adder [n] (fn [x] (+ n x))) #'user/make-adder user= ((comp println (make-adder 4)) 3) 7 nil user= (- 3 (make-adder 4) println) ArityException Wrong number of args (2) passed to: user$make-adder clojure.lang.AFn.throwArity (AFn.java:437) user= (- 3 ((make-adder 4)) println) 7 nil (make-adder 4) is a function application form but the result isn't similar to function composition because the threading operators rewrite their arguments, so we end up with (make-adder 3 4). If it were expected that all arguments but the first would be functions, rather than lists corresponding to function-invocations-with-one-argument-deleted, then - *could* be equivalent to function composition (and could be written as a regular function): user= (defn -* [a cs] ((apply comp (reverse cs)) a)) #'user/-* user= (-* 3 (make-adder 4) println) 7 nil user= (-* [1 2 3] (partial map inc) set #(contains? % 4)) true -- Ben Wolfson Human kind has used its intelligence to vary the flavour of drinks, which may be sweet, aromatic, fermented or spirit-based. ... Family and social life also offer numerous other occasions to consume drinks for pleasure. [Larousse, Drink entry] -- -- 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: - operator and monads
if you come from the haskell world, it is like . piplining - but in reverse order I needed some time to get used to it but I really like - - as- ... to structure my code. It helps to see the sequence of functions that operate on your data On Wed, Apr 3, 2013 at 11:05 PM, Alan Malloy a...@malloys.org wrote: Not even that: - is not a function composition operator at all, but a form-rewriting macro. You can perfectly well write (- [x xs] (for (inc x))) to get (for [x xs] (inc x)), and that is not composing any functions. The two things are entirely separate. On Wednesday, April 3, 2013 12:45:55 PM UTC-7, Marko Topolnik wrote: I guess you mean the monadic bind operation, but - is not it. The only conceptual connection between *bind* and - is that they are both some kind of function composition operators. -marko On Wednesday, April 3, 2013 8:21:43 PM UTC+2, Plinio Balduino wrote: Hi there Is it correct to say that - operator is a kind of monad in Clojure? Thank you in advance. Plínio Balduino -- -- 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.
Re: - operator and monads
Isn't the dot just like Clojure's *comp*? As Allan correctly points out, the thrushes are macros that combine the given forms in a specified way, which only under certain constraints has the effect of composing function applications, whereas *comp* is truly a function composition operator. On Thursday, April 4, 2013 4:25:18 PM UTC+2, Maik Schünemann wrote: if you come from the haskell world, it is like . piplining - but in reverse order I needed some time to get used to it but I really like - - as- ... to structure my code. It helps to see the sequence of functions that operate on your data On Wed, Apr 3, 2013 at 11:05 PM, Alan Malloy al...@malloys.orgjavascript: wrote: Not even that: - is not a function composition operator at all, but a form-rewriting macro. You can perfectly well write (- [x xs] (for (inc x))) to get (for [x xs] (inc x)), and that is not composing any functions. The two things are entirely separate. On Wednesday, April 3, 2013 12:45:55 PM UTC-7, Marko Topolnik wrote: I guess you mean the monadic bind operation, but - is not it. The only conceptual connection between *bind* and - is that they are both some kind of function composition operators. -marko On Wednesday, April 3, 2013 8:21:43 PM UTC+2, Plinio Balduino wrote: Hi there Is it correct to say that - operator is a kind of monad in Clojure? Thank you in advance. Plínio Balduino -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email to clo...@googlegroups.comjavascript: 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/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.
- operator and monads
Hi there Is it correct to say that - operator is a kind of monad in Clojure? Thank you in advance. Plínio Balduino -- -- 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: - operator and monads
I guess you mean the monadic bind operation, but - is not it. The only conceptual connection between *bind* and - is that they are both some kind of function composition operators. -marko On Wednesday, April 3, 2013 8:21:43 PM UTC+2, Plinio Balduino wrote: Hi there Is it correct to say that - operator is a kind of monad in Clojure? Thank you in advance. Plínio Balduino -- -- 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: - operator and monads
Now it's clear. Thank you Plínio On Wed, Apr 3, 2013 at 4:45 PM, Marko Topolnik marko.topol...@gmail.comwrote: I guess you mean the monadic bind operation, but - is not it. The only conceptual connection between *bind* and - is that they are both some kind of function composition operators. -marko On Wednesday, April 3, 2013 8:21:43 PM UTC+2, Plinio Balduino wrote: Hi there Is it correct to say that - operator is a kind of monad in Clojure? Thank you in advance. Plínio Balduino -- -- 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.
Re: - operator and monads
Not even that: - is not a function composition operator at all, but a form-rewriting macro. You can perfectly well write (- [x xs] (for (inc x))) to get (for [x xs] (inc x)), and that is not composing any functions. The two things are entirely separate. On Wednesday, April 3, 2013 12:45:55 PM UTC-7, Marko Topolnik wrote: I guess you mean the monadic bind operation, but - is not it. The only conceptual connection between *bind* and - is that they are both some kind of function composition operators. -marko On Wednesday, April 3, 2013 8:21:43 PM UTC+2, Plinio Balduino wrote: Hi there Is it correct to say that - operator is a kind of monad in Clojure? Thank you in advance. Plínio Balduino -- -- 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.