Groups | Search | Server Info | Login | Register


Groups > comp.lang.lisp > #60602

Re: DEFUN list argument

From "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups comp.lang.lisp, comp.lang.scheme
Subject Re: DEFUN list argument
Date 2025-08-06 00:00 +0000
Organization A noiseless patient Spider
Message-ID <106u5u6$32mic$1@dont-email.me> (permalink)
References <104q5p5$1bb98$1@dont-email.me>

Cross-posted to 2 groups.

Show all headers | View raw


B. Pym wrote:

> Steven E. Harris wrote:
> 
> > (defun dot-product (u v)
> >   (loop for elem-u across u
> >         for elem-v across v
> >         summing (* elem-u elem-v)))
> > 
> > 
> > > (dot-product (vector 1 2 3)
> >                (vector 4 5 6))
> > 32

Gauche Scheme

(define (dot-product U V)
  (gmk u U)
  (gmk v V)
  (do ((s 0 (+ s (* (u) (v)))))
    ((unull?) s)))

(dot-product (vector 1 2 3) (vector 4 5 6))
  ===>
32

Given:

;; Make a generator.
(define (gmk* vec)
  (let ((v vec)
        (i 0))
    (values
      (lambda()
        (if (= i (vector-length v)) #f (begin0 (~ v i) (inc! i))))
      (lambda() (= i (vector-length v))))))

(define-macro gmk
  (lambda (sym vec)
    `(define-values
       (,sym ,(symbol-append sym 'null?))
       (gmk* ,vec))))

-- 
[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

Back to comp.lang.lisp | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: DEFUN list argument "B. Pym" <Nobody447095@here-nor-there.org> - 2025-07-11 05:00 +0000
  Re: DEFUN list argument "B. Pym" <Nobody447095@here-nor-there.org> - 2025-08-06 00:00 +0000
    Re: DEFUN list argument "B. Pym" <Nobody447095@here-nor-there.org> - 2025-08-06 01:10 +0000
  Re: DEFUN list argument "B. Pym" <Nobody447095@here-nor-there.org> - 2025-08-28 06:15 +0000

csiph-web