Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #321: Scheduled global CPU outage


comp / comp.lang.lisp / Re: when are macros useful?

SubjectAuthor
* Re: when are macros useful?B. Pym
`- Re: when are macros useful?Lawrence D'Oliveiro

1
Subject: Re: when are macros useful?
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Thu, 4 Jul 2024 22:04 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: when are macros useful?
Date: Thu, 4 Jul 2024 22:04:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <v6769t$2ubtb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Fri, 05 Jul 2024 00:04:48 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="91b8164c6e15c4fd5f6e8024bb3937cc";
logging-data="3092395"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19FN1txrLVPiHFl+bitCNDv"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:1BoPO+LH8buyXj9VcgQ78Z9a2BA=
View all headers

> Here is a very simple macro example which shows some of the features:
> destructuring, substituting into a template to produce a form,
> using (gensym) to invent a needed symbol. The purpose of this macro
> is to introduce a very simple language feature; a loop construct
> which executes a sequence of forms N times, where N is a parameter.
> We implement our new kind of loop, which we will call ``ntimes''
> in terms of the Common LISP ``dotimes' loop:
>
> (defmacro ntimes (count . forms) (let ((counter (gensym)))
> `(dotimes
> (,counter ,count) ,@forms)))

Scheme

(define-syntax ntimes
(syntax-rules ()
[(_ count forms ...)
(do ((n 0 (+ n 1)))
((= n count))
forms ...)]))

Subject: Re: when are macros useful?
From: Lawrence D'Oliv
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 6 Jul 2024 07:42 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.lang.lisp
Subject: Re: when are macros useful?
Date: Sat, 6 Jul 2024 07:42:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <v6asht$3nlvk$1@dont-email.me>
References: <v6769t$2ubtb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 06 Jul 2024 09:42:53 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1bf6ca10d24952d079c382420ceea130";
logging-data="3921908"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eX8Upvkpqd1jucH7aV32q"
User-Agent: Pan/0.158 (Avdiivka; )
Cancel-Lock: sha1:hNfimXN2kqXOlV70bfZHg2h7NYc=
View all headers

On Thu, 4 Jul 2024 22:04:48 -0000 (UTC), B. Pym wrote:

> (define-syntax ntimes
> (syntax-rules ()
> [(_ count forms ...)
> (do ((n 0 (+ n 1)))
> ((= n count))
> forms ...)]))

I think it’s a sign of desperation when you hope that using different
kinds of bracketing symbols will somehow make your code clearer. The
screen/page is two-dimensional; why not make use of both dimensions in
laying out your code?

(define-syntax ntimes
(syntax-rules ()
((_ count forms ...)
(do ((n 0 (+ n 1)))
((= n count))
forms ...
) ; do
)
) ; syntax-rules
) ; define

1

rocksolid light 0.9.8
clearnet tor