switch case alternative

seany seany at uni-bonn.de
Sat Nov 2 11:19:41 PDT 2013


Hello,

I have the following problem.

In the input consol I can input a string, and the system will 
take action based on such.

So if I input add_2_with_2, it will give me a 4, if I input 
sqrt_4 it will give me 2, etc. Generally, you will do this with a 
switch / case command, but the problem is, then I need a 
condition for each case. So if i want to ADITTIONALLY input 
cube_2, then I have to write a case for this.

However, I would like to do the same without having to explicitly 
write a case each time I insert a new command. So forexample, if 
in input "FUNCTION_1", then the program should look in a specific 
place, in a specific forlder / file, find out if the function is 
defined, and execute it. If not defined in the file / folder, 
then it should throw AN EXCEPTION. If I additionally want to 
input "FUNCTION_2", then i will define the function in the same 
file or folder (whatever is possible with D) and then let the 
original program to automatically search and execute.

Can this be done in D?

(sorry for stupid question and bad English)


More information about the Digitalmars-d mailing list