util.lisp 650 B

12345678910111213141516171819202122
  1. (def! inc (fn* [a] (i+ a 1)))
  2. (def! gensym
  3. (let* [counter (atom 0)]
  4. (fn* []
  5. (symbol (str "G__" (swap! counter inc))))))
  6. ;; Like load-file, but will never load the same path twice.
  7. ;; This file is normally loaded with `load-file`, so it needs a
  8. ;; different mechanism to neutralize multiple inclusions of
  9. ;; itself. Moreover, the file list should never be reset.
  10. (def! load-file-once
  11. (try*
  12. load-file-once
  13. (catch* _
  14. (let* [seen (atom {"../lib/util.mal" nil})]
  15. (fn* [filename]
  16. (if (not (contains? @seen filename))
  17. (do
  18. (swap! seen assoc filename nil)
  19. (load-file filename))))))))