What happened to `it`?

I’m curious about the historic reason for dropping or not porting sml’s it variable in o/caml’s toplevel. At least as far back as 2003 we had the it in sml, maybe people who were programming then can tell me if it was there even before that… seeing that the oldest sml systems are almost 40(?) now.

2 Likes

I don’t believe ocaml itself offers anything like this, but utop does. When started with the -implicit-bindings option, it will bind each expression’s value to _N, where N is the expression number starting with 0. This is similar to the numbered values in Clojure and iPython, though it’s nice that utop’s implementation isn’t limited to three or four entries.

For example, while using utop via dune (with a project of mine that has a src/rsrc source directory):

$ dune utop src/rsrc -- -implicit-bindings
─┬──────────────────────────────────────────────────────────────┬──
 │ Welcome to utop version 2.10.0 (using OCaml version 4.13.1)! │  
 └──────────────────────────────────────────────────────────────┘  

Type #utop_help for help about using utop.

─( 21:46:58 )─< command 0 >─────────────────────────{ counter: 0 }─
utop # "a" ^ "b";;
val _0 : string = "ab"
─( 21:46:58 )─< command 1 >─────────────────────────{ counter: 0 }─
utop # 5 + 5;;
val _1 : int = 10
─( 21:47:07 )─< command 2 >─────────────────────────{ counter: 0 }─
utop # _1;;
val _2 : int = 10
─( 21:47:11 )─< command 3 >─────────────────────────{ counter: 0 }─
utop # _0;;
val _3 : string = "ab"

(This feature was implemented via Bind expressions to _0, _1, etc. by copy · Pull Request #200 · ocaml-community/utop · GitHub, which contains some related discussion of other related options that you might find useful.)

Hope that helps!

4 Likes

thanks, although I’m more interested in the history of ocaml’s development itself and learning about the reasons behind some of its diversions from sml, til on utop. it’s nice to know they have it, even if behind a switch.

1 Like