From Newsgroup: comp.lang.lisp
Rainer Joswig wrote:
This solution is basically the same as yours but a bit
differently written:
(loop with size = (length *nums*)
for i from 0 below size by 2
for j from 1 below size by 2
for a = (aref *nums* i) and b = (aref *nums* j)
do (format t "~A * ~A = ~A~%" a b (* a b)))
Gauche Scheme
(define nums (vector 21 47
23 43
24 29
22 28
22 53
31 36
22 56
31 72))
(with-gen (n nums)
(until (n-null?)
(let ((a (n)) (b (n)))
(format #t "~a * ~a = ~a\n" a b (* a b)))))
21 * 47 = 987
23 * 43 = 989
24 * 29 = 696
22 * 28 = 616
22 * 53 = 1166
31 * 36 = 1116
22 * 56 = 1232
31 * 72 = 2232
Given:
;; Make a vector generator.
(define (gmk vec)
(let ((v vec)
(i 0))
(values
(lambda()
(if (= i (vector-length v)) #f (begin0 (~ v i) (inc! i))))
;; Tells if generator is exhausted.
(lambda() (= i (vector-length v))))))
(define-macro with-gen
(lambda (args . body)
(define duos
(let go ()
(if (null? args) '() (cons (list (pop! args)(pop! args)) (go)))))
(define (proc s v)
`((,s ,(symbol-append s '-null?)) (gmk ,v)))
`(let-values
(,@(map (lambda (xs) (apply proc xs)) duos))
,@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 --- Synchronet 3.21a-Linux NewsLink 1.2