digitalmars.D.learn - Make a function available under different names.
Let's say I have these two functions: They have duplicate functionality. ``` string getExecutableNameFromMainFunction(string[] arguments){ write("Executable_Name: " ~ arguments[0] ~ "\n"); write("Debug mode is enabled.\n"); return arguments[0]; } string printExecutableNameFromMainFunction(string[] arguments){ write("Executable_Name: " ~ arguments[0] ~ "\n"); write("Debug mode is enabled.\n"); return arguments[0]; } ``` How can I easily and in simple way make `printExecutableNameFromMainFunction` as function where `getExecutableNameFromMainFunction` would share functionality or simply point to `printExecutableNameFromMainFunction`.
Jul 29 2023
On Saturday, 29 July 2023 at 14:26:17 UTC, 00004 wrote:Let's say I have these two functions: They have duplicate functionality. ``` string getExecutableNameFromMainFunction(string[] arguments){ write("Executable_Name: " ~ arguments[0] ~ "\n"); write("Debug mode is enabled.\n"); return arguments[0]; } string printExecutableNameFromMainFunction(string[] arguments){ write("Executable_Name: " ~ arguments[0] ~ "\n"); write("Debug mode is enabled.\n"); return arguments[0]; } ``` How can I easily and in simple way make `printExecutableNameFromMainFunction` as function where `getExecutableNameFromMainFunction` would share functionality or simply point to `printExecutableNameFromMainFunction`.Seems to be working ``` alias printExecutableNameFromMainFunction = getExecutableNameFromMainFunction; string getExecutableNameFromMainFunction(string[] arguments){ write("Executable_Name: " ~ arguments[0] ~ "\n"); write("Debug mode is enabled.\n"); return arguments[0]; } ```
Jul 29 2023