Hi,
Richard Jones < rich%40annexia.org">rich
annexia.org> writes:
> Nice language extension and if I understand it correctly it's
> completely unambiguous with the original syntax, so it could be a
> candidate to be added to the base language ...
Thanks for the positive feedback.
Now I'm considering to combine it (pa_trybind [1]) with pa_use [2], since
they both deal with binding-level exception handling. For the moment,
they both use "with" as the keyword, if combined, we must devise
a different keyword for either of them.
I can't make up my mind on which keyword to use, so I need some
suggestions. To illustrate the concept, here is an example:
---
let read_a_file name =
let ch = open_in name [KWD] close_in with Sys_error _ -> [] in
read_lines ch
---
The second line is written in the (not yet decided) syntax --- we must
choose a keyword for the [KWD] part. We could reuse a predefined keyword
like "then" or "to", but this will probably introduce indent problem
with tuareg mode
---
let ch = open_in name then close_in with Sys_error _ -> [] in
let ch = open_in name to close_in with Sys_error _ -> [] in
---
or to occupy a new keyword like "before" "until" "finally" "later" "at_last"
etc., which is probably more readable and avoid the formatting problem.
---
let ch = open_in name before close_in with Sys_error _ -> [] in
let ch = open_in name until close_in with Sys_error _ -> [] in
let ch = open_in name finally close_in with Sys_error _ -> [] in
let ch = open_in name later close_in with Sys_error _ -> [] in
let ch = open_in name at_last close_in with Sys_error _ -> [] in
---
What do you think?
Moreover, there is another choice to make on the finalizer clause: it
can be a function (e.g. close_in) to be applied on the resource, or an
action itself e.g.
---
let ch = open_in name then close_in ch with Sys_error _ -> [] in
---
They are actually equivalent in expressiveness. The later seems more
verbose in general cases, but it can also be more concise in some other
cases:
* the resource parameter is not at the tail position of the finalizer
function
* the resource parameter is not a parameter of the finalizer function
at all
Any suggestions are welcome. Thanks in advance.
[1] http://www.pps.jussieu.fr/~li/software/index.html#pa_trybind
[2] http://www.pps.jussieu.fr/~li/software/index.html#pa_use
--
Zheng Li
http://www.pps.jussieu.fr/~li
.