* Associative array "pop" ?
@ 2021-01-21 2:32 Craig Ringer
2021-02-16 21:40 ` Frank Ch. Eigler
0 siblings, 1 reply; 2+ messages in thread
From: Craig Ringer @ 2021-01-21 2:32 UTC (permalink / raw)
To: systemtap
Hi all
I find myself using the patterns
x_foo = foo[x]
if (x_foo != 0)
delete foo[x]
# do something with x_foo
}
and
if ([x] in foo) {
x_foo = foo[x]
delete foo[x]
# do something with x_foo
}
frequently.
I wonder if it's feasible to have a "pop" that combines these to eliminate
repeated searches of the array. Assuming that those aren't already
optimised away - I didn't see any indication they are, but don't know the
underlying code well enough.
Something like
if (pop(foo_x, foo[x])) {
}
where "pop" returns 1 if the element was present, 0 if it was not present,
and deletes it if it was present.
If you think it's a good idea I'll pop this on my TODO for pending
enhancements for me to try to hack up.
--
Craig Ringer http://www.2ndQuadrant.com/
2ndQuadrant - PostgreSQL Solutions for the Enterprise
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Associative array "pop" ?
2021-01-21 2:32 Associative array "pop" ? Craig Ringer
@ 2021-02-16 21:40 ` Frank Ch. Eigler
0 siblings, 0 replies; 2+ messages in thread
From: Frank Ch. Eigler @ 2021-02-16 21:40 UTC (permalink / raw)
To: Craig Ringer; +Cc: systemtap
Craig Ringer <craig@2ndquadrant.com> writes:
> x_foo = foo[x]
> if (x_foo != 0)
> delete foo[x]
> # do something with x_foo
> }
This is probably:
https://sourceware.org/bugzilla/show_bug.cgi?id=10837
... except the "value = delete foo[i]" syntax is kind of meh, and
doesn't work with slice ops like "delete foo[*]". A functional syntax
like @pop() would look okay. We try to not introduce new keywords,
except in the @-space, and even there only with version-conditional
parsing.
- FChE
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-02-16 21:41 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21 2:32 Associative array "pop" ? Craig Ringer
2021-02-16 21:40 ` Frank Ch. Eigler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).