Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 28 |
Nodes: | 6 (1 / 5) |
Uptime: | 45:48:21 |
Calls: | 422 |
Calls today: | 1 |
Files: | 1,024 |
Messages: | 90,336 |
Or you could write
(defun pos+ (lst)
(let ((i -1))
(mapcar #'(lambda (x) (+ x (incf i)))
lst)))
Btw, in Arc that would be
(def pos+ (lst)
(let i -1
(map [+ _ (++ i)] lst)))
paul graham wrote:
Or you could write
(defun pos+ (lst)
(let ((i -1))
(mapcar #'(lambda (x) (+ x (incf i)))
lst)))
Btw, in Arc that would be
(def pos+ (lst)
(let i -1
(map [+ _ (++ i)] lst)))
Gauche Scheme
(define (pos+ lst)
(let1 i -1
(map (~> (+ (inc! i))) lst)))
Given:
(define-syntax ->
(syntax-rules ()
[(_ x) x]
[(_ x (y more ...) z ...)
(-> (y x more ...) z ...)]
[(_ x y z ...)
(-> (y x) z ...)]))
(define-syntax ~>
(syntax-rules ()
[(_ (func0 a ...) func ...)
(lambda xs (-> (apply func0 (append xs (list a ...))) func ...))]
[(_ func0 func ...)
(lambda xs (-> (apply func0 xs) func ...))]))
[mapcar + '(10 20 30) 0](10 21 32)