tag:blogger.com,1999:blog-12467669.post2249131847358454413..comments2023-04-29T07:23:25.825-04:00Comments on Jay Fields' Thoughts: Clojure: DestructuringJayhttp://www.blogger.com/profile/14491442812573747680noreply@blogger.comBlogger10125tag:blogger.com,1999:blog-12467669.post-34721203206312231932012-12-15T04:37:58.310-05:002012-12-15T04:37:58.310-05:00Thanks for sharing this.Thanks for sharing this.firesofmayhttps://www.blogger.com/profile/02198451649692833106noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-34863797418678206182012-12-15T04:37:20.633-05:002012-12-15T04:37:20.633-05:00This was really helpful. Thanks for sharing.This was really helpful. Thanks for sharing.firesofmayhttps://www.blogger.com/profile/02198451649692833106noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-33164071483216390702012-07-03T15:16:34.004-04:002012-07-03T15:16:34.004-04:00I come back again and again to this post as a refe...I come back again and again to this post as a reference. Terrifically useful. Thanks.Anonymoushttps://www.blogger.com/profile/10192515888062662552noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-36362782229654474722011-01-15T17:15:01.539-05:002011-01-15T17:15:01.539-05:00Weirdly, let* doesn't appear to support this, ...Weirdly, let* doesn't appear to support this, at least as of Clojure v1.2.0.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-82760898105059993962011-01-13T18:42:31.087-05:002011-01-13T18:42:31.087-05:00this post is very helpful to me, thanks!this post is very helpful to me, thanks!btw0https://www.blogger.com/profile/17884917107831603439noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-75278718121150560112010-07-28T03:08:23.161-04:002010-07-28T03:08:23.161-04:00Hi, one note about using destructuring for functio...Hi, one note about using destructuring for function arguments : by doing so, you're quite explicitly establishing a more detailed contract with the consumer of the function. That is, you open the internals of the passed arguments.<br /><br />Depending on the fact that the user may or may not be aware of the internals of the arguments, it may or may not be a good idea.<br /><br />So I tend to think about the use of destructuring function arguments directly in the function signature, depending on whether the "layout" of the arguments of the function is part of the user API.Laurent PETIThttps://www.blogger.com/profile/09137064608534274041noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-52825342291732382322010-07-27T19:29:28.666-04:002010-07-27T19:29:28.666-04:00Yes, all the directives can be used at the same ti...Yes, all the directives can be used at the same time. <br /><br />Cheers, JayAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-83221661043688159492010-07-27T17:31:13.104-04:002010-07-27T17:31:13.104-04:00Can you combine :as and :or et al?Can you combine :as and :or et al?Matt Toddhttp://maraby.org/noreply@blogger.comtag:blogger.com,1999:blog-12467669.post-20080326971695171412010-07-27T09:08:30.981-04:002010-07-27T09:08:30.981-04:00Good stuff Fogus, thanks.
Cheers, JayGood stuff Fogus, thanks.<br /><br />Cheers, JayAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-12467669.post-82055764503463525592010-07-27T08:26:58.538-04:002010-07-27T08:26:58.538-04:00Nice post. One other note that naturally follows ...Nice post. One other note that naturally follows from the end of your post is that destructuring forms the basis of Clojure's named arguments:<br /><br />(defn print-status [& {name :name [hole1 hole2] :scores}] <br /> (println "name:" name "hole1:" hole1 "hole2:" hole2))<br /><br />(print-status :name "Joey" :scores [42 18])<br /><br /><br />You can also use pre-conditions to check if certain arguments are passed in:<br /><br /><br />(defn print-status [& {name :name [hole1 hole2] :scores}]<br />{:pre [name]}<br /> (println "name:" name "hole1:" hole1 "hole2:" hole2))<br /><br />(print-status :scores [42 18])<br />; java.lang.AssertionError: Assert failed: name<br /><br />(print-status :name "Joey" :scores [42 18])<br />; name: Joey hole1: 42 hole2: 18<br /><br /><br />:ffogushttp://joyofclojure.comnoreply@blogger.com