跳轉到內容

Rebol 程式設計/控制檯

來自華夏公益教科書,開放的書籍,為開放的世界

控制檯

[編輯 | 編輯原始碼]

互動式控制檯是您可以執行大部分程式設計操作的地方,用於測試程式碼的小片段並嘗試各種函式。它是學習 Rebol 函式的最佳方式。

如果您有 Rebol/View,您可以從控制檯訪問各種實用程式,例如桌面、文字編輯器和用於輸入的基本實用程式,這些實用程式可以在您的程式中使用。

如何訪問控制檯

[編輯 | 編輯原始碼]

當您使用 Rebol.exe 啟動 Rebol/Core 時,可以直接訪問控制檯,但這不允許您使用 桌面編輯器 命令。

如果您啟動 Rebol/View,它將從 Viewtop 開始。控制檯可以在視窗左側的底部圖示中訪問。要進入控制檯,請點選該圖示。您可以在控制檯提示符下輸入 桌面 命令返回 Viewtop。

使用控制檯

[編輯 | 編輯原始碼]

在開始 Rebol 程式設計之前,瞭解有關控制檯的一些重要基礎知識會很有幫助。您將花費大量時間在控制檯中!

只需鍵入命令,您就可以開始使用控制檯。如果您鍵入

>> now

Rebol 將返回當前日期和時間

== 2-Sep-2005/2:12:42+2:00

另一個例子

>> print "Hello world!"
Hello world!

數學運算也是可以的

>> 2 + 2
== 4

請注意 >> 和 == 符號

>>
這是您輸入函式和命令的提示符。
==
這是之前執行的程式或操作的 返回值 符號。

我們之前使用的 列印 函式只是在控制檯中產生了輸出。列印 函式的返回值是一個特殊值,直譯器在顯示結果時會忽略它。

讓我們嘗試一些會導致錯誤的操作

>> 2 / 0
** Math Error: Attempt to divide by zero
** Near: 2 / 0

Rebol 友好地使用 ** 符號生成錯誤資訊文字。

歷史命令

[編輯 | 編輯原始碼]

如果您想再次重試這些示例,請使用鍵盤上的向上箭頭鍵訪問 Rebol 的已執行函式歷史記錄。

要移動控制檯捲軸,您可以使用滑鼠或 Page-UpPage-Down

要顯示之前輸入的行,您可以使用 向上向下 箭頭,就像在 Linux 控制檯中一樣。

要修改它們,請使用 HomeEnd 鍵以及 DeleteBackspaceLeftRight 箭頭。

TAB 自動完成

[編輯 | 編輯原始碼]

TAB 鍵可用於自動完成:Rebol 將嘗試完成您正在鍵入的內容。例如,如果您只按 a 然後按 TAB,您將獲得以 a 開頭的所有單詞的建議。

>> action! any-type! any-word! any-function! any-string! any-block! action? any-type? any-word?
any-function? any-string? any-block? and add and~ absolute at alias all any as-string as-binary
access-os arccosine arcsine arctangent abs as-pair about apply also append ajoin array alter 
attempt ask ascii? any-path!  any-path? any-object! any-object? assert alert aqua alive?
a 

因此,如果您鍵入 ale,它將完成為 alert,這是唯一以 ale 開頭的單詞。

>> alert

如果您宣告一個變數,例如 aaa,Rebol 將記住它並也使用它進行自動完成。

控制檯幫助函式

[編輯 | 編輯原始碼]

可以使用 幫助 命令或其快捷方式問號 ? 訪問控制檯幫助。它可以

1- 在 Rebol 詞典中查詢一個詞並描述其內容。示例

>> ? day
No information on day (word has no value)
>> ? pi
PI is a decimal of value: 3.14159265358979
>> my-word: "beginning"
== "beginning"
>> ? my-word
MY-WORD is a string of value: "beginning"

2- 描述函式的語法

>> ? now
USAGE:
   NOW /year /month /day /time /zone /date /weekday /yearday /precise

DESCRIPTION:
    Returns the current local date and time.
    NOW is a native value.

REFINEMENTS:
    /year -- Returns the year only.
    /month -- Returns the month only.
    /day -- Returns the day of the month only.
    /time -- Returns the time only.
    /zone -- Returns the time zone offset from GMT only.
    /date -- Returns date only.
    /weekday -- Returns day of the week as integer (Monday is day 1).
    /yearday -- Returns day of the year (Julian)
    /precise -- Use nanosecond precision

3- 如果您在字串中鍵入元素的一部分,Rebol 將返回包含該字串的任何元素

>> ?? part-of-searched-word
Print result here
>> ? wor
Found these words:
  any-word!       datatype! any-word!
  any-word?       action!   Returns TRUE for any-word values.
  get-word!       datatype! get-word!
  get-word?       action!   Returns TRUE for get-word values.
  lit-word!       datatype! lit-word!
  lit-word?       action!   Returns TRUE for lit-word values.
  my-word         string!   "beginning"
  set-word!       datatype! set-word!
  set-word?       action!   Returns TRUE for set-word values.
  to-get-word     function! [value]
  to-lit-word     function! [value]
  to-set-word     function! [value]
  to-word         function! [value]
  word!           datatype! word!
  word?           action!   Returns TRUE for word values.

您也可以使用引號來搜尋字串。請注意這兩個示例之間的區別

>> ? "find"
Found these words:
  find            action!   Finds a value in a series and returns the series a...
  find-key-face   function! Search faces to determine if keycode applies.
  find-window     function! Find a face's window face.
>> ? find
USAGE:
   FIND series value /part range /only /case /any /with wild /skip size /match /tail /last /reverse
DESCRIPTION:
    Finds a value in a series and returns the series at the start of it.
    FIND is an action value.
ARGUMENTS:
    series -- (Type: series port bitset)
    value -- (Type: any-type)
REFINEMENTS:
    /part -- Limits the search to a given length or position.
        range -- (Type: number series port)
    /only -- Treats a series value as a single value.
    /case -- Characters are case-sensitive.
    /any -- Enables the * and ? wildcards.
    /with -- Allows custom wildcards.
        wild -- Specifies alternates for * and ? (Type: string)
    /skip -- Treat the series as records of fixed size
        size -- (Type: integer)
    /match -- Performs comparison and returns the tail of the match.
    /tail -- Returns the end of the string.
    /last -- Backwards from end of string.
    /reverse -- Backwards from the current position.

有關當前工作會話的其他有用資訊,可以使用以下 Rebol 詞

probe       : Displays the contents of a Rebol word in its original format.
source      : Displays the contents of a Rebol function.
what        : Lists all Rebol words currently defined.
what-dir    : Displays name of the current directory.
list-dir    : Lists all filenames in current directory.
change-dir  : Change current directory.

停止程式

[編輯 | 編輯原始碼]

您可以停止一個程式,如果它是在控制檯中執行的,或者如果它輸出到程式中開啟的控制檯,請按 Escape 鍵。這將使您返回到提示符。

華夏公益教科書