Crow programming language

Steven Schveighoffer schveiguy at gmail.com
Fri Feb 16 18:36:48 UTC 2024


On Thursday, 15 February 2024 at 23:46:10 UTC, andy wrote:
> On Thursday, 15 February 2024 at 15:24:37 UTC, IchorDev wrote:
>
>> You can make a scope with `nothrow`, `@nogc`, etc.:
>
> I've been setting `@safe @nogc pure nothrow:` at the top of 
> (almost) every module, but then I still have to do it at the 
> top of each struct in the module (if it has functions) and 
> after each delegate type.

`@safe` permeates into structs, the others do not.

>
>> If you make global variables `immutable`, you can access them 
>> in `pure` functions.
>
> Is it as simple as that? I'd have to cast away the `immutable` 
> when adding a new interned string though. Is that still the 
> correct way to do it?

No, this is not correct.

What you are doing is something that is logically immutable, but 
not actually immutable.

What you need to do is to section this off into its own module, 
and then use language tricks to lie to the compiler. For 
instance, cast a function pointer that is not pure to a pure 
function. Then you need to carefully review the module for 
correctness from an API standpoint.

The language does something similar with memory allocation, which 
uses a global data structure to allocate memory, but effectively 
is giving you back memory that is unique while it is valid.

-Steve


More information about the Digitalmars-d-announce mailing list