开发者

Language history: origin of variable 'it' in read-eval-print loop?

开发者 https://www.devze.com 2023-01-09 05:33 出处:网络
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

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 the开发者_StackOverflow中文版m if possible?


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.


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消