String Metaprogramming

Clayton via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 18 06:48:18 PDT 2015


Am new to D programming, am considering it since it supports 
compile-time function execution . My challenge is how can I 
re-implement the function below so that it is fully executed in 
compile-time. The function should result to tabel1 being computed 
at compile-time. There seems to be a lot of mutation happening 
here yet I have heard no mutation should take place in 
meta-programming as it subscribes to functional programming 
paradigm.



void computeAtCompileTime( ref string pattern ,ref int[char] 
tabel1){
	int size = to!int(pattern.length) ;
	
	foreach( c; ALPHABET){
		tabel1[c] = size;
	}
	
	for( int i=0;i<size -1 ; ++i){   //Initialise array
		tabel1[pattern[i]] = size -i-1;

         pragma(msg, format("reached pattern  
table1[pattern[i]]=(%s) here",
         table1[pattern[i]].stringof  ~"     v="~ (size 
-i-1).stringof));
	}

	
	
	
}



More information about the Digitalmars-d-learn mailing list