Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Is a "series" aka an "array"

 [1/22] from: dukeofperl:ml1 at: 3-Nov-2010 16:02


Hey list... I'm re-visiting REBOL, and I must say that I'm appreciating it a whole lot more this 2nd time around. Just to be clear - is a REBOL series exactly the same thing as an array in other languages? -- Duke

 [2/22] from: tom:conlin:g:mail at: 3-Nov-2010 15:31


Hi Duke, the question is ... broad ... array in different languages can mean different things and rebol has it's own array that is closer to arrays in some other languages I think it is safe to say a series in rebol can 'cover' most of the roles of arrays in other languages. A block (which is a subset series) may be a bit closer to a general 1D array. On 11/3/2010 3:02 PM, Duke Normandin wrote:

 [3/22] from: dhsunanda:g:mail at: 3-Nov-2010 22:40


Hey Duke
> I'm re-visiting REBOL, and I must say that I'm appreciating it a whole > lot more this 2nd time around. >
Welcome back! Glad REBOL deserved a second look.
> Just to be clear - is a REBOL series exactly the same thing as an > array in other languages?
They can be used as arrays, but have more flexibility. The official definition is: A series is a set of values arranged in a specific order. It's well worth taking a swing through the chapter on series in the REBOL Core documentation. http://www.rebol.com/docs/core23/rebolcore-6.html Anything unclear? Just ask! Sunanda

 [4/22] from: dukeofperl:ml1 at: 3-Nov-2010 16:51


On Wed, 3 Nov 2010, tomc wrote: Hello Tom,
> the question is ... broad ... array in different languages can mean > different things and rebol has it's own array that is closer to > arrays in some other languages
umm... Haven't got that far in the tutorial, to encounter REBOL arrays yet.
> I think it is safe to say a series in rebol can 'cover' most of the > roles of arrays in other languages. A block (which is a subset > series) may be a bit closer to a general 1D array.
At first glance, a series as described in http://www.rebol.com/docs/core23/rebolcore-6.html looked an awful lot like a regular array in some languages, except that the indexing in a REBOL series is not zero-based. It seems that there are _a lot_ of built-in functions to "slice-n-dice" a series - just like in Lisp, e.g. I'm just trying to categorize a REBOL series into a slot that I'm familiar with. -- Duke

 [5/22] from: dhsunanda:gm:ail at: 3-Nov-2010 23:11


Duke Normandin:
> looked an awful lot like a regular array in some languages
As Tom says, depending on the other languages, REBOLs series may have some or all of the capabilities of their arrays -- and vice versa. Remember that a series is not just a block....Strings (and some other data types) are also series, so REBOL has a regular set of operations that apply to strings as well as series. So, from another perspective, REBOL series look a lot like regular strings in other languages :). A couple of things you can do with block series that may not be obvious from the core documentation..... Each element in a block can be any datatype: blk: copy [99 "a" 1-jan-2010 [1 2 3]] blk/2 == "a" ;; is a strings blk/1 == 99 ;; is an integer blk/4 == [1 2 3] ;; is another block insert at blk 2 1.1 ;; insert at new entry at position 2 probe blk == [99 1.1 "a" 1-Jan-2010 [1 2 3]] ;; inserting has shuffled down the entries to make room -- more like a list in some languages append/only blk blk == [99 1.1 "a" 1-Jan-2010 [1 2 3] [...]] ;; blk now contains itself Have fun playing with series! Sunanda

 [6/22] from: dukeofperl:ml1 at: 3-Nov-2010 23:00


On Wed, 3 Nov 2010, Sunanda wrote:
> Have fun playing with series!
Thanks! Having fun while learning - that's the best motivator along the learning curve, IMO. -- Duke

 [7/22] from: tim-johnsons:web at: 4-Nov-2010 11:54


* Duke Normandin <dukeofperl-ml1.net> [101103 15:10]:
> Hey list... > > I'm re-visiting REBOL, and I must say that I'm appreciating it a whole > lot more this 2nd time around. > > Just to be clear - is a REBOL series exactly the same thing as an > array in other languages?
Hi Duke I'm going to take a little different track on your question: First of all, datatypes in rebol are layed out in a hierarchy. This differs from any other programming language that I have worked with. So .... a block is a series, but a series is not necessarily a block because the block! datatype is subordinate to the series datatype as is string!, issue! and others: From the console
>> type? #000000
== issue!
>> series? #000000
== true
>> b: [my name is Duke]
== [my name is Duke]
>> type? b
== block!
>> series? b
== true
>> s: "my name is duke"
== "my name is duke"
>> type? s
== string!
>> series? s
== true ;; end of code I hope you don't find this too confusing, but this knowledge may prove helpful, for instance in setting up the interface for a function. -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com

 [8/22] from: dukeofperl:ml1 at: 4-Nov-2010 18:59


