Previous Page Next Page Contents

history -- access an entry of the history table

Introduction

history(n) returns the nth entry of the history table.

history() returns the index of the most recent entry in the history table.

Call(s)

history(n)
history()

Parameters

n - a positive integer

Returns

history(n) returns a list with two elements, and history() returns a nonnegative integer.

Related Functions

fread, HISTORY, last, read

Details

Example 1

The index of the most recent entry in the history table increases by one for each entered command, also by history(). Note that every command is stored in the history table, whether its output is suppressed by a colon or not:

>> history(); sqrt(1764); history(): history()
                                     3
      
                                    42
      
                                     6

history(history()) returns a list with two elements. The first element is the last command, and the second element is the result returned by MuPAD, which is equal to last(1) or %:

>> int(2*x*exp(x^2), x);
   history(history()), last(1)
                                       2
                                  exp(x )
      
                                2            2         2
                  [int(2 x exp(x ), x), exp(x )], exp(x )

The following command returns the next to last command and its result:

>> history(history() - 1)
                                    2            2
                      [int(2 x exp(x ), x), exp(x )]

A restart cleans up the history table:

>> reset():
   history()
                                     4

The output of the command history() above depends on the number of commands in your MuPAD startup file userinit.mu.

Example 2

First a should be 0:

>> a := 0:
   a
                                     0

Now 1 is assigned to a:

>> a := 1:
   a
                                     1

The command history(history()-2) refers to the command a after assigning 0 to a, the return value of history is not the new value of a, because the result returned by history is not evaluated again:

>> history(history() - 2)
                                  [a, 0]

Example 3

The both commands leads to two entries in the history table. The command history(history()-1) returns only the last command b:=a, not both commands:

>> a := 0: b := a:
   history(history() - 1)
                               [(a := 0), 0]

If the commands are entered as an statement sequence (enclosed in ( )), they leads to one entry. history(history()) picks out the last command, that is the statement sequence:

>> (a := 0; b := a;):
   history(history())
                                [(a := 0;
                                b := a), 0]

The last input

>> type(op(%, 1))
                                "_stmtseq"

Changes




Do you have questions or comments?


Copyright © SciFace Software GmbH & Co. KG 2000