-- Implements the logical AND module QuicQuid.Agent.And(andAgent) where import Control.Concurrent import Control.Monad(forever) import QuicQuid.Router import qualified Data.Map as M import QuicQuid.Log import QuicQuid.Logic import QuicQuid.Agent.Util -- BUG: security problem, 'and' can be taken over by rogue agents. -- BUG: spawn agents are never stopped. -- BUG: inefficient, an agent for every combination of results? andAgent = answerAgent "and" "and ?preds" process where process qch = do (bs,replyCh) <- readAskChan qch let Just (Arr preds) = M.lookup "preds" bs andQuery M.empty preds replyCh andQuery bs [] outChan = write outChan $ Obj bs andQuery bs (q:qs) outChan = do debugM "QuicQuid.Agent.And.andQuery" $ show bs ++ " " ++ show (q:qs) forkIO $ do (ch,chName) <- newEndPoint "/tmp" newQuery_ q chName forever $ do Obj nbs <- readBody ch andQuery (M.union bs nbs) (map (substitute nbs) qs) outChan return ()