www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Better Debugging With Metaprogramming

reply "Kyle Siefring" <kyle.siefring verizon.net> writes:
I was thinking that there were a few useful applications for 
using metaprogramming could be used as

int rng()
{

}
Sep 11 2014
parent reply "Kyle Siefring" <kyle.siefring verizon.net> writes:
On Friday, 12 September 2014 at 01:17:10 UTC, Kyle Siefring wrote:
 I was thinking that there were a few useful applications for 
 using metaprogramming could be used as

 int rng()
 {

 }
I think pressing the tab key just sent this message before I was sure I even wanted to type it. Let's see if the tab key is the verdict.... Okay the tab key selected the send element and then I must have pressed enter. Let's try that...
Sep 11 2014
parent "Kyle Siefring" <kyle.siefring verizon.net> writes:
On Friday, 12 September 2014 at 01:19:40 UTC, Kyle Siefring wrote:
 On Friday, 12 September 2014 at 01:17:10 UTC, Kyle Siefring 
 wrote:
 I was thinking that there were a few useful applications for 
 using metaprogramming could be used as

 int rng()
 {

 }
I think pressing the tab key just sent this message before I was sure I even wanted to type it. Let's see if the tab key is the verdict.... Okay the tab key selected the send element and then I must have pressed enter. Let's try that...
Not really metaprogramming I suppose. I think I know how I made myself think that and explaining it is more than I can write. I'm sure somebody is going to be curious to what I was going to write so I suppose I have to write it anyway. Will what I write be coherent? Probably not. I want this. With sensible syntax. int rng (int n) dbg { // define what can be put into the value of the keyvalue store of the debug database int notSoRandomNumber; } body { dbg // Checks if the database is empty then if there is an entry for the callee of this method { // return a number determined outside of compile time and provided by the user return dbg.notSoRandomNumber; } else { // do things normally return (a random number 0 through n); } } Callees automatically pass on who they are. You can select callees using some method (ide, gdb like breakpoint list, ect.) and then add entries. You would be doing a search for where line and file equal what you select. usage of the above function string[] choices = ["dead", "stone dead", "definitely deceased" "bleeding demised", "not pining", "passed on", "no more", "ceased to be", "expired and gone to meet his maker", "a stiff", "Bereft of life", "rests in peace", "ect.", "EX-PARROT"]; writeln(choices[rng(choices.length)]); You could write this function and not have to change the code that calls it! Another fun idea. dbg variables can be searched in the database. for(dbg int i = 0; i < 5; i++) { string[] choices = ["dead", "stone dead", "definitely deceased" "bleeding demised", "not pining", "passed on", "no more", "ceased to be", "expired and gone to meet his maker", "a stiff", "Bereft of life", "rests in peace", "ect.", "EX-PARROT"]; writeln(choices[rng(choices.length)]); } You could decide to only interfer when i = 3 for example. This idea may be stupid but that cursed tab and enter thing forced me to write this regardless of if it's any good.
Sep 11 2014