文字和评论

评析

"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