Why doesn't this ENVELOPE SHAPER program work?
-
- Posts: 1309
- Joined: Wed Jan 27, 2016 12:50 am
- Contact:
Why doesn't this ENVELOPE SHAPER program work?
http://stardot.org.uk/mirrors/www.bbcdo ... _mm_02.htm
The long one there.
I honestly typed the listing as printed but get Array at line 1060 whenever I try to run it.
I have Beebsynth, which does this and more but I wanted to see if this was different.
The long one there.
I honestly typed the listing as printed but get Array at line 1060 whenever I try to run it.
I have Beebsynth, which does this and more but I wanted to see if this was different.
Re: Why doesn't this ENVELOPE SHAPER program work?
Check carefully that you have the DIM Min%(14) in line 150 and that in line 1060, you have typed FORX%=0TO14 and READ Min%(X%)
I suspect that in one of those elements you have made a typo....
I suspect that in one of those elements you have made a typo....
Re: Why doesn't this ENVELOPE SHAPER program work?
Is that really right? DIM Min%(14) in most languages would create 14 elements in the array...MartinB wrote:Check carefully that you have the DIM Min%(14) in line 150 and that in line 1060, you have typed FORX%=0TO14 and READ Min%(X%)
I suspect that in one of those elements you have made a typo....
X%=0 to 14 is accessing 15 elements....
Paul
Re: Why doesn't this ENVELOPE SHAPER program work?
No, it DIMs 0-14 which is 15 elements and this is what is being used.
I still think you have a typo somewhere in one of the items I mentioned....
I still think you have a typo somewhere in one of the items I mentioned....
Last edited by MartinB on Wed Jul 06, 2016 9:28 pm, edited 1 time in total.
Re: Why doesn't this ENVELOPE SHAPER program work?
Wow, I never realised that before. it's a bit counter intuitive too. Just reading the code, unless you know that DIM x%(14) will give you 15 elements, it could lead to some very interesting errors.MartinB wrote:No, it DIMs 0-14 which is 15 elements and this is what is being used.
EDIT 1:
I was sure that although the array is 0 indexed, DIM x%(14) would give you 14 elements so you'd access them as 0 through to 13.
http://www.bbcbasic.co.uk/bbcwin/tutori ... ter14.html seems to imply that the arrays are 1 indexed and not 0 indexed which complicates things...
As I read it the code should be
DIM Min%(14)
FOR X%=1 TO 14
EDIT2: Reading further down that page it then goes on to confirm that DIM Min%(14) would indeed give you 15 elements and as such the original code as written in the OP should work just fine.
Paul
Last edited by paulv on Wed Jul 06, 2016 9:35 pm, edited 2 times in total.
Re: Why doesn't this ENVELOPE SHAPER program work?
I suspect the concept of, and difference in, 'count from zero' versus 'count from one' is the cause of many hiccups in many aspects of modern life.....
Paul - no, I'm absolutely certain and can assure you it's correct. There are 15 data items too to underline the use here....
Paul - no, I'm absolutely certain and can assure you it's correct. There are 15 data items too to underline the use here....
Last edited by MartinB on Wed Jul 06, 2016 9:34 pm, edited 1 time in total.
Re: Why doesn't this ENVELOPE SHAPER program work?
Sorry, I mis-posted so have edited my response above to discuss 0 vs 1 indexed arrays etc.MartinB wrote:I suspect the concept of, and difference in, 'count from zero' versus 'count from one' is the cause of many hiccups in many aspects of modern life.....
Paul
Re: Why doesn't this ENVELOPE SHAPER program work?
Ha, we're stuck in a loop.....
I repeat....
I repeat....
I wrote:I'm absolutely certain and can assure you it's correct. There are 15 data items too to underline the use here....
Re: Why doesn't this ENVELOPE SHAPER program work?
...and now we're stuck in an editing loop
Re: Why doesn't this ENVELOPE SHAPER program work?
Marvellous! I have to say, some of the examples on that page I linked to are quite confusing and/or wasteful
DIM Month%(12) gives 13 elements for instance and the examples access elements 1 to 12, meaning there's a chunk of memory lost for the first integer in the array.
Another example that says...
then we have this...
Inconsistent examples lead to inconsistent programming practices which leads to errors. Grrr
Paul
DIM Month%(12) gives 13 elements for instance and the examples access elements 1 to 12, meaning there's a chunk of memory lost for the first integer in the array.
Another example that says...
Code: Select all
DIM AlienAlive(50)
REM ...
NewLevel=TRUE : REM Assume new level
FOR I%=1 TO 50
IF AlienAlive(I%) THEN NewLevel=FALSE
NEXT I%
Code: Select all
DIM MyArray%(3)
MyArray%() = 1,2,3,4
FOR I%=0 TO 3
PRINT MyArray%(I%)
NEXT I%
Paul
Re: Why doesn't this ENVELOPE SHAPER program work?
This is also the way it was done in Atom Basic.
Very inconsistent and confusing in my opinion.
Dave
Very inconsistent and confusing in my opinion.
Dave
Re: Why doesn't this ENVELOPE SHAPER program work?
I'm pretty sure that all BASIC implementations I've ever encountered have always implicitly included element (0) in array dimensioning. I never even flinched when I looked at that envelope shaper code, it just seemed perfectly 'normal' to me but perhaps there's a cultural difference between you guys who 'do' programming and software compared to the likes of myself who are just hobby/self-taught...?
I have done programming at work but it's always been various flavours of assembler or machine code where this sort of thing doesn't rear its head. (Well, the difference in counting from 0 or 1 does but not array dimensioning.)
I have done programming at work but it's always been various flavours of assembler or machine code where this sort of thing doesn't rear its head. (Well, the difference in counting from 0 or 1 does but not array dimensioning.)
Re: Why doesn't this ENVELOPE SHAPER program work?
It's more a question of the languages you've used I think. I used Turbo Pascal and Delphi heavily for many years which uses 1 indexed arrays and for the past 16 years, I've used a mix of languages from Delphi to CFML to C# where CFML is 1 indexed and C# is 0 indexed.MartinB wrote:I'm pretty sure that all BASIC implementations I've ever encountered have always implicitly included element (0) in array dimensioning. I never even flinched when I looked at that envelope shaper code, it just seemed perfectly 'normal' to me but perhaps there's a cultural difference between you guys who 'do' programming and software compared to the likes of myself who are just hobby/self-taught...?
I have done programming at work but it's always been various flavours of assembler or machine code where this sort of thing doesn't rear its head. (Well, the difference in counting from 0 or 1 does but not array dimensioning.)
My confusion though was brought about not by the indexing, once you know that an array for the language is 0 or 1 indexed, then you just run with that, it was more of a thing where you say DIM X%(15) which when reading it back looks like you're asking for 15 elements whereas it gives you 16...
Indexing and capacity are two different things so for code such as
Code: Select all
DIM X%(15)
Code: Select all
FOR Y%=0 to 14
....
NEXT
- OR -
FOR Y% = 1 to 15
...
NEXT
What I wouldn't expect to see however is
Code: Select all
FOR Y%=0 to 15
...
NEXT
In C# you'd see
Code: Select all
int[] x = new int[15];
for (int y=0; y<=14; y++)
{
do something with x[y];
}
Paul
-
- Posts: 1309
- Joined: Wed Jan 27, 2016 12:50 am
- Contact:
Re: Why doesn't this ENVELOPE SHAPER program work?
There were no typing errors. I double and triple checked. I checked the data stream too. Had the program not been badly saved, hence I lost it now, I would have taken a snap.
Is the program actually around in a text format I can just paste into Beeb-Em, or BBC BASIC For Windows? If it just makes envelopes, it doesn't matter how I sample it.
Is the program actually around in a text format I can just paste into Beeb-Em, or BBC BASIC For Windows? If it just makes envelopes, it doesn't matter how I sample it.
Re: Why doesn't this ENVELOPE SHAPER program work?
I'm late to this topic (only just noticed it) but I can explain why BBC BASIC's DIM works the way does.hoglet wrote:Very inconsistent and confusing in my opinion.
Microsoft, and similar, BASICs often have a special command OPTION BASE to determine whether array indices start at zero or at one. By making all arrays zero-based (internally), but with the DIM statement interpreting its parameter(s) as the maximum index (not the number of elements), BBC BASIC manages to achieve compatibility with both conventions without the complication of a command. The only significant price paid is the wastage of memory resulting from either the first or last element being unused.
It's why you'll see some BBC BASIC examples using one-based indexing and others using zero-based indexing, because it's compatible with both. Personally I think it's clever, not confusing.
Richard.