REBOL這個語言十分精巧,整個程式的編譯器也十分小,但是功能很強大,要執行它的程式只要花不到300k的硬體空間安裝一個小小的直譯器,再花300k裝一些其他的東西,總大小並不超過600k的小工具,跟龐大的.net(安裝完需要2.0G)比起來真是大大的減少硬碟空間,這麼小的程式到底能夠做什麼我一開始也很懷疑,因為好奇心的驅使下就嘗試,以下是我對它的功能的簡單說明,它的功能好像很多,一時之間也沒辦法讓我實驗完畢,我只先將我這幾天所體驗的結果做成以下紀錄。
我最先接觸到的功能就是它的網路能力,沒想到從網路上讀取檔案資料會如此簡單方便
print read http://www.ttu.edu.tw
以上這一行紅色的程式是從網路中讀取http://www.ttu.edu.tw的首頁,並將原始碼印出來,就僅僅只需要一行程式竟然就可以將遠方的資料像開啟你自己本機的資料不費力。
send g9106028@mail.ttu.edu.tw read http://www.ttu.edu.tw
以上這一行紅色的程式是從網路中讀取http://www.ttu.edu.tw的首頁,並將這些資料以email的方式傳送出去

這個程式也提供了多種的資料型態,例:
12:59 ←左邊是時間型態
$29.3 ←左邊是金錢型態
[red blue yellow] ←左邊是區塊型態
g9106028@mail.ttu.edu.tw ←左邊是email型態
其他還有String!、Tag!、tuple!...等等
Series型態的資料處理十分方便,Series包含Block Types、String Types等
變數設定使用':'
colors: [red green yellow]←左邊是設定colors這個變數的值是[red green yellow]
注意:設定變數使用':',注意':'後面必須空一格,在這個程式中空格相當重要
head? colors ←左邊是詢問colors是否指在區塊的開頭,如果是回答true
index? colors ←左邊是詢問colors的索引值是多少
tail? colors ←左邊是詢問colors是否指在區塊的結尾
length? colors ←左邊是詢問colors中共有多少元素,以此範例為5
colors: next colors ←左邊是在移動colors的視窗,表示將視窗向右移一個變成[green yellow]
colors: back colors ←左邊是在移動colors的視窗,表示將視窗向左移一個變成[red green yellow]
print pick colors 2 ←左邊是挑選出colors的第二個元素,在本例中所挑出來的是green
print colors/2 ←左邊是挑選出colors的第二個元素,在本例中所挑出來的是green
poke colors 2 'pink←左邊是修改colors的索引值2的值,結果[red pink yellow]
append colors 'green←左邊是在colors的最後插入'green',結果[red pink yellow green]
insert colors 'blue←左邊是在colors的最前面插入'blue',結果[blue red pink yellow green],要執行back colors才會看到結果
remove next colors←左邊是移除colors目前索引值的下一筆資料,結果[blue pink yellow green]
remove/part colors 2←左邊是移除colors目前索引值兩筆資料,結果[yellow green]
insert next colors [blue yellow orange]←左邊是在目前索引值的下一筆資料後插入[blue yellow orange]到colors,結果[yellow blue yellow orange green],要執行back colors才會看到結果
目前我們的colors中有部分的顏色重複
unique colors←左邊是消除colors中的重複,結果[yellow blue orange green]
intersect sort colors [black blue yellow]←左邊是取colors和[black blue yellow]的交集並做排序,結果[blue yellow]
union colors [black blue yellow]←左邊是取colors和[black blue yellow]的聯集,結果[blue green orange yellow black]
還有很多如find、search等等都可以使用在Series這種型態上,到底在REBOL這個語言中到底有多少是屬於Series,請自行查閱,至少字串和我剛剛所使用的都是屬於Series

這個語言雖小,但卻提供不少的功能,以上僅就Series方面的功能做介紹,好像這個語言也可以使用物件的方式來撰寫,真是小右實用的語言
 
變數設定:
例子:
設定一個字串a,內容為"hello world"
a: "hello world"
設定一個變數i,值為1
i: 1
==>i=i+1
i: i + 1
注意中間有空格區隔

條件判斷:
if [year > 20] [print "old man"]

陣列:
a: [1 2 3 4 5]
print first a
1
print second a
2
print third a
3
print fourth a
4
print fifth a
5
print last a
5
insert a 6
a=[6 1 2 3 4 5]
append a 7
a=[6 1 2 3 4 5 7]
remove a
a=[1 2 3 4 5 7]
remove/part a 3
a=[4 5 7]

迴圈:
i: 0
while [i < 5] [print i i: i+1]
先將i值設為0然後執行while迴圈,看看i 值是否小於5,若小於5則印出i值

函數定義:
main: func [argv] [print argv]
main ["hello"] 

詳細的使用說明 
arrow
arrow
    全站熱搜

    CJY0503 發表在 痞客邦 留言(0) 人氣()