3 ms·
Any readability problem in vector-map! there is an issue with some given Scheme and the available primitives that it has out of the box for writing it. TXR Lis
by kazinator 10y ago
Any readability problem in vector-map! there is an issue with some given Scheme and the available primitives that it has out of the box for writing it.
TXR Lisp:
(defun inplace-vec-map (f v)
(each ((i (range (length v))))
(set [v i] [f [v i]])))
I should provide mappers that iterate over the places in a sequence.
;; Fantasy:
(each-place ((elem seq)) ;; seq is vector, string or list or whatever
(set elem [f elem])) ;; elem is mutable place alias
Good idea. Like non-const iterators in C++ or whatever.
If `[v i]` is repeated a lot in the body of the each, we can currently approximate this now with placelet, an invention of mine:
(each ((i (range (length v))))
(placelet ((elem [v i])) ;; once-only evaluation of [v i]!
(set elem [f elem]))) ;; elem can be used many times
That translation for the each-place fanatasy construct would work, but would be inefficient for lists; it has to use some type-specific iterator object under the hood to designate the place with constant-time access.
Lisp is forever malleable and can overcome any ergonomic problem that anyone wants; you just have to articulate the requirements clearly: "I don't like writing X; why can't it be expressed as Y".
- qwertyuiop924 10y agoWell, part of my point was that new primitives (vector-map!) are being introduced that makes this more convenient (and already exist in most Schemes). To your point, there are numerous loop macro sets that make the do in my vector-map! simpler, but I didn't want to introduce any external dependancies (or implementation dependancies), and I thought it was clear enough.