On Thu, 4 Nov 2010, Tim Johnson wrote:
> * Duke Normandin <dukeofperl-ml1.net> [101103 15:10]: > >
<<quoted lines omitted: 5>>
> > Just to be clear - is a REBOL series exactly the same thing as an > > array in other languages?
[snip]
> >> type? #000000 > == issue!
<<quoted lines omitted: 15>>
> I hope you don't find this too confusing, but this knowledge may > prove helpful, for instance in setting up the interface for a function.
So... It seems that several REBOL data-types fall into an umbrella category called "series". Is there a particular reason for *categorizing* these data-types under the name "series"? -- Duke

 [9/22] from: carl:cybercraft at: 5-Nov-2010 5:12


On Thursday, 4-Novenber-2010 at 18:59:10 Duke Normandin wrote,
>So... It seems that several REBOL data-types fall into an umbrella >category called "series". Is there a particular reason for *categorizing* >these data-types under the name "series"?
For one, it means routines that are written to handle series will then handle all the types that are series. ie...
>> foreach value "abc" [print value]
a b c
>> foreach value [xxx yyy zzz] [print value]
xxx yyy zzz
>> foreach value %file.r [print value]
f i l e . r -- Carl Read.

 [10/22] from: izkata:gma:il at: 4-Nov-2010 20:41


On Thu, Nov 4, 2010 at 8:25 PM, Carl Read <carl-cybercraft.co.nz> wrote:
> On Thursday, 4-Novenber-2010 at 18:59:10 Duke Normandin wrote, > >
<<quoted lines omitted: 22>>
> To unsubscribe from the list, just send an email to > lists at rebol.com with unsubscribe as the subject.
As another quick example, there's a datatype called number! that both integer! and decimal! fall under. -- <*>

 [11/22] from: gregg:pointillistic at: 4-Nov-2010 21:01


DN> So... It seems that several REBOL data-types fall into an umbrella DN> category called "series". Is there a particular reason for *categorizing* DN> these data-types under the name "series"? Yes. They all contain a series of values. -- Gregg

 [12/22] from: dukeofperl:ml1 at: 4-Nov-2010 22:45


On Thu, 4 Nov 2010, Izkata wrote:
> On Thu, Nov 4, 2010 at 8:25 PM, Carl Read <carl-cybercraft.co.nz> wrote: > >
<<quoted lines omitted: 32>>
> As another quick example, there's a datatype called number! that both > integer! and decimal! fall under.
I've been thinking the very same thing! But is "number" the data-type, or integer and decimal the data-type (as in other languages). You see? I don't see the point, e.g. using the Pascal family paradigm, of having LONGINT, INTEGER, SHORTINT, REAL etc, which are data-types, and giving them the collective name of "numbers". What would be the point? In REBOL, the functions that operate on a "block", also work on a string, also work etc etc etc. So is a "series" some OOP super CLASS or something members inherent all those methods (functions). -- Duke

 [13/22] from: dukeofperl:ml1 at: 4-Nov-2010 22:47


On Fri, 5 Nov 2010, Carl Read wrote:
> On Thursday, 4-Novenber-2010 at 18:59:10 Duke Normandin wrote, > >
<<quoted lines omitted: 17>>
> . > r
I'm thinking that my reply to Iskata, comes close to what you mean above. What do think? -- Duke

 [14/22] from: carl:cybercraft at: 5-Nov-2010 5:14


On Thursday, 4-Novenber-2010 at 22:45:03 Duke Normandin wrote,
>> As another quick example, there's a datatype called number! that both >> integer! and decimal! fall under. > >I've been thinking the very same thing! But is "number" the data-type, >or integer and decimal the data-type (as in other languages). You see?
number! and series! are called pseudo-types to distinguish them from the other, normal datatype.
>I don't see the point, e.g. using the Pascal family paradigm, of having >LONGINT, INTEGER, SHORTINT, REAL etc, which are data-types, and giving >them the collective name of "numbers". What would be the point?
Well, if you're doing maths you can then check if the data is a number...
>> integer? 7
== true
>> integer? 7.5
== false
>> number? 7
== true
>> number? 7.5
== true
>In REBOL, the functions that operate on a "block", also work on a >string, also work etc etc etc. So is a "series" some OOP super CLASS >or something members inherent all those methods (functions).
I'll leave others to answer that since my experience of class and such in other languages is limited. -- Carl Read.

 [15/22] from: dukeofperl:ml1 at: 5-Nov-2010 6:40


On Fri, 5 Nov 2010, Carl Read wrote:
> On Thursday, 4-Novenber-2010 at 22:45:03 Duke Normandin wrote, > >> As another quick example, there's a datatype called number! that both
<<quoted lines omitted: 4>>
> number! and series! are called pseudo-types to distinguish them from > the other, normal datatype.
OK! We're getting close... What is the motivation/reason for having a pseudo-type?
> >I don't see the point, e.g. using the Pascal family paradigm, of having > >LONGINT, INTEGER, SHORTINT, REAL etc, which are data-types, and giving
<<quoted lines omitted: 8>>
> >> number? 7.5 > == true
Sure ... REBOL has "predicates" that asks a question about a data-type - "are you an integer?" yes or no? Are you a "real"? yes or no? But what's the point of asking, "are you a number? The question is too broad, is it not? Does asking "are you a number?" lead me down a different path than asking the question, "are you an integer?" ? Get my point? -- Duke

 [16/22] from: semseddinm:bircom at: 5-Nov-2010 15:04


