跳轉到內容

Rebol 程式設計/內部

來自 Wikibooks,開放世界中的開放書籍

Rebol 內部

[編輯 | 編輯原始碼]

系統物件

[編輯 | 編輯原始碼]

系統物件是一個非常大的物件,包含 Rebol 中的大部分中間層程式碼,即 VID、網路協議和有關您正在執行的 Rebol 產品的系統資訊。

原生函式

[編輯 | 編輯原始碼]

原生函式是硬編碼到 Rebol 核心中的函式。它們可以被認為是低階函式,旨在提高速度。存在大量的原生函式。

您可以在控制檯中像這樣顯示一個原生函式

>> source insert
insert: native [
    {Inserts a value into a series and returns the series after the insert.} 
    series [series! port! bitset!] "Series at point to insert" 
    value [any-type!] "The value to insert" 
    /part "Limits to a given length or position." 
    range [number! series! port! pair!] 
    /only "Inserts a series as a series." 
    /dup "Duplicates the insert a specified number of times." 
    count [number! pair!]
]

由於函式已編譯到 Rebol 直譯器核心中,因此無法檢視原始碼。

中間層函式

[編輯 | 編輯原始碼]

中間層函式是在原生函式或其他中間層函式之上構建的函式。這意味著您可以更改它們或在現有函式之上構建更多函式。Rebol 在其所有產品中都內建了許多中間層函式。

它們可以被認為是更高級別的函式,旨在為編寫 Rebol 程式提供易用性。Rebol 中的網際網路協議,例如 HTTP 或 POP3,都是作為中間層函式構建的。

在設計自己的程式時,您可以構建自己的函式,這些函式與現有的中間層函式融為一體,例如,如果您希望使用新的網際網路協議擴充套件 Rebol。

中間層函式還很特別,因為您可以在控制檯中像這樣檢視它們的原始碼

>> source append
append: func [
    {Appends a value to the tail of a series and returns the series head.} 
    series [series! port!] 
    value 
    /only "Appends a block value as a block"
] [
    head either only [
        insert/only tail series :value
    ] [
        insert tail series :value
    ]
]
華夏公益教科書