B. Pym wrote:
B. Pym wrote:
(defun mapcar-pos+ (list)
(let ((i -1))
(mapcar #'(lambda (elt) (+ elt (incf i)))
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)))
(defun pos+ (xs)
(do ((i 0 (+ 1 i))
r)
((not xs) (reverse r))
(push (+ i (pop xs)) r)))
(define (pos+ xs)
(Do ((i 0 (+ 1 i))
r)
((null? xs) @ r)
(push! r (+ i (pop! xs)))))
Given:
(define-syntax Do-aux
(syntax-rules (<> @ values)
[(_ ((a b <>) d ...) (seen ...) z ...)
(Do-aux (d ...) (seen ... (a b b)) z ...) ]
[(_ ((a b c ...) d ...) (seen ...) z ...)
(Do-aux (d ...) (seen ... (a b c ...)) z ...) ]
[(_ ((a) d ...) (seen ...) z ...)
(Do-aux (d ...) (seen ... (a '())) z ...) ]
[(_ (a d ...) (seen ...) z ...)
(Do-aux (d ...) (seen ... (a '())) z ...) ]
[(_ () seen (a b ... @ (values x ...)) z ...)
(Do-aux () seen (a b ... (values (reverse~ x) ...)) z ...) ]
[(_ () seen (a b ... @ xs) z ...)
(Do-aux () seen (a b ... (reverse xs)) z ...) ]
[(_ () seen till body ...)
(do seen till body ...) ]))
(define-syntax Do
(syntax-rules ()
[(_ specs till body ...)
(Do-aux specs () till body ...) ]))
--
[T]he problem is that lispniks are as cultish as any other devout group and basically fall down frothing at the mouth if they see [heterodoxy].
--- Kenny Tilton
The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)