Re: take a sequence of numbers 2 at a time, print numbers and

Liste des GroupesRevenir à cl scheme 
Sujet : Re: take a sequence of numbers 2 at a time, print numbers and
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 06. Aug 2025, 05:00:17
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <106uk0e$35ddu$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
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

Date Sujet#  Auteur
6 Aug 25 o Re: take a sequence of numbers 2 at a time, print numbers and1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal