From f1e9dc12e68f3f602a9b8e09f20b0922fc5bb6e2 Mon Sep 17 00:00:00 2001 From: "chris.double" Date: Thu, 3 Aug 2006 00:23:02 +0000 Subject: [PATCH] concurrency: fix lazy evaluation The 'lazy' word wasn't allowing multiple requests for the lazy value. It now caches the lazy value once it's computed and immediately returns it. --- contrib/concurrency/concurrency.factor | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/contrib/concurrency/concurrency.factor b/contrib/concurrency/concurrency.factor index 0061886036..077c5f98da 100644 --- a/contrib/concurrency/concurrency.factor +++ b/contrib/concurrency/concurrency.factor @@ -423,22 +423,16 @@ C: promise ( -- ) ! ****************************** ! Experimental code below ! ****************************** -SYMBOL: lazy-quot +: (lazy) ( v -- ) + receive over reply (lazy) ; : lazy ( quot -- lazy ) #! Spawn a process that immediately blocks and return it. #! When '?lazy' is called on the returned process, call the quotation #! and return the result. The quotation must have stack effect ( -- X ). - [ - [ - lazy-quot set - [ - [ tagged-message? [ [ drop t ] [ get call ] send-reply ] ] - ] recv - ] with-scope - ] curry spawn ; + [ receive >r call r> over reply (lazy) ] spawn nip ; : ?lazy ( lazy -- result ) #! Given a process spawned using 'lazy', evaluate it and return the result. - lazy-quot swap send-synchronous ; + f swap send-synchronous ;