parrotcode: Untitled | |
Contents | Language Implementations | TCL |
Prodding by Matt Diephouse to generate documentation for two things:
It is, of course, quite likely that said feature already exists with a nice interface, and was just not found by the partcl developers - If you find something along these lines, let them know.
% proc sum {{a 2} {b 3}} {
return [expr $a + $b]
}
% sum
5
% info args sum
a b
% info body sum
return [expr $a + $b]
% info default sum a the_argument
1
% puts $the_argument
2
%
% sum a b c
wrong # args: should be "sum ?a? ?b?"
Tcl kind of conflates normal returns and exceptional returns, and uses the same mechanism for [break]ing and [continue]'ing out of loops.
Right now, this is being handled by returning *two* values from each publicly exposed function. (And from several internal ones, as well.) The first is the code, that is, an integer, which is a faked up enum of:
TCL_OK, TCL_ERROR, TCL_BREAK, TCL_CONTINUE, TCL_RETURN
Then, the actual interesting value is returned as as a PMC. How do we tie in the two happy return cases, the two cases that interact with loops, and the error case into parrot's normal return/exception handler in a way that works for tcl and will allow interoperability
Note: The reason we're not using parrot exceptions is that we're unable at the moment to redefine them ourselves - I don't see any easy way to get the nice stacktraces that tcl gives you using the parrot exception handling mechanism. So we could potentially use exceptions for TCL_ERROR in the long term. But then [catch] will need to be re-written to cope with exceptions or not (as opposed to now, where all codes are equal).
Cheating and keeping a global around right now, so we can figure out if we should be using a global or a lexical (and if so, how far down or up).
There are two ways we can go about the tracing - either we can keep the information about the traces in a global, and check that global every time the appropriate action is taken; or, we can tie that information into the actual commands and variables. I think the latter would be somewhat cleaner, and, if any other languages support this feature, this would give us a chance to interoperate.
Hey! The above document had some coding errors, which are explained below:
|