文字和評論

評析

"Comments are enclosed in double quotes. BEWARE: This is NOT a string!"
"They can span
 multiple lines."

字串

'Strings are enclosed in sigle quotes.'
'Single quotes are escaped with a single quote, like this: ''.'
''''  "<--This string contains one single quote"

'Strings too can span
multiple lines'

''   "<--An empty string."

符號

#thiIsaSymbol  "Symbols are interned strings, used for method and variable names,
                and as values with fast equality checking."
#'hello world' "A symbol with a space in it"
#''            "An empty symbol, not very useful"
#+
#1             "Not the integer 1"

人物

$a     "Characters are not strings. They are preceded by a $."
$A     "An uppercase character"
$      "The spacecharacter!"
$→     "An unicode character"
$1     "Not to be confused with the number 1"

數字

數字有各種各樣:

整數:

  • 十進位制

    10

    -1

    0

    1000000000000000000000000000000000000000000

  • 十六進位制

    16rAB1F

    16r0

    -16rFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

  • ScaledDecimal

    17s0

    3.14159265s8

  • 其他

    8r7731八進位制

    2r1001二進位制

    10r99987“十進位制再次!”

浮點

3.14 1.2e3     "2 floating-point numbers"

餾分

分數與浮點數不同,它們是精確數字(沒有舍入誤差)。

4/3            "The fraction 4/3"
355/113        "A rational approximation to pi"

陣列

#(#abc 123)    "A literal array with the symbol #abc and the number 123"

位元組陣列

#[1 2 3 4]       "separators are blank"
#[]              "empty ByteArray"
#[0 0 0 0 255]   "length is arbitrary"

動態陣列

動態陣列是從表示式構建的。大括號內的每個表示式在構造的陣列中求值為不同的值。

{self foo. 3 + 2. i * 3}   "A dynamic array built from 3 expressions"

[ :p | p asString ] "A code block with a parameter p.
                     Blocks are the same as lambdas in other languages"

一些說明:

請注意,文字陣列使用任何種類和數量的空格作為分隔符

#(256 16rAB1F 3.14s2 2r1001 $A #this)
"is the same as:"
#(256
  16rAB1F
  3.14s2
  2r1001
  $A #this)

另請注意,你可以撰寫文字

#[255 16rFF 8r377 2r11111111]       (four times 255)

#(#[1 2 3] #('string' #symbol))     (arrays of arrays)

對寬鬆的符號有一些寬容

#(symbol) = #(#symbol)              (missing # => symbol)

#('string' ($a 'a'))                (missing # => array)

但不是這裡:

#([1 2 3]) ~= #(#[1 2 3])           (missing # => misinterpreted)

然而

#(true nil false)                   (pseudo variables ok)

但不是在這裡!

#(self) = #(#self)                  (missing # => symbol)

正如你所看到的,存在一些不一致之處:

  • 偽變數 truefalsenil 在陣列中被接受為文字,偽變數 selfsuper 被解釋為符號 (使用非限定字串的更一般規則。)

  • 雖然寫入 #( 並不是必須在陣列中啟動巢狀陣列並且括號足夠,但是必須編寫 #[ 來啟動巢狀的 ByteArray

其中一些取自:

http://stackoverflow.com/a/37823203/4309858