Menu

#19 wrapping dynamic gotos into exceptions

open
nobody
5
2006-03-26
2006-03-26
No

Good morning,

according to the documents, (currently in en_flx_tutorial_0045.html
from cvs), exceptions can be simulated via dynamic gotos. What do you
all think about wrapping this pattern with the classis "try ... with"?

so something like this:

union string_option =
| Some of string
| None
;

proc raiser
{
raise 1;
raise Some "string";
raise None;
}

proc main
{
try raiser() with
| ?i:int => {print "int="; print i; endl}
| Some ?s => {print "Some="; print s; endl}
| None => {print "None"; endl}
endmatch;

print "done"; endl;
}

is just sugar for this:

proc raiser (err1: int->void, err2: string_option->void)
{
err1 1;
err2 (Some "string");
err2 None;
}

proc main
{
proc err1(i:int)
{
print "int="; print i; endl;
goto resume;
}

proc err2(s:string_option)
{
match s with
| Some ?s => print "Some="; print s; endl;
| None => print "None"; endl;
goto resume;
}

raiser(err1, err2)
resume:>
print "done"; endl;
}
main;

of course, this means that every exception must be handled at the call
site, but it would be a nice stop-gap until if/when full exceptions are
supported. Can a macro handle this translation, or would it require
lexer/parser changes?

-e

Discussion


Log in to post a comment.