Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"I don't think so," said Ren'e Descartes. Just then, he vanished.


devel / comp.std.c / conditional macro definition also for recursive conditionally limited expansion

SubjectAuthor
* conditional macro definition also for recursive conditionally limited expansionMarco Munari
+* Re: conditional macro definition also for recursive conditionallyJames Kuyper
|`- Re: conditional macro definition also for recursive conditionally limited expansTim Rentsch
`* Re: conditional macro definition also for recursive conditionally limited expansTim Rentsch
 `* Re: conditional macro definition also for recursive conditionallyMarco Munari
  `- Re: conditional macro definition also for recursive conditionally limited expansTim Rentsch

1
conditional macro definition also for recursive conditionally limited expansion

<723aa6f8-0994-4b1d-b2d2-59abe33906ban@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=437&group=comp.std.c#437

  copy link   Newsgroups: comp.std.c
X-Received: by 2002:a05:6214:5288:: with SMTP id kj8mr9618178qvb.88.1641775928053;
Sun, 09 Jan 2022 16:52:08 -0800 (PST)
X-Received: by 2002:a9d:200f:: with SMTP id n15mr51936778ota.66.1641775927723;
Sun, 09 Jan 2022 16:52:07 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.std.c
Date: Sun, 9 Jan 2022 16:52:07 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=2001:b07:5d29:86a7:ac40:3213:f379:ede3;
posting-account=6GhcZAoAAACLv9qyEZqxYDKgr5yf9Ofg
NNTP-Posting-Host: 2001:b07:5d29:86a7:ac40:3213:f379:ede3
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <723aa6f8-0994-4b1d-b2d2-59abe33906ban@googlegroups.com>
Subject: conditional macro definition also for recursive conditionally limited expansion
From: allerta...@gmail.com (Marco Munari)
Injection-Date: Mon, 10 Jan 2022 00:52:08 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 43
 by: Marco Munari - Mon, 10 Jan 2022 00:52 UTC

I thought it could be nice to introduce condition inside macro definition, to produce less jumping code (so compiler can output bigger but more efficient code with concise definition)

a syntax could be defined by adding an optional #defif (due to the late time this could be introduced to C, that would be my preference reminding to who would learn by seeing it that the if is part of the macro definition) as
#define macro(#N,x) #defif (#N>0) macro(#N-1,…) #defelse …

usable with macro(5,x)
expansion parameter that i called #N need to be a constant provided to the expansion engine, the # prefix I indicated here is not a syntax necessity because it can be deduced by the fact that this parameters appears in the #defif condition which also must be fully valuable during preprocessing (just a bit more powerful preprocessing)

or if you prefer instead of #defif a shorter #IF or even #if but inside the line (expandable with \ ending lines) of a #define pragma, and the correspondent #defelse or #ELSE or #else
the result of the definition has to be a single entity as it is currently, but can be tweaked over the parameters of the macro definition during each expansion

e.g. for something like binary search in batch of direct elaboration without use of stack each batch of depth 5

#define f(N,bt,a) #defif(N>0) (a == bt->val) ? bt : (a < bt->val) ? f(N-1,bt->left,a) : f(N-1,bt->right,a) #defelse g(bt,a)

struct {int val; binarytree *left,*right} binarytree;
int g(binarytree bt, int a) {
return f(5,bt,a); /* recursive batch dept 5 is stored only here */
} would correspond to a very uncomfortable to write and maintain but efficient form

what do you think of the idea?

All the best,
MARco MunARi

x(t),y(t) = th(3t-34.5)*e^[-(3t-34.5)^2]/2-4.3+e^(-1.8/t^2)/(.8*atg(t-
3)+2)(t-1.8)-.3th(5t-42.5),(1.4e^[-(3t-34.5)^2]+1-sgn[|t-8.5|-.5]*1.5*
|sin(pi*t)|^[2e^(-(t-11.5)^2)+.5+e^(-(.6t-3.3)^2)])/(.5+t)+1 ; 0<t<14

Re: conditional macro definition also for recursive conditionally limited expansion

<srghc4$hsn$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=438&group=comp.std.c#438

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.std.c
Subject: Re: conditional macro definition also for recursive conditionally
limited expansion
Date: Mon, 10 Jan 2022 00:48:52 -0500
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <srghc4$hsn$1@dont-email.me>
References: <723aa6f8-0994-4b1d-b2d2-59abe33906ban@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 10 Jan 2022 05:48:52 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="70101d842d4c3689c09b40dcee90df43";
logging-data="18327"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hLbXII33GF3vJpoWneiGyTj4ZbRVeQ4A="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:n2LX5F/IjJdLquRL+LtN7MboCvc=
In-Reply-To: <723aa6f8-0994-4b1d-b2d2-59abe33906ban@googlegroups.com>
Content-Language: en-US
 by: James Kuyper - Mon, 10 Jan 2022 05:48 UTC

