Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2010-03-31
17:31 • Closed ticket [2974744fff]: share exception codes (ObjType?) plus 6 other ch... artifact: a90b1ceb53 user: nijtmans
15:34 • Ticket [2974744fff]: 4 changes artifact: 0d65bd0aba user: dkf
14:04 • Ticket [2974744fff]: 4 changes artifact: e5583935dd user: nijtmans
13:46 • Ticket [2974744fff]: 4 changes artifact: 86939861b7 user: nijtmans
12:54 • Ticket [2974744fff]: 4 changes artifact: 9339ccd661 user: nijtmans
04:45 • Ticket [2974744fff]: 4 changes artifact: 9ad49a1feb user: dgp
04:15 • Open ticket [2974744fff]. artifact: 8b96e7a33e user: dkf
04:15 • Ticket [2974744fff]: 4 changes artifact: 5ff21b1fc8 user: dkf
2010-03-30
20:21 • Ticket [2974744fff]: 4 changes artifact: 05946a5fa4 user: nijtmans
2010-03-29
03:58 • Ticket [2974744fff]: 4 changes artifact: de60b55314 user: nijtmans
2010-03-28
09:13 • Ticket [2974744fff]: 4 changes artifact: cd1fc5496e user: dgp
05:40 • Closed ticket [2974744fff]. artifact: 034b9774ec user: nijtmans
05:28 • Ticket [2974744fff]: 7 changes artifact: 0d8ec20b9d user: nijtmans
2010-03-23
20:57 • Ticket [2974744fff]: 4 changes artifact: 9aaa7b7802 user: dkf
20:54 • Ticket [2974744fff]: 4 changes artifact: 457afcc399 user: nijtmans
20:51 • Ticket [2974744fff]: 4 changes artifact: eb22f931a6 user: nijtmans
20:51 • Add attachment tclResult.c.patch to ticket [2974744fffffffff|2974744fff... artifact: ec28841ce0 user: nijtmans
2010-03-22
18:26 • New ticket [2974744fff] share exception codes (ObjType?). artifact: a04df92daa user: dgp

share exception codes (ObjType?)

Closed / Fixed2974744fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2010-03-22 18:26:32
I see that the [try] implementation has a
table of Tcl's built-in exception code,
duplicating the table already in the
[return] implementation.  Might be
worth factoring this out.
nijtmansplain2010-03-23 20:51:35
File Added - 367871: tclResult.c.patch
nijtmansplain2010-03-23 20:54:15
Here is a first attempt at such a function. A separate ObjType is not very
useful, because the implementation is already covered by an integer
object and an index object. But a separate parse function (see patch)
could be useful to extensions as well.

Missing: documentation, integration with "try" command, addition to stub table.

Is this similar to wyat you had in mind?
dkfplain2010-03-23 20:57:43
Make it private to Tcl for now. Like that we don't need to document it or put it in any stub table. (We can expose later if we want, but not all "parse" functions are exposed IIRC.)
nijtmansplain2010-03-28 05:28:14
working on it
nijtmansplain2010-03-28 05:40:59
allow_comments - 1

Fixed in HEAD. Made it private function, as dkf suggested. Added
(trivial) integration with "try" command.
dgpplain2010-03-28 09:13:34
Thanks, I think that's a step in the
right direction.

The thought I had with ObjType was
along the lines of Tcl_GetBooleanFromObj(),
so that the string values "ok", "error", etc.
could hold the corresponding integer values
as their internal reps.  Not critical at all to do,
but possibly a further future enhancement.
nijtmansplain2010-03-29 03:58:46
Answer to dgp: I think that's the new function TclGetCompletionCodeFromObj already doing: It will convert the object to index type, which has indeed the integer value as its internal rep. There is no new object type needed for that, the index object type already does this. If the original string rep already is an integer, it will be converted to an integer object type. What more do you want? ;-)
nijtmansplain2010-03-30 20:21:26
Added one further optimization: If the object type is indexType
already, it makes no sense to check if it is an integer. This
is indeed more in line with Tcl_GetBooleanFromObj, which does
every effort not to do useless conversions. Moved the function
to tclIndexObj.c, so we can make use of indexType.
dkfplain2010-03-31 04:15:47
changes behaviour of [try]: now can't do this:
  try { ... } on err {} { puts Whoops! }
but instead need a full
  try { ... } on error {} { puts Whoops! }

Impacted Schelte Bron's code.
dkfplain2010-03-31 04:15:48
allow_comments - 0
dgpplain2010-03-31 04:45:08
I do *not* what [return -code] to start
accepting abbreviations.  If [try] needs
to do so, then I was mistaken about thinking
this was a good refactor.  Sorry.
nijtmansplain2010-03-31 12:54:41
So, why don't we give the new function a flag argument, which
describes whether we accept exact abreviations or not?
nijtmansplain2010-03-31 13:46:40
Thinking more about it: I agree with Donal,
and I recommend to keep it as is. Because:
- Tcl currently mainly accepts abbreviations in two cases:
      - option arguments starting with "-"
      - commands and ensemble subcommand,
        when in interactive mode
- If it was intended that try accepts abbeviations, there
  should have been a test case for it.
- Abbeviations only cause trouble when new return values
  are added: a new "error2" code whould start breaking
  Schelte Bron's code as well.
- TIP #329 mentiones:
The on handler allows exact matching against the exceptional return code (the integer value that would be returned by catch). The code may be given as an integer or one of the magic keywords ok (0), error (1), return (2), break (3), continue (4).
  it doesn't mention the possibility of abbreviations.
- Error codes are short, so I don't see much added
  value in allowing abbreviations.

Things to do:
- have a look at the current try documentation.
- add test case for [try], showing that use of
  abbreviations result in an error.
nijtmansplain2010-03-31 14:04:24
>Thinking more about it: I agree with Donal,
Of course, I meant Don!

The results show that this WAS a good
refactor:
- It discovered that the error messages
  used by the try command were not
  consistent with the return command.
- It discovered that the original try
  implementation did not match the TIP.
dkfplain2010-03-31 15:34:38
My code (I'm wholly responsible^Wto blame for the C implementation of [try]) accepted 'err' just because I couldn't be bothered to make it not do so. I'll have to apologize to Schelte for breaking his code, but it's for the best.

(And yes, more tests would be great.)
nijtmansplain2010-03-31 17:31:24
allow_comments - 1

- Checked documentation: It only handles exact matches, so it is consistent with the TIP
- Revised test cases, checking for the error case when using abbreviations.

So, this issue can be closed.
Log in (anonymous is fine) to add a comment.

Attachments: