Author Topic: Elastic String Array  (Read 2851 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3005
    • ScriptBasic Open Source Project
Elastic String Array
« on: April 28, 2015, 08:28:37 PM »
I have been following the BP.org Elastic String Array thread and just want to mention that I haven't found ANY language that is more flexible than Script BASIC arrays. I challenge anyone to prove me wrong.

  • No need to pre-DIM arrays.
  • No limitations other than available memory with number of indices's, type or size.
  • Associative and standard index based arrays can be mixed together.
  • LBOUND/UBOUND values are dynamically adjusted at runtime.
  • Arrays can be exported to XML strings or SB formatted strings & restored back to SB arrays.
Script BASIC Array Tutorial

Offline John

  • Forum Support / SB Dev
  • Posts: 3005
    • ScriptBasic Open Source Project
Re: Elastic String Array
« Reply #1 on: April 28, 2015, 09:44:29 PM »
Quote from: AIR
Quote from: aurelB
so nothing will stop you...
create program in py which build a$[1000000]
then fill each element with just one char
and tell us how much time python need for that.
simple isn't?

Yes, simple indeed:

Code: Python
  1. #!/usr/bin/env python
  2. arr = ['c']*1000000
  3.  


[riveraa@Blossom ~] $ time ./arr.py

real   0m0.059s
user   0m0.033s
sys   0m0.021s


MacBook Pro laptop, 2.53 GHz Intel Core 2 Duo, 4GB ram, 250GB 5400 RPM mechanical drive

Here is AIR's Python example on my laptop.


jrs@laptop:~/python$ time ./arr.py

real   0m0.971s
user   0m0.030s
sys   0m0.020s
jrs@laptop:~/python$


Here is the Script BASIC execution time on my laptop.

Code: Script BASIC
  1. SPLITA STRING(1000000,"C") BY "" TO a
  2. PRINT UBOUND(a)," : ",a[UBOUND(a)],"\n"
  3.  


jrs@laptop:~/sb/sb22/test$ time scriba airray.sb
999999 : C

real   0m0.298s
user   0m0.177s
sys   0m0.120s
jrs@laptop:~/sb/sb22/test$

« Last Edit: April 28, 2015, 09:56:15 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3005
    • ScriptBasic Open Source Project
Re: Elastic String Array
« Reply #2 on: April 28, 2015, 10:37:21 PM »
Quote from: Aurel
and here we go:

Quote
Arrays in basic Python are actually lists that can contain mixed datatypes. However, the numarray module contains support for true arrays, including multi-dimensional arrays, as well as IDL-style array operations and the where function. To use arrays, you must import numarray or from numarray import *. Unfortunately, numarray generally only suports numeric arrays. Lists must be used for strings or objects. By importing numarray.strings and numarray.objects, you can convert string and object lists to arrays and use some of the numarray features, but only numeric lists are fully supported by numarray.

so what is that ?
there is no real array in python core than list?
well so it seems that Armando fill list of pointers?
and if you wish real array you depend on external modules   ::)

 :)

Quote from: bestofqbasic
(you mean you NEVER wanted option to mix strings and numerics in an array? never?)

I could NEVER go back to a language that doesn't support mixed type arrays.
« Last Edit: April 28, 2015, 11:32:27 PM by John »