Weird string stuff

Anything QL Software or Programming Related.
User avatar
Andrew
QL Wafer Drive
Posts: 1050
Joined: Tue Jul 17, 2018 9:10 pm

Re: Weird string stuff

Post by Andrew »

Derek_Stewart wrote: Mon Jan 13, 2025 12:31 pm Hi,

I have been reading, Artificial Intelligenence on the QL, after I made single page and OCR.

Texamples in the book and the programme at the end of the of the book "Computer_SalesMan_bas", use arrays to store the data and use array element 0 as a data element, string or integer.

Consulting many QL manuals and books, they say that the length of the string is the last element in the array, as detailed in the QL User Guide and many books.

Only the Online Supebasic Manual, The Definitive Superbasic Guide by Jan Jones, gives array element 0 as the lenth of the string.

This has I expected, but thd more interesting question is why are so many manuals and books including the QL User Guide saying incorrectly that the length of the array is held at the end of the array.

That said how many programmes do not work in SMSQ/E or Minerva based on incorrect asumpions on the array storage details.

Needless to say, the programme: "Computer_Saleman_bas" needs correcti g.

I think I should stick to assembler programming, it is alot easier.
At first glance I do not spot any errors in array handling in the program.
However, line 16040 is fishy and needs correcting.
I only OCRed the first 5 pages of the program, and have 9 pages more to do ...


User avatar
tofro
Font of All Knowledge
Posts: 3148
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Weird string stuff

Post by tofro »

Derek_Stewart wrote: Mon Jan 13, 2025 12:31 pm Hi,

I have been reading, Artificial Intelligenence on the QL, after I made single page and OCR.

Texamples in the book and the programme at the end of the of the book "Computer_SalesMan_bas", use arrays to store the data and use array element 0 as a data element, string or integer.

Consulting many QL manuals and books, they say that the length of the string is the last element in the array, as detailed in the QL User Guide and many books.

Only the Online Supebasic Manual, The Definitive Superbasic Guide by Jan Jones, gives array element 0 as the lenth of the string.

This has I expected, but thd more interesting question is why are so many manuals and books including the QL User Guide saying incorrectly that the length of the array is held at the end of the array.

That said how many programmes do not work in SMSQ/E or Minerva based on incorrect asumpions on the array storage details.

Needless to say, the programme: "Computer_Saleman_bas" needs correcti g.

I think I should stick to assembler programming, it is alot easier.
Well, you can basically store nearly anything in a DIMensioned array, as long as you don't exceed the array bounds.

String length in both QDOSSMSQ and S*BASIC (including Minerva) is always stored in the element 0. I have yet to see any claim that string length is stored at the end (well, maybe at the "near" one, but never at the "far one" :) ) of an array. Where did you find those? Note that if you have a multi-dimensional string array (like DIM a$(10,100)), only access to the second index with 0 touches a string length. A$(0) returns the complete string at index 0 of the array. A$(0,0) returns the length of that first string as a character.

I had a quick glance through your mentioned salesman program and cannot find access to a string length at the end. Can you point me to that?


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Derek_Stewart
Font of All Knowledge
Posts: 4796
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Weird string stuff

Post by Derek_Stewart »

Andrew wrote: Mon Jan 13, 2025 4:05 pm At first glance I do not spot any errors in array handling in the program.
However, line 16040 is fishy and needs correcting.
I only OCRed the first 5 pages of the program, and have 9 pages more to do ...
no need to OCR thd book I have done the whole book, into a Libreoffice file and PDF.

Just git to proof read the final document.

I extracted the Computer_Saleman basic code, wwhich I am tryi g to grt working.

The problem with the array length storage seems to be in conficit with the QL User Guide: https://dilwyn.theqlforum.com/docs/ebook ... ds.htm#dim
DIM
Arrays

Defines an array to SuperBASIC. String, integer and floating point arrays can be defined. String arrays handle fixed length strings and the final index is taken to be the string length.


Regards, Derek
User avatar
tofro
Font of All Knowledge
Posts: 3148
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Weird string stuff

Post by tofro »

Derek_Stewart wrote: Mon Jan 13, 2025 6:45 pm
The problem with the array length storage seems to be in conficit with the QL User Guide: https://dilwyn.theqlforum.com/docs/ebook ... ds.htm#dim
DIM
Arrays

Defines an array to SuperBASIC. String, integer and floating point arrays can be defined. String arrays handle fixed length strings and the final index is taken to be the string length.
That's just what I was saying above. Seems to be a misunderstanding of the manual. This is trying to say that

For

Code: Select all

DIM A$(10,100)
the final index (100) is the [maximum usable] string length of an array of 10 strings. Has nothing to do with the string length encoded in the string itself. That's still in A$(x, 0).


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Derek_Stewart
Font of All Knowledge
Posts: 4796
Joined: Mon Dec 20, 2010 11:40 am
Location: Sunny Runcorn, Cheshire, UK

Re: Weird string stuff

Post by Derek_Stewart »

Hi,

Thank you for the clarification.

Looks like I misunderstood the description.


Regards, Derek
User avatar
pjw
QL Wafer Drive
Posts: 1629
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Weird string stuff

Post by pjw »

Derek_Stewart wrote: Mon Jan 13, 2025 8:03 pm Hi,

Thank you for the clarification.

Looks like I misunderstood the description.
It wasnt very clear, I agree. We probably lost a couple of dozen brothers there..


Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
Post Reply