colonop.zy 474 B

1234567891011121314151617181920212223
  1. // colon operator works like aget on arrays
  2. (def a [4 5 6 7])
  3. (assert (== 4 (:0 a)))
  4. // symbol access
  5. (def y 1)
  6. (assert (== 5 (:y a)))
  7. // function access
  8. (defn g [] 0)
  9. (defn f [] 3)
  10. (assert (== 4 (:(g) a)))
  11. (assert (== 7 (:(f) a)))
  12. // colon operator works like hget on hashes
  13. (def h (hash karin:9 heath:10))
  14. (assert (== (:karin h) 9))
  15. (assert (== (:heath h) 10))
  16. // NB doesn't work because hash expects symbols as keys
  17. // (defn f [] %heath)
  18. // (assert (== (:(f) h) 10))