![]() |
|
|
|
|
|
| 16 31st October 14:01 |
OK, thanks everyone for dropping an explanation. Can't say I have fully
appreciated the technical reasons, but I think I now know the human reasons involved. In summary, We have 3 solutions here: 1) declare a string variable instead of a constant: StringVar: ARRAY <length> OF CHAR; ... String := "<string-value>"; c := StringVar[i]; 2) place the string in a read-only variable in another module: MODULE Mod1; VAR StringVar-: ARRAY <length> OF CHAR; END Mod1. BEGIN StringBVar := "<string-value>"; MODULE Mod2; ... c := Mod1.StringVar[i]; END Mod2. Drawback: Hassle of creating/maintaining a semantically spurius "constants" module. 3) place the string in a constant, and then use a helper routine to extract items: CONST StringConst = "<string-value>"; ... PROCEDURE Get(a: ARRAY OF CHAR; i: INTEGER): CHAR; BEGIN RETURN a[i]; END Get; ... c := Get(StringConst,i); Drawback: Has a funny feeling, and the extra routine is a hassle. Thanks again. -- K -- Message posted using http://www.talkaboutprogramming.com/...p.lang.oberon/ More information at http://www.talkaboutprogramming.com/faq.html |
|
|
17
31st October 14:01
External User
Posts: 1
|
I propose a fourth solution that might go something like:
PROCEDURE SoundexMap(ch: CHAR): INTEGER; BEGIN CASE CAP(ch) OF "A", "E", "I", "O", "U": RETURN 0 | "B", "F", "P", "V": RETURN 1 | "C", "G", "J", "K", "Q", "S", "X", "Z": RETURN 2 | "D", "T": RETURN 3 | "H", "L": RETURN 4 | "M", "N": RETURN 5 | "R": RETURN 6 | "W", "Y": RETURN 7 END END SoundexMap; It should be as efficient but much less obscure than the other three solutions. Readers / maintainers of the code then have a better chance of verifying that this algorithm is doing what it is intended to do. e.g. it might lead to the question: Shouldn't "W", "Y" and "H" return 0 instead of 7, 7 and 4? -- Chris Burrows CFB Software http://www.cfbsoftware.com/gpcp |
|
|
|
| 18 31st October 14:01 |
Chris, thanks for your suggestion, but the discussion wasn't "what is the
most efficient way to implement the soundex algorithm." It was "why can't we access constant strings the way we can variable ones." I picked that example off the top of my head, so that's irrelevant. Nevertheless, it's nice to learn that using the "CASE" construct produces such efficient code in Oberon. I'll start converting all my table lookups to CASEs. Anyway, this should settle my question. I got my answers, and thanks to everyone. -- K -- Message posted using http://www.talkaboutprogramming.com/...p.lang.oberon/ More information at http://www.talkaboutprogramming.com/faq.html |
|
|
20
31st October 14:02
External User
Posts: 1
|
Fair enough - but not totally irrelevant. I am interested to learn of
alternative tasks that could *best* be implemented by accessing constant strings as if they were an array rather than using any of the alternative approaches that are possible in Oberon. If such tasks exist then that would support the introduction of such a feature into future descendants of Oberon / Component Pascal / Zonnon etc. -- Chris Burrows CFB Software http://www.cfbsoftware.com/gpcp |
|