digitalmars.D - find function satisfying input-output instance constraints to help
- timotheecour (37/37) Feb 11 2013 I'd like to suggest a new feat...
I'd like to suggest a new feature to help discoverability : a function in phobos that finds candidate function names given input-output constraints (not just type constraints) that the function should satisfy (and optionally, other constraints such as type traits). That'll be valuable not only within phobos but also for user packages (potentially in online packages). Example usage: ---- import std.typecons : tuple; import std.tools : findFunctionByInputOutput; //could be put there auto candidates = findFunctionByInputOutput(tuple("rocks", "ks"),true); writeln(candidates); //the user can then lookup each function in the docs // prints :["endsWith"]; //there might be other matching functions assert("endsWith" in candidateFunctions.byName); //there might be other ---- Implementation: This would go over each function in each module of std, filter out the ones incompatible with input-output arguments (with __traits(compiles,...)), and then return the ones that satisfy the input-output constraint(s). For multiple constraints syntax could be: auto candidates = findFunctionByInputOutputs(tuple(tuple("rocks", "ks"),true,tuple("rocks", "cks"),true)); Tuples seem necessary to allow mixed types in arguments. Potentially only pure functions would be searched to avoid side effects or writing to disk etc. In addition, each attempt would be protected by a try catch block, and maybe a timeout. Some provision could be given to extend search in user packages/modules, and for other type constraints. The returned candidates could be a lazy range of struct containing module/file/line/function signature/ddoc info of functions that match constraints. This doesn't sound too hard to implement. Is there interest or suggested improvements?
Feb 11 2013