On 1/9/22 7:52 PM, Marco Munari wrote:
> I thought it could be nice to introduce condition inside macro definition, to produce less jumping code (so compiler can output bigger but more efficient code with concise definition)
>
> a syntax could be defined by adding an optional #defif (due to the late time this could be introduced to C, that would be my preference reminding to who would learn by seeing it that the if is part of the macro definition) as
> #define macro(#N,x) #defif (#N>0) macro(#N-1,…) #defelse …
>
> usable with macro(5,x)

The committee decided long ago to not allow recursive macros. The
relevant wording is:

2 If the name of the macro being replaced is found during this scan of
the replacement list (not including the rest of the source file’s
preprocessing tokens), it is not replaced. Furthermore, if any nested
replacements encounter the name of the macro being replaced, it is not
replaced. These nonreplaced macro name preprocessing tokens are no
longer available for further replacement even if they are later
(re)examined in contexts in which that macro name preprocessing token
would otherwise have been replaced." (6.10.3.4p2).

The Rationale explains: "A problem faced by many pre-C89 preprocessors
is how to use a macro name in its expansion without suffering “recursive
death.” The C89 Committee agreed simply to turn off the definition of a
macro for the duration of the expansion of that macro."

I doubt that the committee is likely to change it's mind on that matter.

Re: conditional macro definition also for recursive conditionally limited expansion

<86zgnus8dx.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=444&group=comp.std.c#444

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.std.c
Subject: Re: conditional macro definition also for recursive conditionally limited expansion
Date: Mon, 17 Jan 2022 07:13:14 -0800
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <86zgnus8dx.fsf@linuxsc.com>
References: <723aa6f8-0994-4b1d-b2d2-59abe33906ban@googlegroups.com> <srghc4$hsn$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="15598caebf32ebbe97649a2f881af1fe";
logging-data="6752"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+uxps03IlQVTH9e82dGp5tsI7IxfKvt9U="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:/NXX7OVAMrpNmSH4Vy5SfZjsO98=
sha1:HDW6P4+45XHTMv0KrHD6Fe2k0mk=
 by: Tim Rentsch - Mon, 17 Jan 2022 15:13 UTC

James Kuyper <jameskuyper@alumni.caltech.edu> writes:

> On 1/9/22 7:52 PM, Marco Munari wrote:
>
>> I thought it could be nice to introduce condition inside macro
>> definition, to produce less jumping code (so compiler can output
>> bigger but more efficient code with concise definition)
>>
>> a syntax could be defined by adding an optional #defif (due to the
>> late time this could be introduced to C, that would be my preference
>> reminding to who would learn by seeing it that the if is part of the
>> macro definition) as
>> #define macro(#N,x) #defif (#N>0) macro(#N-1,?) #defelse ?
>>
>> usable with macro(5,x)
>
> The committee decided long ago to not allow recursive macros. The
> relevant wording is:
>
> 2 If the name of the macro being replaced is found during this scan of
> the replacement list (not including the rest of the source file's
> preprocessing tokens), it is not replaced. Furthermore, if any nested
> replacements encounter the name of the macro being replaced, it is not
> replaced. These nonreplaced macro name preprocessing tokens are no
> longer available for further replacement even if they are later
> (re)examined in contexts in which that macro name preprocessing token
> would otherwise have been replaced." (6.10.3.4p2).
>
> The Rationale explains: "A problem faced by many pre-C89 preprocessors
> is how to use a macro name in its expansion without suffering 'recursive
> death.' The C89 Committee agreed simply to turn off the definition of a
> macro for the duration of the expansion of that macro."

IMO this conclusion is unwarranted. The earlier decision was
about how to deal with unexpected and infinite recursion. What
is being proposed does involve recursion, but recursion of a form
that is neither unexpected nor infinite. There is no reason to
expect comments about unexpected and infinite recursion to apply
to macro definitions that are explicitly and finitely recursive.
(Of course there does need to be some sort of limit because any
actual compiler cannot accommodate recursion that is arbitrarily
deep even if still finite, but that is a separate issue.)

Re: conditional macro definition also for recursive conditionally limited expansion

