【问题标题】:How to write an empty block如何写一个空块
【发布时间】:2023-01-31 06:21:30
【问题描述】:

你怎么写一个空块?例如,在 C 中,您可以有 { }。但在 BCPL 中,等效的 $( $) 是一个语法错误,因为一个块至少需要一个语句。那么如何进行以下编译呢?

let foo() be $(
    test bar then $(
        //to do
    $) else $(
        writes("baz*n")
    $)
$)

【问题讨论】:

    标签: bcpl


    【解决方案1】:

    好吧,首先,您的语法似乎是 testif 的一半。从记忆中,test的语法是test <expression> then <true-bit> or <false-bit>

    如果它是一个 if 语句,您可以切换到 unless (或保留 if 但用 bar 或类似的东西反转表达式)以获得所需的结果:

    // TODO: refactor later to use "if", and add other case.
    unless bar then $(  // or "if  bar".
        writes("baz*n")
    $)
    

    如果你真的想要保持原样(除了修复语法),任何 null 类型的语句(对功能没有影响的语句)都可以。例如 let xyzzy = 42writes("")

    【讨论】:

      猜你喜欢
      • 2011-02-11
      • 2013-08-03
      • 2018-06-02
      • 1970-01-01
      • 1970-01-01
      • 2010-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多