Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/prelude/System/GetArgs.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


module System where

import NHC.FFI

foreign import ccall cGetArg      :: IO (Ptr Char)
foreign import cast  ptrToCString :: (Ptr Char) -> IO PackedString

getArgs  :: IO [String]
getArgs =
-- The use of unsafePerformIO followed by return is a slightly bizarre
-- way of ensuring that the stateful computation gets executed once
-- and once only.
  let args = unsafePerformIO (getThem ())
  in return args
 where
  getThem () = do
    a <- cGetArg
    if (a==nullPtr) then return []
      else do arg  <- ptrToCString a
              args <- getThem ()
              return (fromCString arg:args)

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.