<86v8yis6mt.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=445&group=comp.std.c#445

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.std.c
Subject: Re: conditional macro definition also for recursive conditionally limited expansion
Date: Mon, 17 Jan 2022 07:51:06 -0800
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <86v8yis6mt.fsf@linuxsc.com>
References: <723aa6f8-0994-4b1d-b2d2-59abe33906ban@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="15598caebf32ebbe97649a2f881af1fe";
logging-data="22856"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/HktywKUu/h92qC8u1MU1AEHFR77ZdFzQ="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:yy50nbNO2MZTxvBy13uEdgtT08Q=
sha1:RGK44nQsHHCg7j2KJderz+GgVlc=
 by: Tim Rentsch - Mon, 17 Jan 2022 15:51 UTC

Marco Munari <allerta.it@gmail.com> writes:

> I thought it could be nice to introduce condition inside macro
> definition, to produce less jumping code (so compiler can output
> bigger but more efficient code with concise definition)
>
> a syntax could be defined by adding an optional #defif (due to the
> late time this could be introduced to C, that would be my preference
> reminding to who would learn by seeing it that the if is part of the
> macro definition) as
> #define macro(#N,x) #defif (#N>0) macro(#N-1,?) #defelse ?
>
> usable with macro(5,x)
> expansion parameter that i called #N need to be a constant provided
> to the expansion engine, the # prefix I indicated here is not a
> syntax necessity because it can be deduced by the fact that this
> parameters appears in the #defif condition which also must be fully
> valuable during preprocessing (just a bit more powerful
> preprocessing) [...]

It's an interesting idea. There are details that need to be
explored and understood first. Also I think it would be better
if expanded and generalized, perhaps along the lines of 'cond'
in lisp, or alternatively with ?# :# as preprocessing if/else.
Hmmm...

Re: conditional macro definition also for recursive conditionally limited expansion

<b5d2bcaf-ed4e-4843-b378-466d729981e0n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=449&group=comp.std.c#449

  copy link   Newsgroups: comp.std.c
X-Received: by 2002:a37:44cd:: with SMTP id r196mr17496880qka.90.1642508664946;
Tue, 18 Jan 2022 04:24:24 -0800 (PST)
X-Received: by 2002:a9d:24e4:: with SMTP id z91mr19993072ota.11.1642508664607;
Tue, 18 Jan 2022 04:24:24 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.mixmin.net!news2.arglkargh.de!2.us.feeder.erje.net!feeder.erje.net!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.std.c
Date: Tue, 18 Jan 2022 04:24:24 -0800 (PST)
In-Reply-To: <86v8yis6mt.fsf@linuxsc.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:b07:5d29:86a7:b39c:bf03:a940:80dc;
posting-account=6GhcZAoAAACLv9qyEZqxYDKgr5yf9Ofg
NNTP-Posting-Host: 2001:b07:5d29:86a7:b39c:bf03:a940:80dc
References: <723aa6f8-0994-4b1d-b2d2-59abe33906ban@googlegroups.com> <86v8yis6mt.fsf@linuxsc.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <b5d2bcaf-ed4e-4843-b378-466d729981e0n@googlegroups.com>
Subject: Re: conditional macro definition also for recursive conditionally
limited expansion
From: allerta...@gmail.com (Marco Munari)
Injection-Date: Tue, 18 Jan 2022 12:24:24 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 94
 by: Marco Munari - Tue, 18 Jan 2022 12:24 UTC

