Oxygen Basic
Programming => Example Code => Topic started by: Arnold 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
include "$/inc/console.inc"
redim int a[5]
a = {1,2,3,4,5}
printl
for x=1 to 5 : print a[x] " " : next
printl
redim int a(10)
for x=1 to 10 : print a[x] " " : next
printl
type compound
int val1
string val2
end type
redim compound c[5]
c = {1,"this", 2,"is", 3,"a", 4,"great", 5,"feature"}
printl
for x=1 to 5 : print c[x].val1 "," c[x].val2 " " : next
printl
redim compound c(10)
for x=1 to 10 : print c[x].val1 "," c[x].val2 " " : next
printl
printl "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 ...
-
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):
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
-
s = """
Multi-line
string support
would be a nice feature
in OxygenBasic.
"""
PRINT s
-
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.
-
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. :)
-
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:
s=quote !!
'a
//b
/* c */
!!
print s
s=quote //
'a
/* c */
//
print s