Note Colin, if I had declared foo differenlty, e.g. (defn foo [a b {:keys [c d]}), that would be slightly different since it requires a map as third argument. But that is not the case with (defn foo [a b & {:keys [c d]}]). It may be using maps under the hood, but none of my formal parameters are necessarily intended to be bound to maps in this case, and I'm looking for a very fixed set of keywords in the function call.
On Sun, Aug 23, 2015 at 10:17 AM, Dave Tenny <dave.te...@gmail.com> wrote: > The point of my colorful title and judgmental post is that in the example, > passing :e for the declared parameters as declared is a pointless operation > at best, and in most practical situations it is also an erroneous > operation. > > The language designers have (arguably for the good) chosen to complain > about various actual argument mismatches vs. formal parameters. > > If I tried to call foo with only one argument I'd get an error about > missing arguments (or more generally, arity). > Similarly, in this case, calling foo with :e should complain about > superfluous arguments, all assuming that foo is declared as intended. > Without an :as option on the destructuring, there is nothing that can be > done to meaningfully process a keyword to the function named :e. > > I am proposing the language should do better in this case. If not now, > perhaps 2.0. > > > On Sat, Aug 22, 2015 at 9:06 PM, Colin Yates <colin.ya...@gmail.com> > wrote: > >> Hi Dave, it _isn't_ an Illegal argument though :-), your destructuring >> is simply ignoring that parameter. >> >> However, I get the pain and solutions might be (in order of 'heavyness'): >> - http://blog.fogus.me/2009/12/21/clojures-pre-and-post/ >> - https://github.com/Prismatic/schema >> - http://typedclojure.org/ >> >> HTH >> >> Dave Tenny writes: >> >> > I sure wish Clojure would generate "IllegalArgumentException" in the >> > following sample case: >> > >> > (defn foo [a b & {:keys [c d]}] 1) >> > (foo 1 2 :e 5) ; blithely ignores :e 5 >> > >> > I understand that Clojure's destructuring things are very nice, and more >> > powerful than Common Lisp's, and I like >> > that when I need it. >> > >> > However I can't tell you how many times I've been bitten by this. Some >> > simple typo or other other parameter name error on keyword arguments >> > with untended and way-too-long-to-debug consequences. >> > >> > In my mind, on this subject, Common Lisp lambda lists got this right and >> > Clojure gets a poor grade. >> > Something about being doomed to repeat history. In Common Lisp, if you >> > really wanted to allow other (arbitrary) keywords you'd >> > just use &allow-other-keys. >> > >> > Maybe clojure should only allow the above case to go >> un-complained-about if >> > :as was specified for the map. >> > >> > If there's some automatic enforcement I'm missing that comes with 'defn' >> > please let me know, I'm still learning the language. >> > >> > I've thought more that once about making a common lisp DEFUN statement >> that >> > maps to DEFN but implements >> > lambda list semantics (including 'supplied-p' parameters). I've just >> been >> > too lazy to do it. >> > >> > It would also likely perform poorly after injecting the additional >> > checks/rearrangements into the function on top of what Clojure has >> already >> > done, >> > so I suppose it would have to be taken a step further so that it didn't >> > generate DEFN expressions at all but was implemented at DEFN's level as >> > a seperately named form. >> > >> > Tips welcome. Just thinking aloud. >> > >> > - Dave >> >> -- >> Sent with my mu4e >> >> -- >> 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 a topic in the >> Google Groups "Clojure" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/clojure/3-CevvzQg1s/unsubscribe. >> To unsubscribe from this group and all its topics, send an email to >> clojure+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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.