-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
request: automatic macro for reporting current function definition in error messages #1
Comments
Hi, As I am planning to use this macro for adding more info into log messages, Just the current function name would be useful and really reproduce the Regards, |
There is no systematic and unambiguous "current function name" in OCaml. We have to find something useful that corresponds to the same usage pattern. In particular, what should we do with the following cases: (* no function definition *)
let x = y + 1
(* is this a function definition? *)
let print = output_string stdout
(* which function to report? *)
let tail_from x l =
let rec aux = function
[] -> []
| x' :: tl as l -> if x = x' then l else aux tl
in
aux l |
I start to understand that implementing this is not trivial. (* is this a function definition? *) (* which function to report? *) I hope experts at parsing OCaml source code will |
There is no way of distinguishing between cases (1) and (2) from the syntax only. In case (3), the innermost function name is "aux" which like "x" is used all over the place. I don't think it would be very helpful to report just that. |
mjambon said: "There is no way of distinguishing between cases (1) and (2) from the syntax only." For case 3, I also agree, maybe the function name should be reported as: |
Cppo was designed as an OCaml-compatible preprocessor strongly reminiscent of the C preprocessor. It does not know the grammar of OCaml, not even the list of reserved keywords. Reporting the "indentation stack" may be worth exploring and doesn't need to be aware of the syntax of OCaml. Given the following code: (* which function to report? *)
let tail_from x l =
let z = 1 + 1 in
let rec aux = function
[] -> []
| x' :: tl as l -> if x = x' then l else aux tl
in
aux l An error on the "if-then-else" line could report the following:
Note that I think that the goal of making an error message fit on a single line and the goal of making the same error message clearer are conflicting. If your log format requires one error message to fit a single line, just escape the LF characters and use another tool to read the log and display the error messages using as many lines are needed for readability. |
I agree with the conflict on having one-line messages and their understandability. |
The request is about providing something like
__FUNCTION__
in cpp but applicable to OCaml, whose purpose would be to provide better error messages by indicating the function or logical section of the program where an error occurs.I suggested
__CONTEXT__
, an automatic macro that would contain the last contiguous sequence of non-empty, non-indented lines.The text was updated successfully, but these errors were encountered: