util.lisp 713 B

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