1. Uninitialised or "dummy" values

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

new topic     » topic index » view message » categorize

2. Re: Uninitialised or "dummy" values

I try to use default values that are impossible to ge normally. This way I
can tell if they have ever been set by normal means or not.
So in your example try setting start2 and weight  to an empty sequence.

  newgroup = {0, {}, 0, {})

then you can test later on " if sequence(newgroup[start2]) then -- has no
value yet" etc...

----- Original Message -----
From: <petelomax at blueyonder.co.uk>
To: "EUforum" <EUforum at topica.com>
Subject: Uninitialised or "dummy" values



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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu