-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Comments inline On 08/15/2014 06:47 AM, Dave Tenny wrote: > This is getting old. Any suggestions or plans to fix it? Do I need to use > some other common declaration style for functions? > > ; CIDER 0.5.0 (Clojure 1.6.0, nREPL 0.2.3) > user> (defn foo [& {:keys [bar]}] bar) > #'user/foo > user> (foo :baz 1) > nil > > In my opinion the compilation of the call to foo should have complained about :baz not matching a known parameter.
At the implementation level, there is no "formal parameter" here. You've defined a variadic function, who's varargs are to be treated as a map key/value sequence, and the key ":bar" of which you wish to extract and bind to a local. "bar" here is _not_ a formal parameter of foo, it's simply a local destructured from the map converted varargs. > Failure to do this leads to lots of extra debugging because someone had a > typo in a keyword name, > e.g. ":Name" instead of ":name" or :product instead of :project, or whatever. > > This is probably the leading cause of unexpected program operation in clojure for me. For a number of implementation reasons, this is not something that clojure/core is ever likely to provide better support for. Prismatic's Schema, core.typed and aggressive use of preconditions are the best tools available for you to guard against these errors. For exactly this reason I have personally adopted the practice of asserting what equates to a full typecheck of all arguments in function preconditions. Clojure/core doesn't do this in the name of "performance", but for user code it's easy enough to remove typechecks if the overhead becomes significant. Reid -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBAgAGBQJT7j+QAAoJELjHpJOzPfTl2pAP/3IbqqxDayp5Vz7I2l3D1dE5 Eq4mFz3bjLrsR+th69xd6VWY4szTeeg09ub1NKUPQ2Uhm8EIMj1lFeZIHi9VmxNN zKASZ+l29ntDolChSLBM7JqQBWNYaLcPQQl4BTXi6BFy97TUFUq5IxKhIpvhgjQ+ HV9Csg7rGhvz3sQU55W/K3YwoIgf1Kjd18Ewa3KytbKgKbGiwYDAqfqPtaQn0V+K 709lPTDe/WNMCjW8AcKsCqQAOhRObxfLwdL9iBRrdJNSaj17Vy0p+0xXA8RXuiGk tdEF6MADOmquFxZko3tvkaJfizA/2wRwIzbvqByuGqfgVQgsDdUEbsC04tB5pMqi 8H/O7HZ5DnExeOmL6TcSuBW+wWwqptBvqI1QuplZX2BOfbu1/whozUXU9Jq0SQLp V+bB2nM9qO+c6lxF9o8Fep3UaGxU4eKwwviJ6i3e5+uEvZ0N6p6vY4+wJO8ezJnN s4UOiEEMjtfBo4CyBZGxcNW3XzLoM6/5kAt25nKRQHDSChqsH5vjFbvrP6oq7S1d 4HEcGKHdA2D8wrE5b3XkLwsRjpNmXXn1h5TdE5RB3DYqSmU56Dwrt08aew7gC7We OvFQpIX9F/gW6dFJzVxQka4MV1IkYT0JiNypKFyHXz3l3PkFMYR//W0ehsSlAkjT +E0U1+KjplF9RPZ98myw =sqVb -----END PGP SIGNATURE----- -- 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.