【发布时间】:2012-09-12 00:26:39
【问题描述】:
我在 Developing Applications with OCaml 中关注这个 draw_string_in_box 示例
给出的示例代码如下:
let draw_string_in_box pos str bcf col =
let (w, h) = Graphics.text_size str in
let ty = bcf.y + (bcf.h-h)/2 in
( match pos with
Center -> Graphics.moveto (bcf.x + (bcf.w-w)/2) ty
| Right -> let tx = bcf.x + bcf.w - w - bcf.bw - 1 in
Graphics.moveto tx ty
| Left -> let tx = bcf.x + bcf.bw + 1 in Graphics.moveto tx ty );
Graphics.set_color col;
Graphics.draw_string str;;
如果我删除“匹配”部分周围的括号,则代码将不起作用(不会打印任何内容)。知道为什么吗?
更一般地说,我什么时候应该在这样的代码位周围加上括号?
谢谢。
【问题讨论】: