tagged release 0.6.4
[parrot.git] / languages / tcl / docs / hacks.pod
blobe6ac82a3b1426a3761b028bfb927a9b5e82288ff
1 =head1 hacks.pod
3 =head1 WORKAROUNDS
5 Things that partcl has done that might be considered hacks -
6 things that will likely impair our ability in the distant future to
7 cleanly do language interoperability.
9 =over 4
11 =item PDD20 - lexical vars
13 The current scheme (PDD20) for lexical vars means that to be able use the
14 'store_lex', and 'find_lex' opcodes, you have to be inside a sub that's
15 marked C<:lex>: That is, inside a sub that corresponds to a HLL block that
16 introduces a new lexical scope. Tcl uses helper functions to figure out
17 whether a particular '$a' is referring to a global or a lexical var. We
18 keep track of the lexpads in the 'call_chain' variable and manually
19 look up lexicals in the lexpads.
21 =item subroutine meta information.
23 Tcl provides the ability to query subroutines about their arguments
24 and their code. For example:
26  % proc sum {{a 2} {b 3}} {
27   return [expr $a + $b]
28  }
29  % sum
30  5
31  % info args sum
32  a b
33  % info body sum
35   return [expr $a + $b]
37  % info default sum a the_argument
38  1
39  % puts $the_argument
40  2
41  %
43 Right now, partcl is using globals to store the argument list and the
44 body information. It would seem that we'd want to have a builtin mechanism
45 for querying the subs directly rather than storing this information separately.
47 =item user defined subs; parameter handling.
49 Tcl provides nice exceptions for dealing with argument handling - to continue
50 our example:
52  % sum a b c
53  wrong # args: should be "sum ?a? ?b?"
55 Right now, this is handled I<inside> the function definition - it is defined
56 to take an arbitary number of args, and then is checked for correctness
57 internally. It would be nice to have invoke() automatically figure this out
58 and generate an exception that Tcl can use. (This also starts to drag in
59 "how to do Tcl exceptions cleanly from parrot")
61 =item stack depth
63 Cheating and keeping a global around right now, so we can figure out if we
64 should be using a global or a lexical (and if so, how far down or up).
66 =item [trace]'ing
68 There are two ways we can go about the tracing - either we can keep the
69 information about the traces in a global, and check that global every time
70 the appropriate action is taken; or, we can tie that information into the
71 actual commands and variables. I think the latter would be somewhat cleaner,
72 and, if any other languages support this feature, this would give us a chance
73 to interoperate.
75 =item flush diagnostics
77 At the moment, there doesn't seem to be a parrot method for determining if
78 a filehandle was opened for reading/writing. We can work around this by
79 tracking it in a hash in the _Tcl namespace.
81 =back
83 =cut