|
2010-02-21
| ||
| 06:34 | • Ticket [2927535fff] Retrieve last result in interactive mode status still Op... artifact: dfdf327a16 user: avl42 | |
|
2010-01-19
| ||
| 05:21 | • Ticket [2927535fff]: 4 changes artifact: 0df9281754 user: hobbs | |
| 04:53 | • Ticket [2927535fff]: 4 changes artifact: e9c03f4cac user: avl42 | |
| 02:59 | • Ticket [2927535fff]: 4 changes artifact: c2fb744528 user: ferrieux | |
| 02:54 | • Ticket [2927535fff]: 4 changes artifact: 0af2b6b783 user: ferrieux | |
| 02:54 | • Ticket [2927535fff]: 4 changes artifact: 69d020ebfa user: ferrieux | |
| 02:54 | • Add attachment histresult.patch to ticket [2927535fff] artifact: 87131617aa user: ferrieux | |
| 02:40 | • Ticket [2927535fff] Retrieve last result in interactive mode status still Op... artifact: 348665b0f4 user: avl42 | |
| 02:22 | • Ticket [2927535fff]: 4 changes artifact: 5745223e4c user: avl42 | |
| 02:20 | • Ticket [2927535fff]: 4 changes artifact: 7d2bff4842 user: avl42 | |
|
2010-01-08
| ||
| 21:07 | • Ticket [2927535fff]: 4 changes artifact: f964497626 user: ferrieux | |
| 21:06 | • Ticket [2927535fff]: 4 changes artifact: 978a29f9d1 user: ferrieux | |
| 18:20 | • Ticket [2927535fff]: 4 changes artifact: c1b3653deb user: avl42 | |
|
2010-01-07
| ||
| 21:50 | • Ticket [2927535fff]: 4 changes artifact: e36387226c user: ferrieux | |
| 21:35 | • Ticket [2927535fff]: 6 changes artifact: c8e659be3e user: dkf | |
| 20:58 | • Ticket [2927535fff]: 4 changes artifact: a7cde35464 user: ferrieux | |
| 20:56 | • Add attachment lastresult.patch to ticket [2927535fff] artifact: 1b0cb3ea18 user: ferrieux | |
| 20:56 | • Ticket [2927535fff] Retrieve last result in interactive mode status still Op... artifact: 158f0b7576 user: ferrieux | |
| 13:55 | • New ticket [2927535fff]. artifact: ce106d23c5 user: ferrieux | |
Retrieve last result in interactive mode
Open2927535fffffffffffffffffffffffffffffffffCreated 17 years agoUpdated 17 years ago
Descriptionplain2010-01-07 13:55:13
As suggested on comp.lang.tcl: http://groups.google.com/group/comp.lang.tcl/browse_frm/thread/c78f6d63471cccb7/5ddedc4e11bfa754#5ddedc4e11bfa754 it could be nice to be able to retrieve the last interactive command's result or error, for debugging purposes in situations where things are not easily reproducible. A simple API would be a [::tcl::lastresult] command.
ferrieuxplain2010-01-07 20:56:37
File Added - 358030: lastresult.patch
ferrieuxplain2010-01-07 20:58:47
The attached patch does just that. Implementation: it saves the interp's result object in the assoc area. Note that it is done at object level, not string, so that large values are efficiently handled. It does prorogate the life of the result object until the end of the next interactive command, but that's the price to pay while time machines are not affordable.
dkfplain2010-01-07 21:35:10
The Standard ML language uses the global 'it' variable for the same purpose. Note also that these should be considered to be features of tclsh/wish and not the Tcl language.
ferrieuxplain2010-01-07 21:50:17
If you're suggesting an alternative API please voice it clearly. The patch is confined to tclMain.c and tclHistory.c which are parts of tclsh, and done so that non-interactive execution isn't penalized. Any form of criticism welcome here; I'm not too eager to TIP that now, given the current pipeline of unvoted TIP / uncommitted patches that I have :/
avl42plain2010-01-08 18:20:52
I agree to dkf, that a short-named global variable would be nicer. (my preference would be for "$_") A command (especially in ::tcl namespace) may misguide people into believing that it was a tcl-feature rather than one of tclsh. (I'm not aware of any tclsh-specific commands so far, but argv and argv0 are already precedents for tclsh's own preinitialized variables.) No magic is necessary for that variable apart from that it is overwritten after each eval'ed command. e.g. puts "[set _ 42] $_" would print twice 42, and afterwards $_ would be empty for puts' result. Thanks for taking the effort in the first place! It's appreciated!
ferrieuxplain2010-01-08 21:06:39
Acknowledging the remark about language vs. interpreter, I refactored the patch so that it now uses a call-back (rather than call-forward) API in history.tcl.
So the external API for retrieval is now [history lastresult], and the only affected files are: tclHistory.c and history.{tcl,test,n}.(Yes it is complete with test and doc).
As for the final, easy-to-type shortcut, I'm a bit uneasy about hijacking a toplevel variable like $::_ or $::it for obvious compatibility reasons (though again it only touches interactive sessions). A TIP is needed for _that_, while I guess it is not for the current patch.
Please review.
ferrieuxplain2010-01-08 21:07:32
File Added - 358197: histresult.patch
avl42plain2010-01-19 02:20:32
A small tidbid: a typo in the second manpage-addings: "... [history lastesult]." ("r" missing)
And a suggestion for $_: in interactive mode, make a read-trace on variable "_" to overwrite the variable with [history lastresult].
Eventually make a write-trace too, that just turns off both of these traces, (unless called from the read-trace), so if anything else sets "_" it won't get overwritten anymore.
avl42plain2010-01-19 02:22:25
PS: I definitely prefer the second patch to the first one - big "thank you" again.
avl42plain2010-01-19 02:40:44
I meant the second one that you added. "histresult.patch" - It makes it clear, that this is not for scripts (except of course if they do their own command-loop with history).
ferrieuxplain2010-01-19 02:54:36
File Added - 359387: histresult.patch
ferrieuxplain2010-01-19 02:54:51
File Deleted - 358197:
ferrieuxplain2010-01-19 02:59:50
Typo fixed, thanks.
For the traces I don't know. It feels complicated and generates extra references (you'll see them with [rep] ;-). A simpler method is to rewrite the script-level callback [hist result]: proc ::tcl::HistResult x {set ::_ $x}. Of course this breaks [hist result] but doesn't introduce lingering references...
avl42plain2010-01-19 04:53:54
Thanks to the brilliant design, it's as simple as: upvar #0 ::tcl::history(lastcommand) _ My suggestion of traces was to not get in user's way were he to use "_" himself.
hobbsplain2010-01-19 05:21:24
FWIW, tkcon also uses $::_ for the last result.
avl42plain2010-02-21 06:34:44
Now, how's it going on? What's this patch's possible route into the core? TIP?
Log in (anonymous is fine) to add a comment.
Attachments:
- histresult.patch [download] added by ferrieux on 2010-01-19 02:54:36. [details]
- lastresult.patch [download] added by ferrieux on 2010-01-07 20:56:37. [details]