【问题标题】:output keyword in OCamlOCaml 中的输出关键字
【发布时间】:2018-10-04 19:51:34
【问题描述】:

我想知道关键字 output 在 OCaml 中的含义。

我查看了文档,上面写着:

val output : out_channel -> bytes -> int -> int -> unit

output oc buf pos len writes len characters from byte sequence buf, starting at offset pos, to the given output channel oc. Raise Invalid_argument "output" if pos and len do not designate a valid range of buf.

问题是我完全不明白这意味着什么。

如果您能提供一个使用关键字输出的简单代码示例,那就太好了。

谢谢!

【问题讨论】:

    标签: ocaml


    【解决方案1】:

    没有关键字outputPervasives 模块中只有一个名为 output 的 函数

    output 的目的是将一些字节写入输出通道。

    如果你选择了可打印字节,并且你的输出通道是标准输出,你可以在一个小测试中看到结果:

    # let mybytes = Bytes.of_string "hello\n";;
    val mybytes : bytes = Bytes.of_string "hello\n"
    # output stdout mybytes 0 6;;
    hello
    - : unit = ()
    #
    

    为了表明output 只是一个标识符(即名称)而不是关键字,请注意您可以定义自己的值,命名为output

    # let output = 3010;;
    val output : int = 3010
    #
    

    then等真正的关键字并非如此:

    # let then = 3010;;
    Error: Syntax error
    #
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-06
      • 2016-12-17
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2013-07-14
      • 2014-12-25
      相关资源
      最近更新 更多