4 ms·
I know this as memoization with lazy evaluation, nothing new, but at the same time very useful, and I would argue, it is very CS.
by Shorel 4y ago
I know this as memoization with lazy evaluation, nothing new, but at the same time very useful, and I would argue, it is very CS.
- sethammons 4y agoI've always called it request piggy backing (atop memoization). Our db abstraction at my last gig absolutely required it for scaling purposes. Great tool for the tool belt.
- hn_throwaway_99 4y agonot really quite lazy evaluation, thought, at least in Javascript. Promises begin execution as soon as they are created and there is no way to delay that.
- marcosdumay 4y agoPromises are an implementation of lazy evaluation for Javascript. This is exactly lazy evaluation. By the way, lazy evaluation is the one that offers no guarantees about when your code will be executed. If you can delay the execution, it's not lazy.
- anyfoo 4y agoWait. I thought lazy evaluation is defined as evaluation at the time a value is needed. After that I think it will then be in Weak Head Normal Form, which can be thought of as "evaluated at its top level"... but I'm a bit rusty. Basically, an expression gets used somewhere (e.g. pattern matched, in the ADT sense). If it's in WHNF, cool, it's evaluated already (subexpressions within may not yet, but that's their problem--that's exactly what WHNF says). If not, we evaluate it down to WHNF. Wikipedia states it as: "When using delayed evaluation, an expression is not evaluated as soon as it gets bound to a variable, but when the evaluator is forced to produce the expression's value." So if evaluation begins effectively at the time the promise is issued, not at the time the promise is awaited, then I would not call that lazy evaluation, and what hn_throwaway_99 said sounds correct to me. Is my rusty old PL understanding wrong?
- Sohcahtoa82 4y ago> Wait. I thought lazy evaluation is defined as evaluation at the time a value is needed. Correct. You've got it right, GP comment has it wrong. Lazy does not simply mean "evaluated later". From what I understand, in JS, if you call an async function without `await`, it essentially gets added to a queue of functions to execute. Once the calling function stack completes, the async function will be executed. A queue of functions to execute does not constitute "lazy evaluation" on its own.
- deleted 4y ago[deleted]
- cstrahan 4y agoDefinition on Wikipedia says otherwise: “In programming language theory, lazy evaluation, or call-by-need,[1] is an evaluation strategy which delays the evaluation of an expression until its value is needed (non-strict evaluation) and which also avoids repeated evaluations (sharing).” Haskell would be an apt example here.
- 9935c101ab17a66 4y agoPromises in javascript are absolutely not considered 'an implementation of lazy evaluation.' Promises are invoked eagerly in javascript.