Arc Forumnew | comments | leaders | submitlogin
2 points by thaddeus 5077 days ago | link | parent

> "Would that make having map and iterator functions always return cons less confusing?"

Yes it would/does. When I created my arc libraries, I built the normalization in. So I have a join function, which detects the type and applies the appropriate operation. I don't use conj, because I don't want to think about those things.

Interesting that you picked a string example, since that's exactly how Clojure already works. That is, using map on a string returns a list of chars. Often I need to:

  (apply str (map #{upcase %} "abc"))
For whatever reason I don't mind this, I expect strings get converted to lists.

However using my first example / sore spot:

  (let [myVector (atom [1 2 3])] 
    (doseq [x [4 5 6]]
      (reset! myVector (conj @myVector x)))
    @myVector)
Here, seeing only the vectors I would get caught thinking it would produce (1 2 3 4 5 6) instead you would get (6 5 4 1 2 3).

Of course I went and created two join functions with my arc functions.

  join : always adds to left side list or vector
  join> : always adds to right side list or vector

 (let [myVector (atom [1 2 3])] 
   (each x [4 5 6]
     (reset! myVector (join> x @myVector)))
   @myVector)
And I no longer have problems, I can see what's happening at the top level and it's consistent.

So in the end it's not such a big deal when your willing to normalize all the functions.

[note: I never tried out the code, it may not work, but you get the idea]



1 point by thaddeus 5077 days ago | link

In all the above examples I should have had adjoin not join. That's what happens when I don't have an environment in front of me :)

-----