Search the web
Sign In
New User? Sign Up
OSCAR-PROJECT · OSCAR is an open source REBOL interpreter
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Series! Blocks, Arrays, Vectors Strings   Message List  
Reply | Forward Message #1012 of 1031 |
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





Fri Dec 14, 2001 6:55 pm

robbo1mark
Offline Offline
Send Email Send Email

Forward
Message #1012 of 1031 |
Expand Messages Author Sort by Date

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...
Robbo1Mark@...
robbo1mark
Offline Send Email
Dec 14, 2001
6:55 pm

... Switch these two and it's fine. I think the term vector is often used to mean resizable array. ... Not sure about these, but I don't have a better...
Marcus Petersson
d4marcus
Offline Send Email
Dec 18, 2001
10:01 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help