Re: External commands into history buffer

*To*: mathgroup at yoda.physics.unc.edu*Subject*: Re: External commands into history buffer*From*: twj*Date*: Thu, 19 Nov 92 10:20:53 CST

>As far as I am concerned I would prefer to have all the commands >read in from the external file included in the internal history buffer. >This would allow an easy reference to or editing of the read in commads >without a proliferation of fractions of original command file if one >does not want to edit and run it as a whole again and again. I did not >have a look into this yet but if somebody did I would appreciate any >suggestions, comments, etc. Remember that the history "buffer" is just a collection of Mathematica expressions. You can alter it with whatever Mathematica commands you wish. For example you can make a version of Get which will update In and Out: GetHistory[ file_String] := Block[{ coms, first}, coms = ReadList[ file, Hold[ Expression]] ; first = $Line ; Unprotect[ In, Out] ; coms = Last[ Map[ GetHistoryAux, coms]] ; Out[ first] = coms ; Protect[ In, Out] ; coms ] GetHistoryAux[ com_] := Block[{res}, $Line++ ; com /. Hold[ x_] :> SetDelayed[ In[ $Line], x] ; res = ReleaseHold[ com] ; Set[ Out[ $Line], res] ; res ] In[7]:= !!test1 (1 + 5 ) Integrate[ f[x], {x, 0, Infinity}] In[7]:= GetHistory[ "test1"] Out[9]= Integrate[f[x], {x, 0, Infinity}] In[10]:= %% Out[10]= 6 Tom Wickham-Jones WRI