On Monday, January 17, 2022 at 4:51:12 PM UTC+1, Tim Rentsch wrote:
> Marco Munari <aller...@gmail.com> writes:
>
> > I thought it could be nice to introduce condition inside macro
> > definition, to produce less jumping code (so compiler can output
> > bigger but more efficient code with concise definition)
> >
> > a syntax could be defined by adding an optional #defif (due to the
> > late time this could be introduced to C, that would be my preference
> > reminding to who would learn by seeing it that the if is part of the
> > macro definition) as
> > #define macro(#N,x) #defif (#N>0) macro(#N-1,...) #defelse ...
> >
> > usable with macro(5,x)
> > expansion parameter that i called #N need to be a constant provided
> > to the expansion engine, the # prefix I indicated here is not a
> > syntax necessity because it can be deduced by the fact that this
> > parameters appears in the #defif condition which also must be fully
> > valuable during preprocessing (just a bit more powerful
> > preprocessing) [...]
[I wrote this first post encountering the message
"Your message has not finished sending yet."(google)
when trying to escape a buggy group post editing in iPad,
buggy because the keyboard was totally covering the insert point...
(I miss NNTP interfaced with gnus in emacs...)]
the binary search three example should have been consistent to the following:
#define f(#N,bt,a) \
#defif(#N>0) \
bt == NULL ? bt : (a == bt->val) \
? bt : (a < bt->val) \
? f(#N-1,bt->left,a) \
: f(#N-1,bt->right,a) \
#defelse \
g(bt,a)
/* f macro definition ended here, below the example continue with the use */
struct {int val; binarytree *left,*right} binarytree;
binarytree* g(binarytree* bt, int a) {
return f(5,bt,a); /* recursive batch dept 5 is stored only here */
}

[Also, the character shown in inclusive replies with "?" was "..."
but transformed by iPad in an unicode single character of three dots,
now I replaced to the original three dots also inside my inclusion
which obviously meant unspecified traditional #define content]

>
> It's an interesting idea. There are details that need to be
> explored and understood first. Also I think it would be better
> if expanded and generalized, perhaps along the lines of 'cond'
> in lisp, or alternatively with ?# :# as preprocessing if/else.
> Hmmm...

I'm favorable to any changes to the syntax I proposed,
including something a less powerful but simpler as
a number in the square brakes before the macro name
saying how many recursive expansion are permitted

#define f(bt,a) \
bt == NULL ? bt : (a == bt->val) \
? bt : (a < bt->val) \
? [5]f(bt->left,a) \
: [5]f(bt->right,a) \
#defelse \
g(bt,a)

You mentioned lisp, yes and why not lisp... I mean even lisp syntax!
limited to that (#define)context (which might exceptionally if you like,
save from the obligation of end lines with backslash when parenthesis
are not balanced at the end of #define line)
(cond CLAUSES...) (returning empty expansion where
returns nil when all clausole are unsatisfied).
Anyway (cond) could be along the line of #defswitch ... #defcase
wich is to #defif / #defelseif / #defelse (or without the prefix def)

Interesting also your concise syntax ?# :# (or maybe you meant ... #? ... #: ...
as the dash come before in preprocessing recognition) as a form of ... ? ... : ...
but with dash used as preprocessing-only condition, with the same
functionality that I invoked with #defif / #defelse), it can be both
CPP forms, as the C has the dual.

As it was not introduced for so long to C/CPP, I welcome to open the discussion
and make a wise choice, which include cases of possible and opportune use studio.
Actually I have in mind recursion batch as a case where this is effectively
needed/beneficial, but the case of generic constant condition... I'm not too
sure is a generic benefit for maintenance and code understanding (furthermore
there is also already the possibility of #if before the #define for different
and constant #define),
maybe the [number]macro on invocation syntax within the #define macro
is sufficient as well as missing to permit something quite essential.
Let's think about cases of essential use

I'm also considering that there are a series of tools as Visual Studio, gdb
interpreation of macro expansion information saved in debug compiled file
format, which have some expectations on preprocessing, and the change
should be so welcome

Re: conditional macro definition also for recursive conditionally limited expansion

<86o847rd30.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=450&group=comp.std.c#450

  copy link   Newsgroups: comp.std.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.std.c
Subject: Re: conditional macro definition also for recursive conditionally limited expansion
Date: Wed, 19 Jan 2022 06:53:55 -0800
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <86o847rd30.fsf@linuxsc.com>
References: <723aa6f8-0994-4b1d-b2d2-59abe33906ban@googlegroups.com> <86v8yis6mt.fsf@linuxsc.com> <b5d2bcaf-ed4e-4843-b378-466d729981e0n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="6fad361a12fcf775509d251c0ab1bed8";
logging-data="7996"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19uxFAxTewOwNqGkTBOf1bMGzMoJTAaYcQ="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:G7BolJTvO1SkQ6DnXUNXXgGjxL4=
sha1:YXZ3cBp7uPoKzjNm3KXB8V/f/y8=
 by: Tim Rentsch - Wed, 19 Jan 2022 14:53 UTC

Marco Munari <allerta.it@gmail.com> writes:

> On Monday, January 17, 2022 at 4:51:12 PM UTC+1, Tim Rentsch wrote:
>
>> Marco Munari <aller...@gmail.com> writes:
>>
>>> [conditional / recursive macro expansion]
>>
>> It's an interesting idea. There are details that need to be
>> explored and understood first. Also I think it would be better
>> if expanded and generalized, perhaps along the lines of 'cond'
>> in lisp, or alternatively with ?# :# as preprocessing if/else.
>> Hmmm...
>
> I'm favorable to any changes to the syntax I proposed,

I don't mean to suggest any specific changes, just throwing
out ideas.

> You mentioned lisp, yes and why not lisp... I mean even lisp
> syntax! [...]

I think it would be hard to integrate lisp syntax into C's
lexical environment. Technically it might be feasible, but
there are also human factors to consider, and those look
rather daunting.

> Interesting also your concise syntax ?# :# (or maybe you
> meant ... #? ... #: ... [...]

It was just a casual suggestion. Obviously there are lots
of details to consider before settling on specifics.

Good luck!

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor