(def mapstr (f . seqs)
(string (accum a (for i 0 (- (apply min (map1 len seqs)) 1)
(a (string (apply f (map1 [_ i] seqs))))))))
arc> (mapstr [string "." _] "test")
".t.e.s.t"
And we can plug that into the definition of map:
(def map (f . seqs)
(if (some [isa _ 'string] seqs)
(apply mapstr f seqs)
;; the rest is the same as the arc3.1 def
(no (cdr seqs))
(map1 f (car seqs))
((afn (seqs)
(if (some no seqs)
nil
(cons (apply f (map1 car seqs))
(self (map1 cdr seqs)))))
seqs)))
arc> (map [string "." _] "test")
".t.e.s.t"
Though you know, it's funny, my brain doesn't actually like it that map returns different things depending in the types of its arguments. In the same way that a long run-on sentence is annoying if I can't tell what's it's saying until the end, if I see a map I don't know if it's returning a list or a string or whatever until I've looked at its arguments and seen what they are.
So I might like map to always return a list, but still have it treat a string as if it were a list of characters. The example then becomes: