init.body.scm 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ;; Copyright (C) 2999 Your name.
  2. (define work-dir "")
  3. (define (set-work-dir! new-location)
  4. (set! work-dir new-location))
  5. (define (get-work-dir)
  6. work-dir)
  7. (define (initialize-module mod-name)
  8. ;; module name is a list, such as
  9. ;; '(a b c)
  10. ;; which will be created in workdir/a/b/c.sld
  11. (define (all-symbols? l)
  12. (equal? l (filter symbol? l)))
  13. (define (create-library-files path lib)
  14. (define sld-target (string-append path lib ".sld"))
  15. (define body-target (string-append path lib ".body.scm"))
  16. (define sld-contents
  17. `((define-library ,mod-name
  18. (import (scheme base))
  19. (export)
  20. (include ,(string-append lib ".body.scm")))))
  21. (define body-contents
  22. ";; Copyright (C) 2999 Your name.\n\n")
  23. (sexp-list->file sld-target sld-contents)
  24. (string->file body-target body-contents))
  25. (unless (and (pair? mod-name)
  26. (list? mod-name)
  27. (all-symbols? mod-name))
  28. (error "mod-name is not a non-empty list of symbols" mod-name))
  29. (let loop ((path work-dir)
  30. (rest mod-name))
  31. (cond
  32. ((null? (cdr rest))
  33. (create-library-files path (symbol->string (car rest))))
  34. (else
  35. (let ((new-path (string-append path
  36. (symbol->string (car rest))
  37. "/")))
  38. (make-directory* new-path)
  39. (loop new-path (cdr rest)))))))
  40. (define-syntax create-module
  41. (syntax-rules ()
  42. ((_ (a b ...))
  43. (initialize-module '(a b ...)))))