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

[REBOL] Re: Is a "series" aka an "array"

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