Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

What I tell you three times is true. -- Lewis Carroll


comp / comp.lang.lisp / Re: Finding Average without using Recusrion only using Prog

SubjectAuthor
* Re: Finding Average without using Recusrion only using ProgB. Pym
+* Re: Finding Average without using Recusrion only using ProgHenHanna
|+- Re: Finding Average without using Recusrion only using ProgHenHanna
|`- Re: Finding Average without using Recusrion only using ProgKaz Kylheku
+* Re: Finding Average without using Recusrion only using Progsteve g
|`- Re: Finding Average without using Recusrion only using ProgKaz Kylheku
`- Re: Finding Average without using Recusrion only using Progsteve g

1
Subject: Re: Finding Average without using Recusrion only using Prog
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 16 Jun 2024 04:39 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: Finding Average without using Recusrion only using Prog
Date: Sun, 16 Jun 2024 04:39:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <v4lq9k$3t78r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 16 Jun 2024 06:39:19 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c83d270445aa4b2c39858211581a12ef";
logging-data="4103451"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197/THEOzhQ7c9W/KlnHdZ9"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:ybvIEiW8HSgONggV/lKa0qFZw80=
View all headers

> (defun avg (args)
> (loop for x in args
> for l upfrom 1
> summing x into tot
> finally (return (/ tot l))))

Gauche Scheme

(use gauche.collection) ;; fold2

(define (add&count n sum cnt) (values (+ sum n) (+ cnt 1)))

(define (avg nums)
(apply /
(values->list
(fold2
add&count
0 0
nums))))

(avg '(20 30 40 50 60 70 80))
===>
50

Subject: Re: Finding Average without using Recusrion only using Prog
From: HenHanna
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 16 Jun 2024 18:28 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.lisp
Subject: Re: Finding Average without using Recusrion only using Prog
Date: Sun, 16 Jun 2024 11:28:23 -0700
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <v4nas9$5tka$1@dont-email.me>
References: <v4lq9k$3t78r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 16 Jun 2024 20:28:26 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="15d315eb6699321768c126a81b6bef90";
logging-data="194186"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+u5dCV9O9OSYBSb33O26ou9riPMbQPcNQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:V6cMatV4ptc7ves7tR9Ht36qVwc=
Content-Language: en-US
In-Reply-To: <v4lq9k$3t78r$1@dont-email.me>
View all headers

On 6/15/2024 9:39 PM, B. Pym wrote:
>> (defun avg (args)
>> (loop for x in args
>> for l upfrom 1
>> summing x into tot
>> finally (return (/ tot l))))
>
> Gauche Scheme
>
> (use gauche.collection) ;; fold2
>
> (define (add&count n sum cnt) (values (+ sum n) (+ cnt 1)))
>
> (define (avg nums)
> (apply /
> (values->list
> (fold2
> add&count
> 0 0
> nums))))
>
> (avg '(20 30 40 50 60 70 80)) ===> 50

Nice... Here's a more boring version:

(define (ave x)
(let ((L (length x)))
(if (> L 0)
(/ (fold + 0 x) L))))

(define (Pave x) (format #t "~% ~S ~S ~%" x (ave x)))

(Pave '(1 2 3))
(Pave '(1 2 3 4))
(Pave '(1))
(Pave '())

Subject: Re: Finding Average without using Recusrion only using Prog
From: HenHanna
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 16 Jun 2024 19:48 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.lisp
Subject: Re: Finding Average without using Recusrion only using Prog
Date: Sun, 16 Jun 2024 12:48:24 -0700
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <v4nfia$6tk3$1@dont-email.me>
References: <v4lq9k$3t78r$1@dont-email.me> <v4nas9$5tka$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 16 Jun 2024 21:48:27 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="15d315eb6699321768c126a81b6bef90";
logging-data="226947"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX190CgUY48ISeE575o6whXdGtSmVMNM4bJI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:psZ+Q+BvfpVEujn9DeaIqOaqzoY=
In-Reply-To: <v4nas9$5tka$1@dont-email.me>
Content-Language: en-US
View all headers

On 6/16/2024 11:28 AM, HenHanna wrote:
> On 6/15/2024 9:39 PM, B. Pym wrote:
>>>      (defun avg (args)
>>>        (loop for x in args
>>>            for l upfrom 1
>>>            summing x into tot
>>>            finally (return (/ tot l))))
>>
>> Gauche Scheme
>>
>> (use gauche.collection) ;; fold2
>>
>> (define (add&count n sum cnt) (values (+ sum n) (+ cnt 1)))
>>
>> (define (avg nums)
>>    (apply /
>>      (values->list
>>        (fold2
>>          add&count
>>          0 0
>>          nums))))
>>
>> (avg '(20 30 40 50 60 70 80))     ===>   50
>
>
> Nice...    Here's a more boring version:
>
>
> (define (ave x)
>   (let ((L (length x)))
>     (if (> L 0)
>       (/ (fold + 0 x) L))))
>
> (define (Pave x)   (format #t "~%    ~S  ~S  ~%" x (ave x)))
>
> (Pave  '(1 2 3))
> (Pave  '(1 2 3 4))
> (Pave  '(1))
> (Pave  '())
>

(define-macro (ave x)
`(/ (+ ,@ (map (lambda (n) `(+ ,@ (make-list n 1))) (cadr x)))
(+ ,@ (map (lambda (n) 1) (cadr x)))))

(print (ave '(1)))
(print (ave '(1 2 3)))

gosh> (macroexpand '(ave '(1 2 3)))
==> (/ (+ (+ 1) (+ 1 1) (+ 1 1 1)) (+ 1 1 1))

Subject: Re: Finding Average without using Recusrion only using Prog
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Mon, 17 Jun 2024 00:09 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: Finding Average without using Recusrion only using Prog
Date: Mon, 17 Jun 2024 00:09:20 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <20240616170235.690@kylheku.com>
References: <v4lq9k$3t78r$1@dont-email.me> <v4nas9$5tka$1@dont-email.me>
Injection-Date: Mon, 17 Jun 2024 02:09:20 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="05bafc0e4e4620b91ac884490c0b1f07";
logging-data="316253"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3su813bkkLShvjFtMrXKywj4qeUOKDR4="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:MAlGn+YwwzECU3aFuUvpWedUz3E=
View all headers

On 2024-06-16, HenHanna <HenHanna@devnull.tb> wrote:
> On 6/15/2024 9:39 PM, B. Pym wrote:
>>> (defun avg (args)
>>> (loop for x in args
>>> for l upfrom 1
>>> summing x into tot
>>> finally (return (/ tot l))))
>>
>> Gauche Scheme
>>
>> (use gauche.collection) ;; fold2
>>
>> (define (add&count n sum cnt) (values (+ sum n) (+ cnt 1)))
>>
>> (define (avg nums)
>> (apply /
>> (values->list
>> (fold2
>> add&count
>> 0 0
>> nums))))
>>
>> (avg '(20 30 40 50 60 70 80)) ===> 50
>
>
> Nice... Here's a more boring version:
>
>
> (define (ave x)
> (let ((L (length x)))
> (if (> L 0)
> (/ (fold + 0 x) L))))
>
> (define (Pave x) (format #t "~% ~S ~S ~%" x (ave x)))
>
> (Pave '(1 2 3))
> (Pave '(1 2 3 4))
> (Pave '(1))
> (Pave '())

This is the TXR Lisp interactive listener of TXR 294.
Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
Evidence of amphoric Lisp macros was recently found in ancient clay
jars.
1> [[callf / sum len] '(1 2 3 4)]
2.5

callf: return a function which:

- applies the second and subsequent functions given to callf (here sum
and len) to its arguments.
- applies the first argument of callf (here /) to the resulting
values.
- returns the resulting value

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Subject: Re: Finding Average without using Recusrion only using Prog
From: steve g
Newsgroups: comp.lang.lisp
Date: Fri, 9 Aug 2024 21:45 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-3.nntp.ord.giganews.com!local-4.nntp.ord.giganews.com!border-4.nntp.ord.giganews.com!nntp.giganews.com!local-3.nntp.ord.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 09 Aug 2024 21:45:47 +0000
From: sgonedes1977@gmail.com (steve g)
Newsgroups: comp.lang.lisp
Subject: Re: Finding Average without using Recusrion only using Prog
References: <v4lq9k$3t78r$1@dont-email.me>
Date: Fri, 09 Aug 2024 17:45:42 -0400
Message-ID: <87h6bttlo9.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:k4E5EJQtUB/SEThdaBgxpgZZWEk=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 35
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-ccQmPCShllBc/UVW8dYbwCyOPb0Y06CH7rwSPzVFXlmhqsKHzLpcb2cc59git7yqvTvzsbFBzHc3hHz!W7mX7GR7bWIM0q7x+kU13cgzU8bhCzYYYB05y71/N31e8F0=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

"B. Pym" <No_spamming@noWhere_7073.org> writes:

< > (defun avg (args)
< > (loop for x in args
< > for l upfrom 1
< > summing x into tot
< > finally (return (/ tot l))))

>
> Gauche Scheme
>
> (use gauche.collection) ;; fold2
>
> (define (add&count n sum cnt) (values (+ sum n) (+ cnt 1)))
>
> (define (avg nums)
> (apply /
> (values->list
> (fold2
> add&count
> 0 0
> nums))))
>
> (avg '(20 30 40 50 60 70 80))
> ===>
> 50

(loop for x in '(1 2 3 4 5)
summing x into max
counting x into cnt
finally (pprint (/ max cnt)))

Subject: Re: Finding Average without using Recusrion only using Prog
From: steve g
Newsgroups: comp.lang.lisp
Date: Fri, 9 Aug 2024 21:51 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!border-3.nntp.ord.giganews.com!nntp.giganews.com!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Fri, 09 Aug 2024 21:52:00 +0000
From: sgonedes1977@gmail.com (steve g)
Newsgroups: comp.lang.lisp
Subject: Re: Finding Average without using Recusrion only using Prog
References: <v4lq9k$3t78r$1@dont-email.me>
Date: Fri, 09 Aug 2024 17:51:54 -0400
Message-ID: <87bk21tldx.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:pOo319KG2ZNAJUplV2WZdOT6Jtc=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 39
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-bPRw3NebCtN297twHP6T/DvcWuuM3+x9HouKzM0uiEGz97R1p6G/sz+tB1YBV/fB0O3vnlm19Y1Jwbl!v6FhrJ6YHXm+7/Wvgq2BCk2HNW51UflQyH+0+Y6AyKQw2Ig=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
View all headers

"B. Pym" <No_spamming@noWhere_7073.org> writes:

< > (defun avg (args)
< > (loop for x in args
< > for l upfrom 1
< > summing x into tot
< > finally (return (/ tot l))))
>
> Gauche Scheme
>
> (use gauche.collection) ;; fold2
>
> (define (add&count n sum cnt) (values (+ sum n) (+ cnt 1)))
>
> (define (avg nums)
> (apply /
> (values->list
> (fold2
> add&count
> 0 0
> nums))))
>
> (avg '(20 30 40 50 60 70 80))
> ===>
> 50

(defun avg-with-prog (lst)
(prog ((avg 0) (cnt 0))
START
(setq avg (+ avg (pop lst)))
(incf cnt)
(if (endp lst)
(GO END)
(GO START))
END
(print (/ avg cnt))))

Subject: Re: Finding Average without using Recusrion only using Prog
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Fri, 9 Aug 2024 23:30 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.lisp
Subject: Re: Finding Average without using Recusrion only using Prog
Date: Fri, 9 Aug 2024 23:30:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <20240809162102.706@kylheku.com>
References: <v4lq9k$3t78r$1@dont-email.me> <87h6bttlo9.fsf@gmail.com>
Injection-Date: Sat, 10 Aug 2024 01:30:54 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="55856fbef320f8e8129676162efccf12";
logging-data="255267"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Xd9/ppv5bwCT5mKSRUgqcuN2LfEcdh10="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:RoA9OEn3sO7gz8syWbTj5H+mBo0=
View all headers

On 2024-08-09, steve g <sgonedes1977@gmail.com> wrote:
> "B. Pym" <No_spamming@noWhere_7073.org> writes:
>
>< > (defun avg (args)
>< > (loop for x in args
>< > for l upfrom 1
>< > summing x into tot
>< > finally (return (/ tot l))))
>
>
>
>
>>
>> Gauche Scheme
>>
>> (use gauche.collection) ;; fold2
>>
>> (define (add&count n sum cnt) (values (+ sum n) (+ cnt 1)))
>>
>> (define (avg nums)
>> (apply /
>> (values->list
>> (fold2
>> add&count
>> 0 0
>> nums))))
>>
>> (avg '(20 30 40 50 60 70 80))
>> ===>
>> 50
>
>
> (loop for x in '(1 2 3 4 5)
> summing x into max
> counting x into cnt
> finally (pprint (/ max cnt)))

2> [[callf / sum len] '(1 2 3 4 5)]
3.0

1

rocksolid light 0.9.8
clearnet tor