aliasing main

monkyyy crazymonkyyy at gmail.com
Thu Jun 20 00:55:37 UTC 2024


recently I've been looking into creating dsl's via templates
... its not going well

however what does just werk^tm is aliasing main

```d
struct dsl{
	string exe(string s){
		return s;
}}
template repl(alias T){
	pragma(mangle, "main")
	int repl(){
		import std;
		T machine;
		foreach(in_;stdin.byLineCopy){
			if(in_=="quit")return 0;
			if(in_=="vomit"){
				machine.writeln;
			} else {
				machine.exe(in_).writeln;
		}}
		assert(0);
}}
alias main=repl!dsl;
```

I think some stuff is broken like exceptions, but maybe some 
common patterns should be extracted out to make even smaller 
programs


More information about the Digitalmars-d mailing list