Path: utzoo!attcan!uunet!mcsun!sunic!enea!sommar From: sommar@enea.se (Erland Sommarskog) Newsgroups: comp.lang.eiffel Subject: Re: Interesting problems to try in Eiffel Message-ID: <631@enea.se> Date: 13 Jan 90 15:39:14 GMT References: <1721@novavax.UUCP> Organization: Enea Data AB, Sweden Lines: 34 Bob Weiner (weiner@novavax.UUCP) writes: >* Cast the value of a STRING into an entity name and then assign to it. >... >Suppose one needs a >hundred separate input parameters to initialize a program. Command line >options are thus impractical. Instead a file with two fields per line >is created with one parameter per line. The first is the parameter name >which is the same as a program attribute name and the second is the >parameter value. The problem is how to assign the value to the actual >program entity with the right name? Without the aforementioned >capability, one is in for a very long if-then-else structure ... Let's see where is my "A definition of a real programmer"? Ah, here it is! "A real programmer can write Fortran in any language". Or Lisp, or Eiffel or whatever his favourite is. However what is a feasible solution in one language may be completely condemnable in another. Eiffel is statically typed. What do you do when the name in the string is not of the right type? Or is completely undefined? And how do you handle it to give the user an nice error message? And the most funny cases of them all: suppose the user enters the name of internal variable which is not supposed to be altered? A back-on-the-envelope solution to the problem would to be to have class PARAMETER which inherits some sorting mechanism, probably a hash table. Probably you have subclasses STRING_PARAMETER, BOOLEAN_PARAMETER etc. You read the parameter string uses that as key to get the instance, calls its Assign_value passing the value string from the file. Assign_value parses the string and assigns it to the Value feature or gives an error message. Next is of course the problem retrieving values from this parameter table which I'm note fluently enough in Eiffel to solve cleanly. -- Erland Sommarskog - ENEA Data, Stockholm - sommar@enea.se Unix is a virus.