Hi, As Carl Read mentioned, number and series are pseudo datatypes to group some similar datatypes. You can do "A: MAKE INTEGER! 5" but cannot do "A: MAKE NUMBER! 5" for example. It is mostly useful when you PARSE an input. PARSE [A 4.3 [x]] [word! number! series!] ;== true PARSE [B 5 "hello"] [word! number! series!] ;==true So you can iterate or something if it is a series! type. Fri, 05 Nov 2010 14:40:38 +0200 tarihinde Duke Normandin <dukeofperl-ml1.net> şöyle yazmış:

 [17/22] from: santilli:gabriele:g:mail at: 5-Nov-2010 15:02


On Fri, Nov 5, 2010 at 1:40 PM, Duke Normandin <dukeofperl-ml1.net> wrote:
> But what's the point of asking, "are you a number? The question is too > broad, is it not?
No, it is not. Examples: my-join: func [series1 [series!] series2 [series!]] [append copy series1 series2] rather than: my-join: func [ series1 [binary! block! email! file! hash! issue! list! paren! path! string! tag! url!] series2 [binary! block! email! file! hash! issue! list! paren! path! string! tag! url!] ] [ append copy series1 series2 ] Not counting the fact that if a new version of REBOL adds a new series type, you don't need to change your code to account for it.

 [18/22] from: tim-johnsons:web at: 5-Nov-2010 7:20


* Duke Normandin <dukeofperl-ml1.net> [101104 17:56]: <....>
> So... It seems that several REBOL data-types fall into an umbrella > category called "series". Is there a particular reason for *categorizing* > these data-types under the name "series"?
For *my* purposes, this hierarchy allows me to fine-tune function interfaces. I'm sure that further replys are going to edify me as well as you. And, also note that other replys will refer to other types of datatype hierarchies. cheers -- Tim tim at johnsons-web.com or akwebsoft.com http://www.akwebsoft.com

 [19/22] from: moliad:gmai:l at: 27-Nov-2010 3:56


Rebol as a language is so richly typed that what you would normally program as strings, arrays or numbers in other languages, you can do with human understandable datatypes in Rebol (dates, html tags, etc). pseudo types allow you to use several types as a concept rather than having to support each one individually. Gabriele gave you an example for function arguments which is widely used, here is another example which shows how useful pseudo types can be:
>> find [ 1x1 11.22.33 "2" #2 2 <2> 2.0 ] number!
== [2 <2> 2.0]
>> find [ 1x1 11.22.33 "2" #2 2 <2> 2.0 ] series!
== ["2" #2 2 <2> 2.0] you see that the first find really found the first number in the block, whereas the second returned the first series it found. going a bit further, I'll point out that to be considered a series, a datatype must contain an index. in the traditional sense, an array doesn't have an embedded index. so for example:
>> a: skip [ 1 2 3 4 5] 2
== [3 4 5]
>> index? a
== 3 if we refer to the find example above, you will notice that it skipped both the pair! and tuple! datatypes... this is because they are neither numbers nor series. why? they aren't a single value, but they also do not have an index. so although you can do:
>> second 11x22
== 22 you cannot do:
>> a: skip 11.22.33 1
** error ** skip expected series ... these two actually fall into another pseudo-type! scalar!
>> scalar? 11.22.33
== true
>> scalar? 11x22
== true
>> scalar? 1
== true so if we attempt the find above with scalar! (only works in R3) ... we get:
>> find [ 1x1 100.20.300 "2" #2 2 <2> 2.0 ] scalar!
== [2 <2> 2.0] (in R2, scalar! is not really a pseudo type, but just a block! which holds all scalar types. this was fixed in R3). hope this helps! :-D -MAx

 [20/22] from: moliad:gma:il at: 27-Nov-2010 4:00


also, forgot.... 100.20.300 isn't a valid tuple!, since they are restricted to byte sized components (values 0-255)

 [21/22] from: dukeofperl:ml1 at: 27-Nov-2010 6:15


On Sat, 27 Nov 2010, Maxim Olivier-Adlhoch wrote:
> Rebol as a language is so richly typed that what you would normally > program as strings, arrays or numbers in other languages, you can do > with human understandable datatypes in Rebol (dates, html tags, etc).
[snip the good stuff]
> hope this helps! :-D
Hello Max .... I was the OP - must be 2-3 weeks ago. It sure does help - and "fleshes out" previous responses. Much obliged! -- Duke

 [22/22] from: moliad:gma:il at: 27-Nov-2010 3:59


oops...
>> find [ 1x1 100.20.300 "2" #2 2 <2> 2.0 ] scalar!
== [ 1x1 100.20.300 "2" #2 2 <2> 2.0 ] (sorry)

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted