[Coco] Using the Basic09 type statement. CORRECTION

Wayne Campbell asa.rand at gmail.com
Thu Apr 8 11:26:06 EDT 2021


I went through the code and made corrections. The resulting code does work,
but it is not the best code. I would have liked to have just put the text
here in this message, but I'm having to use my phone right now and it gives
me more trouble than it's worth when it comes to trying to put text into an
email.

On Sun, Apr 4, 2021, 12:49 PM Wayne Campbell <asa.rand at gmail.com> wrote:

>  I'm seeing a few problems. Most notably, you're defining apage as type
> PAGE, but you have no type statement for type PAGE. As for the rest, I
> would have to actually enter the code in and run tests on it to figure out
> exactly what you're doing wrong.
>
> On Sun, Apr 4, 2021, 7:01 AM <coco at jechar.ca> wrote:
>
>> Ignore original code. Equal signe were missing from three lines.
>> Program still has issues though.
>>
>> Revised Code
>>
>> PROCEDURE ttype
>>   0000
>>   0001      TYPE LINE=sline:STRING[17]
>>   0011      TYPE HEADER=head:STRING[21]
>>   0021 ERR     TYPE SCREEN=head:HEADER;sline:LINE[6]
>>   0049      (* Trying to say that type SCREEN is a HEDER followed by an
>> array of 6 LINEs s each consisting of up to 17 characters. *)
>>   00C2
>>   00C3      DIM aline:LINE
>>   00CC      DIM ahead:HEADER
>>   00D5      DIM apage:PAGE
>>   00DE
>>   00DF      apage.ahead="This is the Header field of the page"
>>   010E      apage.aline(1)="This is line ONE of the page."
>>   0138      apage.aline(2)="This is line TWO of the page."
>>   0162      apage.aline(3)="This is line THREE of the page."
>>   018E
>>   018F      PRINT apage
>>   0194
>>   0195      END
>> 00DD ERROR #024
>> 00E6 ERROR #066
>> 010D ERROR #071
>> 0114 ERROR #065
>> 0117 ERROR #066
>> 0137 ERROR #071
>> 013E ERROR #065
>> 0141 ERROR #066
>> 0161 ERROR #071
>> 0168 ERROR #065
>> 016B ERROR #066
>> 018D ERROR #071
>>
>>
>>
>> On 2021-04-04 10:14, coco at jechar.ca wrote:
>> > I am trying to create a type that consists of a field that is a 21
>> > character string
>> > followed by a field that is an array of 17 character strings. I read
>> > some documentation and am not sure it is even possible this was my
>> > attempt and it's errors,
>> >
>> > PROCEDURE ttype
>> >  0000
>> >  0001      TYPE LINE=sline:STRING[17]
>> >  0011      TYPE HEADER=head:STRING[21]
>> >  0021 ERR     TYPE SCREEN=head:HEADER;sline:LINE[6]
>> >  0049      (* Trying to say that type SCREEN is a HEDER followed by an
>> > array of 6 LINEs s each consisting of up to 17 characters. *)
>> >  00C2
>> >  00C3      DIM aline:LINE
>> >  00CC      DIM ahead:HEADER
>> >  00D5      DIM apage:PAGE
>> >  00DE
>> >  00DF      apage.ahead="This is the Header field of the page"
>> >  010E ERR     apage.aline(1) "This is line ONE of the page."
>> >  013F ERR     apage.aline(2) "This is line TWO of the page."
>> >  0170 ERR     apage.aline(3) "This is line THREE of the page."
>> >  01A3
>> >  01A4      PRINT apage
>> >  01A9
>> >  01AA      END
>> > 00DD ERROR #024
>> > 00E6 ERROR #066
>> > 010D ERROR #071
>> >
>> > Can this be fixed or am I trying to do the impossible.
>> >
>> > Charlie
>>
>> --
>> Coco mailing list
>> Coco at maltedmedia.com
>> https://pairlist5.pair.net/mailman/listinfo/coco
>>
>
-------------- next part --------------
PROCEDURE ttype

TYPE LINE=sline:STRING[17]
TYPE HEADER=head:STRING[21]

(* This shows the first error in your code. You want sline to be an array of 6 lines, but you define it like a string of 6 characters, except you try to use LINE instead of STRING.
REM TYPE SCREEN=head:HEADER; sline:LINE[6]

(* You also misspelled HEADER in your comment.
(* Trying to say that type SCREEN is a HEDER followed by an array of 6 LINEs s each consisting of up to 17 characters *)

(* So I corrected it to be an array of 6 LINEs. This statement still contains errors because you are defining head and sline twice, once as a field and again as the variable assigned to the type.
REM TYPE SCREEN-head:HEADER; sline(6):LINE

(* I again corrected the statement by renaming head to ahead and sline to aline. This removed the errors from this statement.
REM TYPE SCREEN=ahead:HEADER; aline(6):LINE

(* You attempt to define variables for your new types here, but you misuse them in the assignment statements following them.
REM DIM aline:LINE
REM DIM ahead:HEADER
REM DIM apage:PAGE \(* The type PAGE doesn't exist. Did you mean SCREEN here?

(* added this so the for loop uses an integer instead of a real
DIM x:INTEGER

(* You are using ahead and aline as though they are fields of apage. They are not. You have incorrectly defined the types, or simply misused the variables here.
REM apage.ahead="This is the Header field of the page"
REM apage.aline(1)="This is line ONE of the page."
REM apage.aline(2)="This is line TWO of the page."
REM apage.aline(3)="This is line THREE of the page."

(* If you want aline and ahead to be fields of apage, you must define them as fields of the type you assign to apage. Something like this:

TYPE PAGE=ahead:HEADER; aline(6):LINE
DIM apage:PAGE
apage.ahead.head="This is the Header field of the page"
apage.aline(1).sline="This is line ONE of the page."
apage.aline(2).sline="This is line TWO of the page."
apage.aline(3).sline="This is line THREE of the page."

(* That leaves us with this error. You can't just print a variable of a type when it has more than one field.
REM PRINT apage

PRINT apage.ahead.head
FOR x=1 to 3
PRINT apage.aline(x).sline
NEXT x

END 


More information about the Coco mailing list