Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

command for last answer

3 views
Skip to first unread message

ifbob

unread,
Jan 6, 2010, 2:36:21 PM1/6/10
to
Good evening.
I work on Windows XP and TCL 8.5.8.
I would know if they are commands for retrieving the last answer and
(if possible) the other previous answers
Thank you very much and best regards.

Donald Arseneau

unread,
Jan 6, 2010, 3:45:33 PM1/6/10
to
On Jan 6, 11:36 am, ifbob <7if...@gmail.com> wrote:
> I work on Windows XP and TCL 8.5.8.
> I would know if they are commands for retrieving the last answer

expr 42


Joking aside, what is this "last answer" you speak of?

Donald Arseneau

Donal K. Fellows

unread,
Jan 6, 2010, 4:17:51 PM1/6/10
to
On 06/01/2010 19:36, ifbob wrote:
> I work on Windows XP and TCL 8.5.8.
> I would know if they are commands for retrieving the last answer and
> (if possible) the other previous answers

There's no command (or variable) to retrieve preceding results, unless
you adapt the interpreter loop code in Tcl (or Tk) to provide one.
Usually it's best to just remember to save it (with [set]) the first
time round, though that's sometimes a little late...

Donal.

Don Porter

unread,
Jan 6, 2010, 4:26:47 PM1/6/10
to
Donal K. Fellows wrote:
> On 06/01/2010 19:36, ifbob wrote:
>> I work on Windows XP and TCL 8.5.8.
>> I would know if they are commands for retrieving the last answer and
>> (if possible) the other previous answers
>
> There's no command (or variable) to retrieve preceding results, ...

True, but see [history].

--
| Don Porter Mathematical and Computational Sciences Division |
| donald...@nist.gov Information Technology Laboratory |
| http://math.nist.gov/~DPorter/ NIST |
|______________________________________________________________________|

Andreas Leitgeb

unread,
Jan 7, 2010, 5:54:45 AM1/7/10
to

I think, the question wasn't all that cryptic.

e.g.:

expr 42
puts "The answer is: [last_result]" (or $last_result)

I admit, I have had that wish, too.

But on the down-side:
- adding a command (even just for logging) between such two lines
will break the script "surprisingly"
- it's just cosmetics
- it might slow down apps, if the interpreter needs to save back
all return values for the eventual later use.

In interactive mode, it might be a worthy feature, though, and
could be implemented as a variable, that gets assigned the result
before or after it is printed out. That's a completely different
thing, in that only each line's result is saved, not each command's.

Alexandre Ferrieux

unread,
Jan 7, 2010, 9:02:30 AM1/7/10
to
On Jan 6, 10:17 pm, "Donal K. Fellows"

For those interested in that feature, I just wrote patch 2927535,
adding a [::tcl::lastresult] command:

https://sourceforge.net/tracker/?func=detail&aid=2927535&group_id=10894&atid=310894

-Alex


Alexandre Ferrieux

unread,
Jan 8, 2010, 9:45:03 AM1/8/10
to
On Jan 6, 10:26 pm, Don Porter <d...@nist.gov> wrote:
> Donal K. Fellows wrote:
> > On 06/01/2010 19:36, ifbob wrote:
> >> I work on Windows XP and TCL 8.5.8.
> >> I would know if they are commands for retrieving the last answer and
> >> (if possible) the other previous answers
>
> > There's no command (or variable) to retrieve preceding results, ...
>
> True, but see [history].

Patch 2927535 adds [history lastresult] in an (hopefully) idiomatic
way, please review.

-Alex

keithv

unread,
Jan 8, 2010, 10:49:03 AM1/8/10
to

tkcon has the magic variable $_ which holds the result of
the last command in the console window.

Keith

Andreas Leitgeb

unread,
Feb 9, 2010, 8:08:15 AM2/9/10
to
Alexandre Ferrieux <alexandre...@gmail.com> wrote:
> For those interested in that feature, I just wrote patch 2927535, ...
> https://sourceforge.net/tracker/?func=detail&aid=2927535&group_id=10894&atid=310894

It's a while since this announcement, and a second (much better) patch
was added by Alex early January: histresult.patch

The nice thing about that one patch is, that it concentrates on
the existing history-mechanism, and just adds the last result
to where one would expect such a feature. Also, the last result
itself is saved as an array-element ::tcl::history(lastcommand)
and can trivially be linked to $_ as per user's .tclshrc: just
add "upvar #0 ::tcl::history(lastcommand) _"

Now, my question: what's the future? Will it require a TIP? Is
it a sufficiently local simple change that it can get through
as a fix for a longstanding omission?

I surely wouldn't want it to be just forgotten about (except for
those few "freaks" who regularly compile their own tclsh just for
the patch)

PS: the upvar-line could then be mentioned as a hint in the
history's manpage.

0 new messages