Megatest

c.scm at [2c1a4adb23]
Login

File configf-testing/c.scm artifact 4d512f0590 part of check-in 2c1a4adb23


;; pretend to be a config file processor
(use posix srfi-69)

;; (define getenv get-environment-variable)
(define (print-hash-table ht)
  (print "ht=" (hash-table->alist ht)))

(define cfgdata  (conc "(use simple-md5)"
		       "(set! getenv get-environment-variable)"
		       "(hash-table-set! ht \"PATH\" (getenv \"PATH\"))"
		       "(hash-table-set! ht \"currdir\" (current-directory))"
		       "(hash-table-set! ht \"md5sum\" (string->md5sum \"Hello\"))"))

(define (faux-cfg-processor ht cfgdata)
  (let* ((proc-str (conc "(lambda (ht)" cfgdata ")")))
    (with-input-from-string proc-str
      (lambda ()
	((eval (read)) ht)))))

(module cfgprocessor
	*

(import ports data-structures chicken scheme files srfi-69 posix srfi-1)
	
(define (faux-cfg-processor-modularized ht cfgdata)
  (let* ((proc-str (conc "(lambda (ht)" cfgdata ")")))
    (with-input-from-string proc-str
      (lambda ()
	((eval (read)) ht)))))
)

(import cfgprocessor)

(print "\nRun the non-modularized version")
(let ((ht (make-hash-table)))
  (faux-cfg-processor ht cfgdata)
  (print-hash-table ht))

(print "\nRun the modularized version")
(let ((ht (make-hash-table)))
  (faux-cfg-processor-modularized ht cfgdata)
  (print-hash-table ht))