Author Topic: Dimension an array of zstrings.  (Read 3512 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
Re: Dimension an array of zstrings.
« Reply #15 on: May 02, 2018, 12:52:54 AM »

I've expanded it, and added some annotations

Code: [Select]
'2018-05-02 T 07:30:23
'fixed length string arrays

macro dim_arraytype(ty,va,y,x  ityp,ivar)
  'ty type of element
  'va variable name
  'y  row count of elements
  'x  column count of elements
  'INTERNAL:
  'ityp
  'ivar
  type ityp ty s[x]
  ityp ivar[y]
  def va ivar[%1].s  'eg: va[29].s
end macro

dim_arraytype char,z,100,256
'
z[1]="Hello"
z[2]=" "
z[3]="World"
print z[1] + z[2] + z[3]

Brian Alvarez

  • Guest
Re: Dimension an array of zstrings.
« Reply #16 on: May 02, 2018, 01:05:13 AM »
Thanks Charles, you are very nice. Please see the editions i made to my previous post.

Charles Pegge

  • Guest
Re: Dimension an array of zstrings.
« Reply #17 on: May 02, 2018, 01:47:41 AM »
RESET and REDIM for these fixed-length strings is quite easy to accommodate. SORT SCAN, and other complex operations would be better handled with a class.

REDIM and RESET
Code: [Select]
def reset
  %1_buffer=nuls len(%1_buffer)
  @%1=strptr %1_buffer
end def

macro redim_arraytype(ty,va,y,x)
  'ty type of element
  'va variable name
  'y  row count of elements
  'x  column count of elements
  type va##_type ty s[x]
  redim va##_type va##_var[y]
  def va va##_var[%1].s  'eg: va[29].s
end macro

redim_arraytype char,z,100,256
#recordof z_var_buffer
'
z[1]="Hello"
z[2]=" "
z[3]="World"
redim char_type z_var[200]
'reset z_var
print z[1] + z[2] + z[3]

Brian Alvarez

  • Guest
Re: Dimension an array of zstrings.
« Reply #18 on: May 02, 2018, 08:12:07 AM »
Thanks Charles.

Will this code work for every other array?
Or will i have to generate different code for resetting/redimensioning other arrays?
Can i use the generated array for sorting?
Can i pass the array as a parameter, as regular ZSTRING array?

Edit:
 I hope all my pickiness is not too obnoxious. Please be patient. One of the problems i found with JAVA is that code reusability is almost null. I am trying to make easy for the programmers the repurposing of code, as sometimes it is necessary to use a portion of code for a similar purpose. I'm trying to avoid forcing programmers to rewrite the whole thing just because the array is of type STRING instead of ZSTRING.
« Last Edit: May 02, 2018, 08:36:43 AM by Brian Alvarez »

Mike Lobanovsky

  • Guest
Re: Dimension an array of zstrings.
« Reply #19 on: May 02, 2018, 10:16:57 AM »
Brian,

You don't have to apologize for every question you put and every issue you report. They are natural in one's learning curve I used to mention.

We know who you are and why you are here. Feel yourself at home; you're serving the cause that's important for both O2 an PB communities. Welcome to the ranks! :)

JRS

  • Guest
Re: Dimension an array of zstrings.
« Reply #20 on: May 02, 2018, 11:37:06 AM »
The beauty of the rose is created by its stem of thorns.

Brian Alvarez

  • Guest
Re: Dimension an array of zstrings.
« Reply #21 on: May 02, 2018, 12:34:47 PM »
 Thanks Guys. Oxygen is not difficult to learn, as far as i have seen its quite simple and straightforward. The problem is not its learning curve, the problem is that i need to learn it by figuring it out. Not too hard, but some explanation of the statements would help a lot.

 For example, in this statement:

Code: [Select]
macro dim_arraytype(ty,va,y,x  ityp,ivar)
 Are ityp and ivar something like MACROTEMPs? If so, what determines them as such? 3 spaces with no comma?

 Also, another issue i am having is the freedom of syntax. As things are now, Its a double edged sword, because i dont know if we are talking about a language or another, and the code needs to be interpreted every time. Is it correct? Is it oxygen?

 Its great to have the flexibility!! but sometimes also consistency is needed.

 Anyway, i am slowly progressing. Soon i will have something to show to the world. :)

