lib/Process-struct.ss
#lang scheme/base

(require (planet chongkai/sml/ml-package)
         scheme/system)

(provide Process-struct)

(define-package Process-struct (success failure system
                                        atExit exit terminate
                                        getEnv)
  (define success #t)
  (define failure #f)
  
  (define* system system)
  
  (define registered-actions
    (make-parameter '()))
  
  (define (atExit f)
    (registered-actions
     (cons f (registered-actions))))
  
  (define* (exit st)
    (set! atExit void)
    (for-each (lambda (f) (f (void)))
              (registered-actions))
    (exit st))
  
  (define terminate exit)
  
  (define getEnv getenv))