core.memoize

memo-swap! is misnamed

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

In order to be analogous to atoms, the current behavior of memo-swap! should be called memo-reset! since it overwrites the entire memo map. Similarly, there should be a function called memo-swap! that does an atomic swap operation on the memo cache so, for example, you can add a single value to the cache.

Activity

Hide
Sean Corfield added a comment - - edited

Good point! Backward compatibility could be maintained by checking if (map? base) – and perhaps giving a deprecation warning? – but users would have to be very careful that they would be manipulating the cache and core.memoize wraps raw values in IDeref instances so a simple

(memo-swap! f assoc [42] 99)

would not work – it would need to be

(memo-swap! f assoc [42] (delay 99))

which would make this the only place in the API where that is really exposed.

Show
Sean Corfield added a comment - - edited Good point! Backward compatibility could be maintained by checking if (map? base) – and perhaps giving a deprecation warning? – but users would have to be very careful that they would be manipulating the cache and core.memoize wraps raw values in IDeref instances so a simple
(memo-swap! f assoc [42] 99)
would not work – it would need to be
(memo-swap! f assoc [42] (delay 99))
which would make this the only place in the API where that is really exposed.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: