XPost: comp.lang.scheme
Zachary Beane wrote:
(defun mapcar-pos+ (list)
(let ((i -1))
(mapcar #'(lambda (elt) (+ elt (incf i)))
Truly abysmal ignorance or willful stupidity.
The #' is redundant.
iteration:
(defun pos+ (lst)
(setf acc NIL)
(setf i 0)
(dolist (obj lst)
; i know, instead of append, i could do a cons and reverse afterwards...
(progn (setf acc (append acc (list (+ obj i))))
(setf i (+ i 1))))
acc)
I'd prefer LOOP here:
(defun loop-pos+ (list)
(loop for i from 0
for elt in list
collect (+ elt i)))
Gauche Scheme:
(define (pos+ input)
(@ (i -1) map x : (+ x (++ i)) input))
(pos+ '(900 800 700 600 500))
===>
(900 801 702 603 504)
Given:
(define ++ inc!)
(define-syntax @-aux
(syntax-rules (:)
[(_ () goodlets func (vars ...) : expr lst ...)
(let* goodlets (func (lambda (vars ...) expr) lst ...))]
[(_ () goodlets func (vars ...) var more ...)
(@-aux () goodlets func (vars ... var) more ...)]
[(_ (var val more ...) (goodlets ...) stuff ...)
(@-aux (more ...) (goodlets ... (var val)) stuff ...)]))
(define-syntax @
(syntax-rules ()
[(_ (lets ...) func stuff ...)
(@-aux (lets ...) () func () stuff ...)]
[(_ func stuff ...)
(@ () func stuff ...)]))
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)