Ocaml printing one statement after another -
i new ocaml , ml in general , have been having fundamental issue. using pattern match , within 1 match print 2 or more concatenated statements. eg. chan^"("^var^")"^op2^(poc p); chan^"("^var^")"^op^(poc p)
let processoperatorchange2 t2s2 proc2 op op2= let rec poc2 p = match p | 0 -> "0" | pproc (x) -> string.lowercase x | in(chan, var, _, p, _) -> chan^"("^var^")"^op^(poc2 p); chan^"("^var^")"^op2^(poc2 p) in poc2 proc2 but each time run this, statement printed last 1 after semi colon. can this?
your function not print statement builds string, returns value, , doesn't perform side-effects. semicolon operator, when interspersed between 2 expressions, doesn't combine value produced these expressions, if have "hello"; "world" result "world". happens in case when do
chan^"("^var^")"^op^(poc2 p); chan^"("^var^")"^op2^(poc2 p) everything on lift thrown away.
a quick fix concatenate them, e.g.,
chan^"("^var^")"^op^(poc2 p) ^ ";\n" ^ chan^"("^var^")"^op2^(poc2 p) but in general, idiomatic way print ast use format module, , implement recursive pp function, has type format.formatter -> 'a -> unit. note return type, function doesn't build string (that operation of quadratic complexity), rather prints generic output stream.
Comments
Post a Comment