Default value of new variables

Seems to be 0 but I thought it used to be the empty value

Has it changed in recent years?

My Mayflower project (which I started a long time ago) has a few statements like


which were intended to initialise a variable if it wasn't already set (not really needed but I have them in the project)

So, recently I ended up deleting all my global variables and re-creating them to put them in a particular order and then my project went wrong

Eventually, I worked out that when a variable is created - its given value of 0

Did something change over last 3 years or did I just get it wrong when I wrote the code? :slight_smile:

Or have a slipped into another multiverse (again) :slight_smile:

Snap! inherits from JavaScript a terrible sloppiness about zero-ish values. So really the value was always 0, but it (I guess) used to be interpreted as the empty string instead of as a number.

I take this as a feature; it teaches programmers not to make assumptions about the initial values of variables, but always to initialize them explicitly. (Yes, I get it, that's what you were trying to do.) I tend to do IF (NOT (IS ___ A LIST ?))...

Well, I went back and ran

in 5.4.1 and it behaves exactly the same then as now

I must have just got it wrong (and never ended up testing it properly!) :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.