[Python-ideas] dict.setdefault_call(), or API variations thereupon

Anders Hovmöller boxed at killingar.net
Fri Nov 2 20:15:04 EDT 2018


> defaultdict:
>    - takes a zero-argument factory function which is 
>      unconditionally called when the key is missing.
> 
> Did I miss any?
> 
> What we don't have is a version of setdefault where the default is 
> evaluated only on need. That would be a great use-case for Call-By-Name 
> semantics and thunks, if Python supported such :-)

Could you explain what the difference is between defaultdicts "factory which is unconditionally called when the key is missing" and "the default is evaluated only on need"? To me it seems that "unconditionally called when the key is missing" is a complex way of saying "called only when needed". I must be missing some nuance here.

/ Anders



More information about the Python-ideas mailing list