Uninitialised or "dummy" values
- Posted by petelomax at blueyonder.co.uk Mar 02, 2002
- 436 views
Just a quick(!?!) query. I'll describe a specific case but it's not causing me a problem, bar the code being misleading/unreadable. I'm processing a list of groups, each element of which is {start1,start2,length,weight} After processing each element I save it in "lastgset" to compare with the next entry in the list. Now, before I start I want to initialise a dummy "last element processed". Start1 is known, length has the obvious dummy value of 0 (zero). But start2 and weight don't have any obvious default (in the first pass of the loop they shouldn't actually be referenced). Any thoughts/experience on a "good" default value to use? --------------------------------------------------------------------------------------- I'm toying with the idea of {} for things which should be atoms and 0 for things which should be sequences, as that would cause a type check for unexpected reference, but: a) it makes the code harder to understand b) in some cases 0 and {} are validly used at the same point in the sub-structure. (in my case "processed" and "nothing at all found" respectively) Something perhaps which makes the code more readable? The more I look the more examples of this I find. IIRC, Prolog uses a single underscore. Maybe it would be neat to have a similar predefined constant in Eu such that fred=1 ... fred=_ ... x=fred causes an uninitialised variable error It would also mean "allow garbage collection without creating an unnecessary atom or empty sequence". Pete