pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@lists.postgresql.org
Subject: Re: POC: converting Lists into arrays
Date: Wed, 31 Jul 2019 19:40:09 -0400
Message-ID: <30240.1564616409@sss.pgh.pa.us> (raw)
In-Reply-To: <20190731225756.nozn3j6lgwhm6qvq@alap3.anarazel.de>
References: <11587.1550975080@sss.pgh.pa.us>
	<20190731225756.nozn3j6lgwhm6qvq@alap3.anarazel.de>

Andres Freund <andres@anarazel.de> writes:
> Unfortunately foreach(ListCell *lc, ...) doesn't work with the current
> definition. Which I think isn't great, because the large scopes for loop
> iteration variables imo makes the code harder to reason about.

Yeah, I tried to make that possible when I redid those macros, but
couldn't find a way :-(.  Even granting that we're willing to have
a different macro for this use-case, it doesn't seem easy, because
you can only put one <declaration> into the first element of a
for (;;).

That makes the other idea (of a foreach-ish macro declaring the
listcell value variable) problematic, too :-(.

One idea is that we could do something like

    foreach_variant(identifier, list_value)
    {
       type *v = (type *) lfirst_variant(identifier);
       ...
    }

where the "identifier" isn't actually a variable name but just something
we use to construct the ForEachState variable's name.  (The only reason
we need it is to avoid confusion in cases with nested foreach's.)  The
lfirst_variant macro would fetch the correct value just by looking
at the ForEachState, so there's no separate ListCell* variable at all.

			regards, tom lane





view thread (130+ messages)  latest in thread

Message-ID: <30240.1564616409@sss.pgh.pa.us>
Permalink:  ../30240.1564616409@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/30240.1564616409@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, andres@anarazel.de, pgsql-hackers@lists.postgresql.org
  Subject: Re: POC: converting Lists into arrays
  In-Reply-To: <30240.1564616409@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox