OCaml semicolon single expression in a for loop -
why there semicolon @ end of proc.num_stack_slots.(i) <- 0
in next code? thought semicolons separators in ocaml. can set optional semicolon lastly look of block?
for = 0 proc.num_register_classes - 1 proc.num_stack_slots.(i) <- 0; done;
see https://github.com/def-lkb/ocaml-tyr/blob/master/asmcomp/coloring.ml line 273 finish example.
there no need in semicolumn after expression, syntactic courtesy allowed here. in example, referenced, there semicolumn, because afterwards sec look follows.
essentially, can view semicolumn binary operator, takes 2 unit expressions, executes them left right , returns unit.
val (;): unit -> unit -> unit
then next illustration more understandable:
for = 1 5 printf "hello, "; printf "world\n" done
here ;
works glue. allowed set ;
after sec expression, syntactic sugar, nil more courtesy compiler developers.
if open parser definition of ocaml compiler see, look within seq_expr
can ended semicolumn:
seq_expr: | expr %prec below_semi { $1 } | expr semi { reloc_exp $1 } | expr semi seq_expr { mkexp(pexp_sequence($1, $3)) }
that means, can write such unusual code:
let x = 2 in x; allow y = 3 in y; 25
ocaml semicolon
No comments:
Post a Comment