Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #342: HTTPD Error 4004 : very old Intel cpu - insufficient processing power


comp / comp.lang.scheme / Re: applying macros

SubjectAuthor
* Re: applying macrosB. Pym
`- Re: applying macrosB. Pym

1
Subject: Re: applying macros
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Thu, 19 Sep 2024 07:32 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: applying macros
Date: Thu, 19 Sep 2024 07:32:45 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <vcgk2r$g35t$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 19 Sep 2024 09:32:45 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="771b02138d80f549ec3d77beeedbe017";
logging-data="527549"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eJveb9vhutBzHRQsT9Bfj"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:sQKWC2jcqEAf6j8LTcpLB0ocSfw=
View all headers

Rainer Joswig wrote:

> (defun average-function (list)
> (assert list (list)
> "List should not be empty.")
> (loop for i from 0
> for item in list
> sum item into result
> finally (return (/ result i))))

It's shorter in Gauche Scheme.

(define (average-function lst)
(let1 n 0
(/ (fold (lambda (x sum) (inc! n) (+ x sum)) 0 lst)
n)))

Subject: Re: applying macros
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Thu, 19 Sep 2024 08:45 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Nobody447095@here-nor-there.org (B. Pym)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: applying macros
Date: Thu, 19 Sep 2024 08:45:16 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <vcgoan$gn8h$1@dont-email.me>
References: <vcgk2r$g35t$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 19 Sep 2024 10:45:17 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="771b02138d80f549ec3d77beeedbe017";
logging-data="548113"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19udxEruiaujyOwdCvJIDZ8"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:tzWBMeIlWOr4NBKQEv59ciTJZsU=
View all headers

B. Pym wrote:

> Rainer Joswig wrote:
>
> > (defun average-function (list)
> > (assert list (list)
> > "List should not be empty.")
> > (loop for i from 0
> > for item in list
> > sum item into result
> > finally (return (/ result i))))
>
> It's shorter in Gauche Scheme.
>
> (define (average-function lst)
> (let1 n 0
> (/ (fold (lambda (x sum) (inc! n) (+ x sum)) 0 lst)
> n)))

Another way.

(define (average-function lst)
(let1 n 0
(/ (@ fold x sum : (inc! n) (+ x sum) : 0 lst)
n)))

Given:

(define-syntax @-aux
(syntax-rules (:)
;; No parameters given; use "cut".
[(_ func () ((e0 e ...)) : stuff ...)
(func (cut e0 e ...) stuff ...)]
[(_ func vars (e0 e ...) : stuff ...)
(func (lambda vars e0 e ...) stuff ...)]
[(_ func vars (e0 e ...) expr more ...)
(@-aux func vars (e0 e ... expr) more ...)]
[(_ func vars () : expr more ...)
(@-aux func vars (expr) more ...)]
[(_ func (vars ...) () var more ...)
(@-aux func (vars ... var) () more ...)]))

(define-syntax @
(syntax-rules ()
[(_ func stuff ...)
(@-aux func () () stuff ...)]))

1

rocksolid light 0.9.8
clearnet tor