Commit c1432021 authored by Michael Hanus 's avatar Michael Hanus
Browse files

Global associations removed (now in package `assoc-legacy`)

parent 721478e9
......@@ -2,7 +2,7 @@
--- Library with some useful extensions to the IO monad.
---
--- @author Michael Hanus
--- @version January 2017
--- @version March 2021
------------------------------------------------------------------------------
{-# LANGUAGE CPP #-}
......@@ -11,8 +11,6 @@ module System.IOExts
execCmd, evalCmd, connectToCommand
-- file access
, readCompleteFile,updateFile, exclusiveIO
-- associations
, setAssoc,getAssoc
-- IORef
, IORef, newIORef, readIORef, writeIORef, modifyIORef
) where
......@@ -147,21 +145,3 @@ exclusiveIO lockfile action = do
(\e -> deleteLockFile >> ioError e)
where
deleteLockFile = system $ "lockfile-remove --lock-name " ++ lockfile
--- Defines a global association between two strings.
--- Both arguments must be evaluable to ground terms before applying
--- this operation.
setAssoc :: String -> String -> IO ()
setAssoc key val = (prim_setAssoc $## key) $## val
prim_setAssoc :: String -> String -> IO ()
prim_setAssoc external
--- Gets the value associated to a string.
--- Nothing is returned if there does not exist an associated value.
getAssoc :: String -> IO (Maybe String)
getAssoc key = prim_getAssoc $## key
prim_getAssoc :: String -> IO (Maybe String)
prim_getAssoc external
{-# LANGUAGE MultiParamTypeClasses #-}
import Data.IORef
import System.IO.Unsafe (unsafePerformIO) -- for global associations
import System.Process (readProcessWithExitCode, runInteractiveCommand)
import Control.Concurrent (forkIO)
import System.IO
......@@ -31,23 +30,3 @@ forwardError h = do
-----------------------------------------------------------------------
-- Implementation of global associations as simple association lists
-- (could be later improved by a more efficient implementation, e.g., maps)
type Assocs = [(String,String)]
assocs :: IORef Assocs
assocs = unsafePerformIO (newIORef [])
external_d_C_prim_setAssoc :: Curry_Prelude.C_String -> Curry_Prelude.C_String -> Cover -> ConstStore
-> Curry_Prelude.C_IO Curry_Prelude.OP_Unit
external_d_C_prim_setAssoc str1 str2 _ _ = toCurry
(\key val -> do as <- readIORef assocs
writeIORef assocs ((key,val):as)) str1 str2
external_d_C_prim_getAssoc :: Curry_Prelude.C_String -> Cover -> ConstStore
-> Curry_Prelude.C_IO (Curry_Prelude.C_Maybe (Curry_Prelude.C_String))
external_d_C_prim_getAssoc str _ _ = toCurry
(\key -> do as <- readIORef assocs
return (lookup key as)) str
......@@ -3,19 +3,6 @@
% Prolog implementation of builtins of module System.IOExts:
%
:- dynamic globalAssoc/2.
'System.IOExts.prim_setAssoc'(Key,Val,'Prelude.()') :-
string2Atom(Key,KeyA),
(retract(globalAssoc(KeyA,_)) -> true ; true),
assertz(globalAssoc(KeyA,Val)),
!.
'System.IOExts.prim_getAssoc'(Key,R) :-
string2Atom(Key,KeyA),
(globalAssoc(KeyA,Val) -> R='Prelude.Just'(Val) ; R='Prelude.Nothing'),
!.
% shell command execution:
'System.IOExts.prim_execCmd'(CmdString,'Prelude.(,,)'(StdIn,StdOut,StdErr)) :-
string2Atom(CmdString,Cmd),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment