www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Does exists some way to define a implementation for a symbol?

reply Hipreme <msnmancini hotmail.com> writes:
Right now, I've been implementing classes separately, and I need 
a dummy symbol. The best world is not even having a symbol but 
having only its implementation, for example, I would like being 
able to do that:

```d
void pragma(mangle, "test")(int a){
     writeln(a);
}
```

Is it possible somehow to do that?
Nov 14 2023
parent Paul Backus <snarwin gmail.com> writes:
On Tuesday, 14 November 2023 at 13:43:03 UTC, Hipreme wrote:
 Right now, I've been implementing classes separately, and I 
 need a dummy symbol. The best world is not even having a symbol 
 but having only its implementation, for example, I would like 
 being able to do that:

 ```d
 void pragma(mangle, "test")(int a){
     writeln(a);
 }
 ```

 Is it possible somehow to do that?
You can use the following string mixin to generate an identifier: ```d // Mixin to generate a new identifier that won't repeat within a scope enum gensym(string prefix = "_gensym") = `"` ~ prefix ~ `" ~ __traits(identifier, {})["__lambda".length .. $]`; ``` But since D currently doesn't support mixing in only a function's name, you'd have to put the entire function definition inside a mixin: ```d mixin(q{void pragma(mangle, "test") }, mixin(gensym), q{(int a) { writeln(a); }}); ```
Nov 14 2023