- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 OCaml 的新手,我想知道这个语句是如何工作的:
# 1 + 1 ;;;;
- : int = 2
# 1 + 1 ;;;;;;;;
- : int = 2
;;;;
视为合并
1+1
与
blank
如
(((1 + 1);););;
?或者是
;;;;
以其他方式被视为多字符?
最佳答案
如 discussed here , ;;
在顶级 REPL 中忽略它之后的所有内容。将代码写入文件并编译它们时,不需要双分号。引用 Daniil Baturin 的 What I wish I knew when learning OCaml ,
The answer to the question “When do I need the
;;
within OCaml source code?” is never.It's not a part of the language and is only used by the interpreter as an end of input mark.
;;
有以下论点:
The double semicolon in OCaml exists for historical reasons: the first parsers were driven by the tokens, not by the rules: all constructions needed to have a specific token.
But because of the introduction of modules in OCaml, the double semicolon, which was mandatory in Caml Light to end sentences, became optional: the reason is that in OCaml, a 'phrase' and a 'structure item' are actually the same notion. The problem is that the double semicolon is associated with the idea of 'terminating' something: for a phrase, it is exact, but not for a structure item inside a structure, since other structure items and the keyword 'end' follow.
That choice of letting the double semicolon be optional in normal syntax has introduced several problems:
A structure item is actually ended by the beginning of the next structure item; it means that all structure items must start with a keyword; otherwise there is an ambiguity. For example, you cannot write:
print_string "hello, world"
print_newline ()because it is interpreted as a call to print_string with 3 parameters (and typing error). The advocated solution is to write:
let _ = print_string "hello, world"
let _ = print_newline ()Mmm....
But this solution does not work interactively: in the toplevel, you cannot ask people to type the beginning of the next sentence to see the result of the current one. Therefore the double semicolon still remains! The property that we write in the toplevel like in source files has been lost.
In structures and objects, the fact that you don't end the structure items and object items make the programs more difficult to read. If you write a short object or structure item in one only line, it is very difficult to see where the items start and end.
My opinion is that the structure items should end with a token in a context where there is never need to read another token. This ensures a correct behavior in the interactive toplevel. The fact that the sequence is closed, in the revised syntax, frees the simple semicolon. And a simple semicolon is perfectly acceptable inside structures and objects, to end their item, the same way they close a record item. In the revised syntax, this ending semicolon is mandatory.
It is easier to treat a language whose all phrases end with a token: at end of the sentences, the characters and the tokens streams are synchronized (no need to read an extra token to be sure that the phrase is ended). This property can bring simplifications in other treatments (extraction of comments or code for documentation, indentation, editors modes, interactive tools).
[...]
关于ocaml - 为什么我可以添加任意数量的 ;到底在OCaml顶层就行了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51815342/
我正在开发一个需要多个窗口的程序,第一个出现的是登录窗口,我使用了 Toplevel 小部件以使其他窗口成为其子窗口,但这段代码一直显示两个窗口而不是一个。 from Tkinter import F
我不知道一般如何实现这一点,但为了清楚起见,我会特别询问一个实例: Sexplib 对我来说看起来很有趣。我想玩弄它。我已经下载了它,安装得很好(反正我很确定)等等。我想在顶层使用“with sexp
我在 makefile 中设置一个变量,如下所示: SOMEVAR = foo 此 makefile 稍后包含一些其他 makefile,在其中进行实际的程序构建: include generic/M
from tkinter import* import tkinter as tk def topLevel(): top=Toplevel() top.title("Listbox
我想查看乘法函数 (*) 的类型,因此我将其输入 OCaml 顶层。 # (*) 然而,顶层回应: (*);; 1: this is the start of a comment. 然后消耗我输入的任
我喜欢Try Ocaml的顶层行为:;; 在我按下 Enter 时隐式添加,并且我能够使用 Shift-Enter 进行多行编辑。 是否有可能在标准顶层或 utop 中获得相同的功能? 最佳答案 目前
我想知道,在 Ocaml 中,是否有部分输入信息。对于无法编译的程序,可以通过顶层/编译器的某些现有功能来绘制吗?让我解释。 在 Ocaml 中,众所周知,可以通过 -annot 文件检索推断类型。但
当我将分层 SVG 文件加载到 Illustrator 中时,所有图层都按其应有的方式工作,但它们始终位于新图层下;我没有指定“第 1 层”。 如何创建一个 SVG,使我的顶层最终也成为 Illust
我遇到了让我的 TreeView 填充已创建的顶层窗口的挑战,已尝试 fill=“x”和 fill=“both”,但没有得到结果。有任何建议这样做。 from tkinter import ttk i
标签在 div 中
我有以下布局: target target not target 我的问题是,如何定位所有顶级 标签(参见 target )使用 .fin
大家好,我有一个 div.mapFullscreenContainer #mapFullscreenContainer { position:fixed; top:0; lef
我有一个以编程方式创建的标签栏 Controller ,名为 TPastJourneyTabbar。当我单击 TableView 并调用 didSelectRowAtIndexPath: 时,我的选项
我是一名优秀的程序员,十分优秀!