以下内容是从rebol.com站点上的资料整理而来的.
=======================
1.Values
REBOL有很多内嵌的数据类型。例如:
Numbers:
1234 -432 3.1415 1.23E12
0,01 1,2E12 ; non-British decimal format
Times:
12:34 20:05:32 0:25.34
Dates:
20-Apr-1998 20/Apr/1998 20-4-1998 1998-4-20
20-Apr-1998/12:32 ; date with time
20-Apr-1998/12:32-8:00 ; date with time and timezone
Money:
$12.34 USD$12.34 CAD$123.45 DEM$1234,56
Tuples:
3.1.5 ; version numbers
255.255.0 ; used for colors
199.4.80.7 ; Internet addresses
Coordinate Pairs:
5x10 100x100 -50x-25
Strings:
"Here is a string"
{Here is another way to write
a string that spans many lines
and contains "quoted" strings.}
Tags:
<title> </body>
Email:
info@rebol.com
URLs:
http://www.rebol.com ; web site
ftp://ftp.rebol.com/sendmail.r ; file transfer
mailto:info@rebol.com ; another email format
Files:
%data.txt
Issues:
#707-467-8000 ; a phone number
Binary:
#{0A6B14728C4DBEF5} ; hex encoded
2 Words(字)
这是变量名和函数名。赋值时使用冒号。
以下全是合法的字:
number? time? date!
image-files connection-times file-size
++ -- == +- ***** *new-line* left&right
但字中不可以包含以下符号:
/ @ # $ % ^ ,
字是以空格和下列字符为结束标志的:
[ ] ( ) { } " : ; /
3. Blocks (块)
块中可以包含值,函数,块等来作为数据结构,它也是组织代码的方式。包括在[]中。
4. Variables(变量)
字可以用来作变量。赋值时使用冒号。
变量的作用域可以是在一个块中,在一个函数中,或者整个程序中。
如果不作限制,定义出来的变量为全局变量,即使在块中或者函数中,
函数的参数和对象的属性除外。
要定义一个局部变量,可以使用"function"进行函数定义(参见函数),
可以使用字"use"进行块定义:
use [age] [
age: "young"
print age
]
5. Functions(函数)
例如:
sum: func [a b] [a + b]
"func"用来定义函数。a和b是参数,它们是局部的。此函数会返回两个参数的和。
"does"也可定义函数。但没有参数。
say-hello: does [print "Hello!:)"]
"function"也用来定义函数。它可以定义函数中使用到的局部变量。
average: function [series] [total] [ ;total是局部变量
total: 0
if zero? length? series [return 0]
foreach value series [total: total + value]
return total / (length? series)
]
6. Paths(路径)
路径使用符号"/"分隔每个字。我们用来最多的是文件路径和URL地址。
但它也可应用于块、函数、对象和字符串中:
1)块:取得块中某个位置的内容,或者取得块中键值对中某个键的值。
如:
pathblock: [today friday]
pathblock/2
pathblock/today
2)函数:往往是对函数进行定制
如:
read/binary http://www.rebol.com/
3)对象:引用对象中的可见属性或方法
account/name
4)字符串:进行定位
如:
my-string: "rebol"
my-string/4 ;output is #"o"
7 Objects(对象)
对象是用于组织一些相关的数值以及对这些数据的操作。
如定义一个账号:
account: make object! [
name: "Flintstone"
balance: $100
ss-number: #1234-XX-4321
deposit: func [amount] [balance: balance + amount]
withdraw: func [amount] [balance: balance - amount]
]
如果要对定义另一个账号,它只是在某些属性上值不同,或者它要增加
一些新的属性和方法,那可以这样定义:
checking-account: make account [
bank: "Savings Bank"
last-active: 20-Jun-1998
]
=======================
1.Values
REBOL有很多内嵌的数据类型。例如:
Numbers:
1234 -432 3.1415 1.23E12
0,01 1,2E12 ; non-British decimal format
Times:
12:34 20:05:32 0:25.34
Dates:
20-Apr-1998 20/Apr/1998 20-4-1998 1998-4-20
20-Apr-1998/12:32 ; date with time
20-Apr-1998/12:32-8:00 ; date with time and timezone
Money:
$12.34 USD$12.34 CAD$123.45 DEM$1234,56
Tuples:
3.1.5 ; version numbers
255.255.0 ; used for colors
199.4.80.7 ; Internet addresses
Coordinate Pairs:
5x10 100x100 -50x-25
Strings:
"Here is a string"
{Here is another way to write
a string that spans many lines
and contains "quoted" strings.}
Tags:
<title> </body>
Email:
info@rebol.com
URLs:
http://www.rebol.com ; web site
ftp://ftp.rebol.com/sendmail.r ; file transfer
mailto:info@rebol.com ; another email format
Files:
%data.txt
Issues:
#707-467-8000 ; a phone number
Binary:
#{0A6B14728C4DBEF5} ; hex encoded
2 Words(字)
这是变量名和函数名。赋值时使用冒号。
以下全是合法的字:
number? time? date!
image-files connection-times file-size
++ -- == +- ***** *new-line* left&right
但字中不可以包含以下符号:
/ @ # $ % ^ ,
字是以空格和下列字符为结束标志的:
[ ] ( ) { } " : ; /
3. Blocks (块)
块中可以包含值,函数,块等来作为数据结构,它也是组织代码的方式。包括在[]中。
4. Variables(变量)
字可以用来作变量。赋值时使用冒号。
变量的作用域可以是在一个块中,在一个函数中,或者整个程序中。
如果不作限制,定义出来的变量为全局变量,即使在块中或者函数中,
函数的参数和对象的属性除外。
要定义一个局部变量,可以使用"function"进行函数定义(参见函数),
可以使用字"use"进行块定义:
use [age] [
age: "young"
print age
]
5. Functions(函数)
例如:
sum: func [a b] [a + b]
"func"用来定义函数。a和b是参数,它们是局部的。此函数会返回两个参数的和。
"does"也可定义函数。但没有参数。
say-hello: does [print "Hello!:)"]
"function"也用来定义函数。它可以定义函数中使用到的局部变量。
average: function [series] [total] [ ;total是局部变量
total: 0
if zero? length? series [return 0]
foreach value series [total: total + value]
return total / (length? series)
]
6. Paths(路径)
路径使用符号"/"分隔每个字。我们用来最多的是文件路径和URL地址。
但它也可应用于块、函数、对象和字符串中:
1)块:取得块中某个位置的内容,或者取得块中键值对中某个键的值。
如:
pathblock: [today friday]
pathblock/2
pathblock/today
2)函数:往往是对函数进行定制
如:
read/binary http://www.rebol.com/
3)对象:引用对象中的可见属性或方法
account/name
4)字符串:进行定位
如:
my-string: "rebol"
my-string/4 ;output is #"o"
7 Objects(对象)
对象是用于组织一些相关的数值以及对这些数据的操作。
如定义一个账号:
account: make object! [
name: "Flintstone"
balance: $100
ss-number: #1234-XX-4321
deposit: func [amount] [balance: balance + amount]
withdraw: func [amount] [balance: balance - amount]
]
如果要对定义另一个账号,它只是在某些属性上值不同,或者它要增加
一些新的属性和方法,那可以这样定义:
checking-account: make account [
bank: "Savings Bank"
last-active: 20-Jun-1998
]