arc> (= l '(1 2 3))
(1 2 3)
arc> (= f [+ _ 1])
#<fn: f>
arc> (map l '(0 1 2))
(1 2 3)
arc> (map f '(0 1 2))
(1 2 3) arc> (= l '(1 2 3))
(1 2 3)
arc> (= f [+ _ 1])
#<fn: f>
arc> (map l '(0 1 2))
(1 2 3)
arc> (map f '(0 1 2))
(1 2 3)For the benefit of people familiar with Common Lisp:
* (= ...) is assignment, not equality testing
* (map list index-list) is equivalent to (loop for index in index-list collecting (nth index list)), or in a more FP style (mapcar (rcurry #'nth list) index-list)
* (map function list) is equivalent to (mapcar function list)
I think your example would have been less confusing if it used larger numbers to highlight where addition was happening and where indexing was happening: arc> (= l '(4 5 6))
(4 5 6)
arc> (= f [+ _ 10])
#<fn: f>
arc> (map l '(2 1 0 0))
(6 5 4 4)
arc> (map f '(0 1 2))
(10 11 12)And looks like an easy trap for misreading code ...
arc> (map l '(0 1 2))
(1 2 3)
What is the logic here? Is l made into a function that holds state and returns each element in turn (like an iterator function)? Because I would've expected: arc> (map l '(0 1 2))
((1 2 3) (1 2 3) (1 2 3))
In what way is map being applied here?> In Arc, data structures can be used wherever functions are, and they behave as functions from indices to whatever's stored there.
(quoted from the Arc tutorial)
So
arc> (l 0)
1
and so on. So the GP makes sense.But I like this particular feature. If you think about it, an array is a mathematical function, or map, from indices to values. So it makes sense to be able to apply it to indices to get the respective values.
1
and l
in the same code listing.Clojure is definitely better thought out as a language, and while Arc has some interesting ideas around web development, it also doesn't have a module system, so everything is just loaded into the same global namespace, which is pretty insane.
I don't know that any programming language can be everything it needs to be from the outset, but it certainly needs inherent featured supporting longevity, a framework that supports change and evolution, while still having a pleasing and useful function that can be taken advantage of immediately.
To say they are functions would be incorrect. By the same logic, a keyword is would be a function.
Oh and (#{1 2} 3) is equivalent to (get #{1 2} 3) not (contains? #{1 2} 3)
So point taken.