Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You are number 6! Who is number one?


comp / comp.lang.scheme / Re: What's the error in this macro?

SubjectAuthor
* Re: What's the error in this macro?B. Pym
`- Re: What's the error in this macro?HenHanna

1
Subject: Re: What's the error in this macro?
From: B. Pym
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: A noiseless patient Spider
Date: Sat, 21 Sep 2024 13:29 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: What's the error in this macro?
Date: Sat, 21 Sep 2024 13:29:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <vcmhni$1k4sf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 21 Sep 2024 15:29:23 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="78f553967f83f2d994405934525231d2";
logging-data="1708943"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19HSlHFfEUROe1F2jawWm5c"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:hkff1fGp3I1sH2Y1wrRBnlgVM+E=
View all headers

KK wrote:

> > (defmacro sum (expression index initial condition)
> > ;; Sum $expression$ for $index$ = $initial$ and successive integers,
> > ;; as long as $condition$ holds.
> > (let ((temp (gensym)))
> > `(do ((,temp 0 (+ ,temp ,expression))
> > (,index ,initial (1+ ,index)))
> > ((not ,condition) ,temp))))
>
> The main error with this macro is that it does something you could do
> with the standard LOOP. I.e. instead of debugging this macro, you could
> be working on the program where this macro is intended to be used:
>

> (loop for x from 1 while (< x 6) summing x)
> -> 15

Gauche Scheme

(use srfi-42) ;; sum-ec

(sum-ec (:range x 1 6) x)
===>
15

Subject: Re: What's the error in this macro?
From: HenHanna
Newsgroups: comp.lang.lisp, comp.lang.scheme
Organization: novaBBS
Date: Tue, 24 Sep 2024 00:49 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!news.quux.org!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: HenHanna@dev.null (HenHanna)
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: What's the error in this macro?
Date: Tue, 24 Sep 2024 00:49:20 +0000
Organization: novaBBS
Message-ID: <30b4599472c7cfb8b8e5b278bba46e0e@www.novabbs.com>
References: <vcmhni$1k4sf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="3219383"; mail-complaints-to="usenet@i2pn2.org";
posting-account="25PjXUQKTQXKZnoxTqVufZcfCkmLjnu8AjjfHtuMysE";
User-Agent: Rocksolid Light
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Face: P#KeQ)CUdd!==@fw~Ms1=,Hb`IWtb6:Mw)x3B=H1BfNC\lz?Nb&)M9}$>?'X7l;CuB}utlJ=PHsRBSG6X>dYZ$[>P]$~+`>@V6$t}hTLoQ7XC~W\>:`B3ALU]SH;d(\MEc}znW8m}-ma&yPFkJ2@KSQrz=!Y;><;6a>z6N+mt`ClCt.PAE<o+B$qjwejZSZ,w]^;vrdl24z5(pm={l,F10qRDF
X-Rslight-Site: $2y$10$2QnbcAITM481/20ddpOx2.LdDx7s/mMWQfBsK.vXX3s1V/rVplK0G
X-Rslight-Posting-User: 5a1f1f09909a70d7ae18ae9af00e018f83ece577
View all headers

On Sat, 21 Sep 2024 13:29:23 +0000, B. Pym wrote:

> KK wrote:
>
>>> (defmacro sum (expression index initial condition)
>>> ;; Sum $expression$ for $index$ = $initial$ and successive integers,
>>> ;; as long as $condition$ holds.
>>> (let ((temp (gensym)))
>>> `(do ((,temp 0 (+ ,temp ,expression))
>>> (,index ,initial (1+ ,index)))
>>> ((not ,condition) ,temp))))

This looks good to me... Was this the corrected version?

>>
>> The main error with this macro is that it does something you could do
>> with the standard LOOP. I.e. instead of debugging this macro, you could
>> be working on the program where this macro is intended to be used:
>>
>
>> (loop for x from 1 while (< x 6) summing x) --> 15
>
> Gauche Scheme
>
> (use srfi-42) ;; sum-ec
> (sum-ec (:range x 1 6) x) ===> 15

In Scheme and Gauche Scheme, do ppl use Gensym?

(define-macro (Sum expression index initial condition)
`(do ((%Sum 0 (+ %Sum ,expression))
(,index ,initial (+ 1 ,index)))
((not ,condition) %Sum)))

(print (macroexpand '(Sum x x 1 (< x 6))))

(print (Sum x x 1 (< x 6)))

1

rocksolid light 0.9.8
clearnet tor