Attribute transference from callbacks?

Manu turkeyman at gmail.com
Sun Dec 8 05:54:40 UTC 2024


I've been trying out an API strategy to use sink functions a lot more to
hoist the item allocation/management logic to the user and out from the
work routines. This idea has received a lot of attention, and I heard a lot
of people saying this was a planned direction to move in phobos and friends.

void parseThings(string s, void delegate(Thing) sink)
{
  //...
  sink(Thing());
  //...
}

We have a serious problem though; a function that receives a sink function
must transfer the attributes from the sink function to itself, and we have
no language to do that...
What are the leading strategies that have been discussed to date? Is there
a general 'plan'?
Restriction attributes like pure/nothrow/@nogc/safe, etc need some
expression to operate in a similar way to; where the attribute-ness of
function matches the attributes of its delegate argument(/s).

Here's the stupidest idea ever: expand inout to take an argument...

void parseThings(string s, void delegate(Thing)  inout(nothrow)
inout(@nogc) sink) inout(nothrow) inout(@nogc)
{
  //...
  sink(Thing());
  //...
}

Surely people have had better ideas? But you get the point, and this is
basically essential to make the 'sink' pattern work at all in D.

No, no templates; it's not right to generate multiple copies of identical
functions just because something it CALLS would transfer an attribute. The
function itself is identical no matter the state of any attribute
transference, and so this isn't a template problem; it's a pattern matching
problem.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20241208/1d27f3df/attachment.htm>


More information about the Digitalmars-d mailing list