views:

92

answers:

4

Some interactive systems, including Standard ML of New Jersey and GHC, offer an interactive toplevel loop where you can type expressions and see results. A nice little convenience is that the result of the most recent expression is bound to the variable it. Here's an example from GHCi:

Prelude> 3 + 5
8
Prelude> it
8
Prelude> 2 * it
16
Prelude> it + 1
17

I'm trying to trace the origin of this convention. Can anyone provide examples of other interactive systems that have used similar conventions? And date them if possible?

+1  A: 

Ruby provides the same convenience variable as _:

>> 3 + 5
=> 8
>> _
=> 8
>> 2 * _
=> 16
>> _ + 1
=> 17

Interestingly, the global variable $_ is also available: it's the last input read from gets or readline.

jtbandes
+1  A: 

Many common lisps use '*' to denote previous results. EG '*' is the last result, '**' is the result before last, etc:

* 5
5
* 6
6
* 7
7
* (+ * ** ***)
18

Python has '_' which is last result:

>>> 5
5
>>> _
5   

Erlang has a function 'v()':

1> 5.
5
2> 6.
6
3> 7.
7
4> v(1) + v(2) + v(3).
18
srparish
+1  A: 

Not a REPL, but hypertalk (the language of hypercard) allowed "it" in some contexts. I'm not sure of the exact usage case, as I never used hypercard, but it appears to be a similar idea. This dates it to 1986 or so.

ergosys
A: 

It seems that the first instance of a REPL with history list functionality was BBN LISP, ca. 1972.

"In BBN-LISP, each input typed by the user, and the value of the corresponding operation, are automatically stored by the p.a. on a global data structure called the history list." I could not find any documentation on how to actually access those values, only on how to repeat previous events using REDO. (See http://www.softwarepreservation.org/projects/LISP/interlisp/Teitelman-FCJJ1972.pdf)

Nor could I find any single keyword for accessing the last history value in its successor Interlisp, possibly due to lack of Google-Fu.

mwhite
Thanks; lots of tools have used a history list, including shells and debuggers. But asking some old LISPers would be good.
Norman Ramsey