Brian Alvarez

  • Guest
Re: Dimension an array of zstrings.
« Reply #22 on: May 02, 2018, 01:20:05 PM »
A couple questions...

 In Oxygen, If i need to get the variable address of the string, would i need to @va[29].s or va[29].@s, will i need another macro for that?

 How would i get the length of the fixed length string?

 If the strings are defined as a contiguous 255 character length + null terminated, would i need an extra character for the null or the next string would interfere? I think Oxygen will need to check for either the null character or the max length of 255... not sure if that can be done at higher level. Also i am guessing that passing it to core API functions that require a null terminated string, would cause issues.

 I think i will for now focus in some other areas, in the meantime i trust you guys will do wonders to sort this out. :)

 Thanks.
« Last Edit: May 02, 2018, 03:25:19 PM by Brian Alvarez »

Charles Pegge

  • Guest
Re: Dimension an array of zstrings.
« Reply #23 on: May 02, 2018, 07:57:20 PM »
Hi Brian,

macro dim_arraytype(ty,va,y,x  ityp,ivar)


Quote
Are ityp and ivar something like MACROTEMPs? If so, what determines them as such? 3 spaces with no comma?

Yes, they are the equivalent of MacroTemp. Any unused terms in the macro header will be renamed with a unique symbol, so they are not identifiable outside the macro.

In this form of macro header, commas are not significant, but there should be one after the x, for consistency.

Quote
Also, another issue i am having is the freedom of syntax. As things are now, Its a double edged sword, because i dont know if we are talking about a language or another, and the code needs to be interpreted every time. Is it correct? Is it oxygen?

Yes, I agree. I think we will eventually arrive at a preferred syntax, which gives the clearest possible expression of BASIC code.

Quote
In Oxygen, If i need to get the variable address of the string, would i need to @va[29].s or va[29].@s, will i need another macro for that?

The address of string chars is always strptr(..), for example:  strptr(va[29].s)

This is distinct from the resolved address of the variable @va,  @va[29].s


Quote
How would i get the length of the fixed length string?

 If the strings are defined as a contiguous 255 character length + null terminated, would i need an extra character for the null or the next string would interfere? I think Oxygen will need to check for either the null character or the max length of 255... not sure if that can be done at higher level. Also i am guessing that passing it to core API functions that require a null terminated string, would cause issues.

len(..) also works for fixed length strings. It counts up to, but not including a null character. It won't tell you the allocated size.

When creating a fixed length string, include the null terminator in your count

Brian Alvarez

  • Guest
Re: Dimension an array of zstrings.
« Reply #24 on: May 02, 2018, 09:12:06 PM »
Thanks Charles, that saves me time by not having to convert it. How about passing contiguous ZSTRINGS as API parameters? some windows APIs read up to the next null character. So, if i have, lets say, 2 ZSTRINGS of length 5 and i store in both of them: "Hello", if i pass the first item as a parameter, will the API read "HelloHello"? Just making sure Oxygen will handle this correctly.

Also, will LEN work correctly in such situations?
« Last Edit: May 02, 2018, 09:23:47 PM by Brian Alvarez »

Brian Alvarez

  • Guest
Re: Dimension an array of zstrings.
« Reply #25 on: May 02, 2018, 09:31:21 PM »
Im used to having it store, for example:

Code: [Select]
"Hell" + nul + "Hell" + null
I can generate strings correctly terminated with null, but i personally believe Oxygen should do it natively... thats what ZSTINGS are all about. Would it be too hard to implement it?

Charles Pegge

  • Guest
Re: Dimension an array of zstrings.
« Reply #26 on: May 02, 2018, 09:37:39 PM »
Yes, As long as there is a null terminator after the end of "Hello" this will be handled correctly, as an individual string.

So you can create multiple zstrings in one buffer string, separated by null characters.

O2 also supports wchar / zstring2. For unicode strings 2 null terminator bytes are required
« Last Edit: May 02, 2018, 09:44:40 PM by Charles Pegge »