I've been doing a lot of thinking about the
types of series! PRIMO ought to have available
both for ease of use and efficiency.
Basically series! have three distinct attibutes
which determine their use and suitability for
various purposes.
These three attributes are as follows;
1. SIZE - fixed or variable
Can values be added or removed to the series?
2. TYPE - any-type! or fixed datatype!
Can values in series! be of any-type! as in the
current REBOL block! & paren! implementation or
are the values of a fixed type! as in REBOL's
any-string! types which contain only char! values.
3. MUTABILITY
Can the values in the series! be changed or are
they immutable? An immutable series! by definition
has a fixed length, it's value is it's value - period.
With this is mind I propose the following series
types for PRIMO which allow for creating series!
with meet various combinations of the series attributes
I mentioned above.
Here are the series! I propose with their attributes
and propsed syntax notation & constructors.
block! any-type! variable size ; == []
array datatype! variable size ; == array datatype! []
vector datatype! fixed size ; == vector datatype! []
immutable block! any-type! fixed size ; == .[]
immutable vector datatype! ; == vector datatype! .[]
string! variable size ; == "" or {}
unicode-string! variable size ; == u"" or u{}
immutable string! fixed size ; == ."" or .{}
ditto for unicode-string! ; == .u"" or .u{}
Array is a constructor for a fixed datatype! series
which has the possibility of variable size ie values
can be added or removed.
It's notation is as follows,
Array: function [datatype [datatype!] data [block!] size [integer!]] [
make array! datatype data size
]
example usage
>> a: array integer! [1 2 3] 3 ; note zero indexed
== array integer! [1 2 3]
>> pick a 2
== 3
Vector is a constructor for a fixed datatype! series
which has the property of fixed size ie values
cannot be added or removed, but elements can be changed
unless the vector is immutable.
Vector: function [datatype [datatype!] data [block!] size [integer!]] [
make vector! datatype data size
]
example usage
>> a: vector integer! .[1 2 3] 3 ; immutable data
== vector integer! .[1 2 3]
>> pick a 0
== 1
>> poke a 2 4
** Script Error: vector a has immutable data, cannot be changed.
** near: poke a 2 4
>> b: vector integer! [1 2 3] 3 ; data is mutable
== vector integer! [1 2 3]
>> poke b 2 4
== vector integer! [1 2 4]
>> poke b 2 #"a"
** Script error: vector a is of type integer! not char!.
** near: poke b 2 #"a"
I feel by having series! with varying attributes like these
should enable the selection of the most efficient or appropriate
use of storage to suit the program needs with regards to either
polymorphism or repeated operations on fixed or single datatype!
Let me know what you think?
By the way, have I got my use of Vector and Array the correct
way round?
Array - fixed datatype & variable size
Vector - fixed datatype & fixed size
All series! can be either mutable or immutable and identifiable
with the prefix-joined dot notation ie .[] or ."" etc.
Also a mutable? predicate
>> a: .[1 2 3]
== .[1 2 3]
>> type? a
== immutable block!
>> mutable? a
== false
cheers everybody,
Mark Dickson