This needs to be fixed - ref

Nick Treleaven nick at geany.org
Wed Aug 28 15:19:33 UTC 2024


On Wednesday, 28 August 2024 at 11:47:12 UTC, Manu wrote:
> For instance, the evidence here: 
> __traits(getParamterStorafeClasses,
> function, paramterByIntegerIndex)
> How would you expect to detect if something is ref, or scope, 
> or whatever?

__traits(isRef, x)

I expect a trait for isScope could be added if needed.

> Of course, what you expect is a STRING LITERAL, which you can 
> compare to a
> string of the name of the storage class.
> There's no stronger evidence that storage classes are 
> themselves such a
> broken idea that exist way outside of the language than passing

Just because you can't e.g. alias a storage class doesn't mean it 
is 'outside' the language. It's part of a declaration.

> around
> string literals to tell you a fact about some declaration.
> C++ puts these things in the type, and while that creates some 
> awkward
> cases, it's infinitely better than what we have in D in terms of
> expressiveness and flexibility in terms of meta programming.

I've heard that C++ references are a complete swamp of special 
cases (regardless of lvalue vs rvalue reference).

> Ref as part of
> a type means it can participate in type-like expressions, 
> inferences, etc.

I think its better to explicitly write `ref` if you want a ref, 
rather than infer it.

> What's kinda funny, is that your link to the cool ref-local 
> feature (finally!) above will be shortly followed with "how do 
> I detect if a local is a reference?" ... there's no 
> __traits(getLocalVariableStorageClass, ...)

__traits(isRef, x)

Example with `auto ref` in the changelog.

> So I still don't really know; what IS a ref?

It's a pointer that is automatically dereferenced on use, and 
never does pointer arithmetic.

> It's astonishing that s.tupleof is a sequence of ref's as you 
> say...

BTW that was just how I understand `.tupleof`. I see it as (a 
superset of) a sequence of implicit ref declarations.

> does anything else in the language have a semantic like that?
> How could I synthesise something like that from anything else 
> if I wanted to?

If you mean synthesize `tupleof`, I already showed how (without 
introspection support), the first example here:
https://forum.dlang.org/post/fctetiyhbiyhadlmcyzr@forum.dlang.org

That example literally works with dmd recent git.


More information about the Digitalmars-d mailing list