代码之家  ›  专栏  ›  技术社区  ›  Flux

在Racket REPL中的标识符上加一个“prime”后的奇怪输出

  •  2
  • Flux  · 技术社区  · 6 年前

    今天,我在REPL中输入了一个错误,发现了一个奇怪的行为。以下是互动示例:

    Welcome to Racket v6.11.
    > (define x 3)
    > x
    3
    > x'
    3
    > x
    'x
    > 
    

    所以第一个 x 3 ,这是预期的。这个 x' 我不小心打出来了 ,这是出乎意料的。最后 'x (!!).

    1 回复  |  直到 6 年前
        1
  •  2
  •   Alex Knauth    6 年前

    看到了吗 Racketrivia: Using ' as an "identifier suffix" 在诈骗邮件列表上。这个 reply by Robby Findler reply by Matthias Felleisen 两者都解释了这一点。

    第一行, x ,正常。

    x' ,实际上是一个“表达式和半”。它被解释为一个表达式 接着是一个 未完成 表达 ' next-line .

    也就是说第三个 实际上被解释为 ' x .

    带圆括号的表达式:

    > 1 (list 2     ; 1 followed by an unfinished expression
    1
    > 3 4)          ; finishing it
    '(2 3 4)
    > 3 4)          ; on its own without the `(list 2` before it it's an error
    3
    4
    ; readline-input:13:3: read-syntax: unexpected `)` [,bt for context]
    

    > 1 '                            ; 1 followed by an unfinished expression
    1
    > (indefatigable inexhaustible)  ; finishes previously unfinished, put after a quote
    '(indefatigable inexhaustible)
    > (indefatigable inexhaustible)  ; on its own without the quote before it it's an error
    ; indefatigable: undefined;
    ;  cannot reference an identifier before its definition
    ;   in module: top-level
    ;   internal name: indefatigable