Talk:Function composition: Difference between revisions

Content added Content deleted
mNo edit summary
Line 155: Line 155:
:: Brilliant. No need for another task. --[[User:Paddy3118|Paddy3118]] 19:18, 14 June 2012 (UTC)
:: Brilliant. No need for another task. --[[User:Paddy3118|Paddy3118]] 19:18, 14 June 2012 (UTC)


:: Agreed. Although it is less elegant than composing multiple functions with a single call, it does demonstrate that a language supports function composition without having to resort to additional functional programming language features. I would still prefer to see the task defined more precisely because I'm afraid we'll end up with several (sin (asin (sin x))) implementations. I haven't come up with a good example (yet), but I think that changing the task description to include the following output should separate most of the wheat from the chaff. --[[User:Lhignight|Larry Hignight]] 23:00, 20 June 2012 (UTC)
:: Agreed. Although it is less elegant than composing multiple functions with a single call, it does demonstrate that a language supports function composition without having to resort to additional functional programming language features. I would still prefer to see the task defined more precisely because I'm afraid we'll end up with several (sin (asin (sin x))) implementations. I haven't come up with a good example (yet), but I think that changing the task description to include the following output should separate most of the wheat from the chaff.
::: Not sure I agree with you about elegance -- the syntax you have in your illustration here favors composing lists of functions but that's an implementation detail, it's not universal. For example, in J, composing f g and h looks like f@g@h and composing them as a list looks like <nowiki>(4 :'(x`:6)@(y`:6)`'''''/f`g`h)`:6</nowiki> -- I could define a '''compose''' word that encapsulates that complexity, but it would never beat f@g@h for directness.
::: That said, I added an implementation of your examples to the J implementation on the main page. ----[[User:Rdm|Rdm]] 23:21, 20 June 2012 (UTC)
<pre>;;Example Usage:
<pre>;;Example Usage:
;CL-USER> (compose f #'ceiling #'sin #'sqrt)
;CL-USER> (compose f #'ceiling #'sin #'sqrt)
Line 169: Line 167:
2.0L0
2.0L0
1
1
CL-USER> </pre> --[[User:Lhignight|Larry Hignight]] 23:00, 20 June 2012 (UTC)
CL-USER> </pre>
::: Not sure I agree with you about elegance -- the syntax you have in your illustration here favors composing lists of functions but that's an implementation detail, it's not universal. For example, in J, composing f g and h looks like f@g@h and composing them as a list looks like <nowiki>(4 :'(x`:6)@(y`:6)`'''''/f`g`h)`:6</nowiki> -- I could define a '''compose''' word that encapsulates that complexity, but it would never beat f@g@h for directness. That said, I added an implementation of your examples to the J implementation on the main page. ----[[User:Rdm|Rdm]] 23:21, 20 June 2012 (UTC)
:::: I didn't mean to suggest that the task or implementation should favor composing lists of functions. I find implementations that allow you to compose multiple functions in a straight-forward manner [eg (compose f #'1+ #'abs #'cos), Mathematica's Compose[f1,f2,f3...] and the J example that you provided] to be more elegant than nesting multiple calls to a composition function [eg (setf f (compose #'1+ (compose #'abs #'cos)))]. --[[User:Lhignight|Larry Hignight]] 09:56, 21 June 2012 (UTC)
: Rdm -- The example looks good. Given your experience with J, are there more advanced examples of function composition that you think should be included in the task description? I think it would be desirable to have easy, moderate and hard example problems. --[[User:Lhignight|Larry Hignight]] 09:56, 21 June 2012 (UTC)