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

[REBOL] Re: A little bit of Rebol content

From: pwawood::mango::net::my at: 27-Dec-2004 22:19

Hi Brian A couple of points relating to datatypes and variables that aren't clear from your notes. This is my understanding as a fellow Rebol learner. I'm sure that the many wise Rebolers will chip in and correct my mistakes. 1. Everything is a value in Rebol. Values have datatypes.
>> type? 1
== integer! type? now == date!
>> type? /time
== refinement!
>> type? now/time
== time! 2. Rebol infers the datatype of a value from its format
>> type? 12.34.56.78
== tuple!
>> type? http://www.bbc.co.uk
== url! 3. Rebol simply evaluates the values in the order it is presented with them, normally a line at a time (though blocks enclosed in [] can extend over a line). Each datatype has it's own evaluation rules.
>> 1
== 1
>> now
== 27-Dec-2004/14:04:40+8:00
>> now/time
== 14:04:14
>> [big bigger biggest]
== [big bigger biggest] 4. In console mode, Rebol returns the last value it evaluated :
>> 1 2 3 4 5 6
== 6
>> now/time 5
== 5 5. There are no variables in Rebol. Rebol has the datatype word. A word stores the "address" of a value. When Rebol evaluates a word, it actually evaluates the value "pointed" to by the word.
>> soup-of-the-day
== "minestrone" Even before passing a word to the type? function which returns the datatype of a value, Rebol evaluates the word as the underlying value "pointed" to by the word.
>> type? soup-of-the-day
== string! Sometimes you don't want Rebol to evaluate a word but want to refer to the word itself. This is done by putting a ' in front of the word. This is referred to as a literal word or lit-word in Rebol.
>> type? 'soup-of-the-day
== word! A word is "connected" to value by using the set function :
>> set 'soup-of-the-day "minestrone"
== "minestrone" or its shorter form, known as a set-word:
>> soup-of-the-day: "oxtail"
== "oxtail" Words can be pointed at any type of value including other words, blocks, functions, ports, schemes and so on. One of the Rebol learners mistakes that I often make is to expect a word to always point to a value of a certain type. In most programming languages the datatype is associated with the variable (eg int i), but in Rebol the datatype is associated with the value not the word that points to it. Here is an example :
>> string: "12345"
== "12345"
>> type? string
== string!
>> string: find string "a"
== none
>> type? string
== none! But you probably knew all of this already. Happy Reboling Peter