tbl.fnl 948 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. ;;; Lispy-Fennel (LF) --- The Functional Fennel Library
  2. ;;;
  3. ;;; Copyright (C) 2020 Kevin "The Nuclear" Bloom <nuclearkev@dragora.org>
  4. ;;;
  5. ;;; This file is part of LF.
  6. ;;;
  7. ;;; LF is free software: you can redistribute it and/or modify
  8. ;;; it under the terms of the MIT License.
  9. ;;;
  10. ;;; LF is distributed in the hope that it will be useful,
  11. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;;; MIT License for more details.
  14. ;;;
  15. ;;; You should have received a copy of the MIT License
  16. ;;; along with LF. If not, see <https://opensource.org/licenses/MIT>.
  17. (local tbl {})
  18. (fn tbl.find [val tbl]
  19. (var x nil)
  20. (each
  21. [k v (pairs tbl)]
  22. (when (= v val)
  23. (set x {k v})))
  24. x)
  25. (fn tbl.empty? [l]
  26. (not (next l)))
  27. (fn tbl.merge [t1 t2]
  28. "Perform a right merge on T1 and T2."
  29. (var tbl t1)
  30. (each [k v (pairs t2)]
  31. (tset tbl k v))
  32. tbl)
  33. tbl