Remix.run Logo
▲ fwlr 3 hours ago

Oh, wow, this is a fantastic explanation for why “Zig makes you pass the allocator around as an argument to all your functions” is A Good Thing, Actually. Kudos to the author!

▲mac3n 11 minutes ago | parent | next [-]

This argues for dynamically scoped variables - bindings that are scoped and inherited by all called functions without having to be passed explicitly. After all, why should everyone in the call chain need to know if some deep call allocates temporary storage.

It's always bothered me that the only such feature in many languages is exception handlers (I'm also bothereed by functions that throw things).

I want "late" bindings, implemented as "shallow" bindings. "Late" as in binding is established at runtime in the call chain. "Shallow" as in you don't need to crawl the call chain to find it. Something like

    extern Allocater *theAllocater = &DefaultAllocater;
    ...
    // allocater scope
    { Allocater *prev = theAllocater;
      theAllocater = NewAllocater();
      ...
      theAllocater->free();
      theAllocater = prev;
    }
with a deep call using the current allocater

    // deep call
    { tmp = theAllocater->alloc(size);
      ...
    }
▲guipsp 4 minutes ago | parent [-]

https://tomasp.net/coeffects/

▲pdlclay 2 hours ago | parent | prev [-]

[flagged]