### Author Topic: Redimensioning  (Read 1118 times)

0 Members and 1 Guest are viewing this topic.

#### Arnold

• Hero Member
• Posts: 700
##### Redimensioning
« on: August 11, 2017, 04:18:15 AM »
Hi Charles,

when did you introduce "redim" in OxygenBasic? I did some experiments and redim seems to work quite nice.

Roland

Code: [Select]
`include "\$/inc/console.inc"redim int a[5]a = {1,2,3,4,5}printlfor x=1 to 5 : print a[x] " " : nextprintlredim int a(10)for x=1 to 10 : print a[x] " " : nextprintltype compound   int val1   string val2end typeredim compound c[5]c = {1,"this", 2,"is", 3,"a", 4,"great", 5,"feature"}printlfor x=1 to 5 : print c[x].val1 "," c[x].val2 "  " : nextprintlredim compound c(10)for x=1 to 10 : print c[x].val1 "," c[x].val2 "  " : nextprintlprintl "Enter ... " : waitkey`
Output:

1 2 3 4 5
1 2 3 4 5 0 0 0 0 0

1,this  2,is  3,a  4,great  5,feature
1,this  2,is  3,a  4,great  5,feature  0,  0,  0,  0,  0,

Enter ...

#### Charles Pegge

• Admin Support Member
• Posts: 3837
##### Re: Redimensioning
« Reply #1 on: August 11, 2017, 08:05:52 AM »
Hi Roland,

redim was quietly introduced as a core macro on 10 March 2017. It uses strings for dynamic buffering, so garbage collection is automatic.

The data string name is the same as the array name with '_buffer' appended.

Here is the macro (from o2keyw.bas):

Code: [Select]
`data  "redim 18"+cr+_      "#ifndef %2"+cr+_      "  dim static string %2_buffer = "+qu+qu+cr+_      "  dim static %1 byref %2"+cr+_      "#endif"+cr+_      "scope"+cr+_      "dim sys %2_qb = %3"+cr+_      "dim sys %2_le = len %2_buffer"+cr+_      "dim sys %2_qn = %2_le / sizeof(%1)"+cr+_      "if %2_qb > %2_qn"+cr+_      "  %2_buffer += nuls( sizeof(%1) * (%2_qb - %2_qn))"+cr+_      "elseif %2_qb <  %2_qn"+cr+_      "  %2_buffer = left( %2_buffer, sizeof(%1) * %2_qb )"+cr+_      "end if"+cr+_      "@%2=strptr(%2_buffer)"+cr+_      "end scope"+cr`

#### John

• Hero Member
• Posts: 3392
##### Re: Redimensioning
« Reply #2 on: August 11, 2017, 09:59:50 AM »
Code: OxygenBasic
1. s = """
2. Multi-line
3. string support
4. would be a nice feature
5. in OxygenBasic.
6. """
7.
8. PRINT s
9.

#### Charles Pegge

• Admin Support Member
• Posts: 3837
##### Re: Redimensioning
« Reply #3 on: August 11, 2017, 10:45:12 AM »
Hi John,

We have it for all string literals

string s="
a
b
c
"
string t=`
a
b
c
`
string u=quote  !!!
a
b
c
!!!

With the quote keyword you can use any block of characters to represent a quote mark.

#### Mike Lobanovsky

• Admin Support Member
• Posts: 1871
##### Re: Redimensioning
« Reply #4 on: August 11, 2017, 01:50:20 PM »
string u=quote  !!!
a
b
c
!!!

With the quote keyword you can use any block of characters to represent a quote mark.

OxygenBasic is becoming wonderfuller and wonderfuller with every passing day.
Mike
(3.6GHz Intel Core i5 Quad w/ 16GB RAM, 2 x nVidia GTX 650Ti w/ 2GB VRAM, Windows 7 Ultimate Sp1)

#### Charles Pegge

• Admin Support Member
• Posts: 3837
##### Re: Redimensioning
« Reply #5 on: August 12, 2017, 01:01:07 AM »
Well, Indie Basics face tough competition from so many other languages.

I hope good ideas will propagate!

Just to be sure quote symbols are free from early interception:

Code: [Select]
`s=quote !!'a//b/* c */!!print s`
Code: [Select]
`s=quote //'a/* c *///print s`