Clojure

Adding a :only-keys destructuring option, that throws an exception if there's extra key(s).

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: Backlog
  • Component/s: None
  • Labels:
    None

Description

While discussing the issue that prompted ticket [[ticket:236]] on clojure-dev, Richard Newman suggested modifying map destructuring to incorporate a :only-keys. It works exactly like :keys but raises an exception if the destructured map contains other keys. The attached patch shows a possible implementation.

Activity

Hide
Assembla Importer added a comment -
Show
Assembla Importer added a comment - Converted from http://www.assembla.com/spaces/clojure/tickets/237 Attachments: 0001-Added-only-keys-destructuring-option-like-keys-but-t.patch - https://www.assembla.com/spaces/clojure/documents/bEnEvg-I4r3OA7eJe5afGb/download/bEnEvg-I4r3OA7eJe5afGb
Hide
Assembla Importer added a comment -

budu said: [file:bEnEvg-I4r3OA7eJe5afGb]: Add :only-keys destructuring option

Show
Assembla Importer added a comment - budu said: [file:bEnEvg-I4r3OA7eJe5afGb]: Add :only-keys destructuring option
Hide
Assembla Importer added a comment -

richhickey said: Could someone please review this patch? I'm ok with the idea in general, but it seems strange that the :only test would only be available for (non-renaming) :keys destructuring

Show
Assembla Importer added a comment - richhickey said: Could someone please review this patch? I'm ok with the idea in general, but it seems strange that the :only test would only be available for (non-renaming) :keys destructuring
Hide
Assembla Importer added a comment -

chouser@n01se.net said: One drawback to any such checking is it may prevent code written for a future version of the function that takes more named args from working at all with a previous version of the function. For example 'ref' now accepts :min-history. Code that uses that now would probably work fine with versions of ref that didn't support that knob, but if they checked to prevent extra args they would fail unnecessarily.

Show
Assembla Importer added a comment - chouser@n01se.net said: One drawback to any such checking is it may prevent code written for a future version of the function that takes more named args from working at all with a previous version of the function. For example 'ref' now accepts :min-history. Code that uses that now would probably work fine with versions of ref that didn't support that knob, but if they checked to prevent extra args they would fail unnecessarily.
Hide
Assembla Importer added a comment -

budu said: Good point, didn't think about that! We could recommend the use of :keys in early development and :only-keys when APIs become very stable.

Show
Assembla Importer added a comment - budu said: Good point, didn't think about that! We could recommend the use of :keys in early development and :only-keys when APIs become very stable.
Hide
Assembla Importer added a comment -

richhickey said: I don't see the need for this

Show
Assembla Importer added a comment - richhickey said: I don't see the need for this
Hide
Stuart Sierra added a comment -

Declined. There has been limited support for this ticket. It changes the concept of destructuring to include something more like validation, which it was not intended to support.

Show
Stuart Sierra added a comment - Declined. There has been limited support for this ticket. It changes the concept of destructuring to include something more like validation, which it was not intended to support.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: