util.lisp 761 B

1234567891011121314151617181920212223242526
  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. (def! gensym2
  7. (let* [counter (atom 0)]
  8. (fn* [name]
  9. (symbol (str name "__" (swap! counter inc))))))
  10. ;; Like load-file, but will never load the same path twice.
  11. ;; This file is normally loaded with `load-file`, so it needs a
  12. ;; different mechanism to neutralize multiple inclusions of
  13. ;; itself. Moreover, the file list should never be reset.
  14. (def! load-file-once
  15. (try*
  16. load-file-once
  17. (catch* _
  18. (let* [seen (atom {"../lib/util.mal" nil})]
  19. (fn* [filename]
  20. (if (not (contains? @seen filename))
  21. (do
  22. (swap! seen assoc filename nil)
  23. (load-file filename))))))))