An alternative to (%%…%) (k times)how to print stack trace when TimeConstrained times outAlternative to...

Lighthouse Alternatives

Disable all sound permanently

Why do personal finance apps focus on outgoings rather than income

PhD Length: are shorter PhD degrees (from different countries) valued differently in other counter countries where PhD Is a longer process?

Duck, duck, gone!

How important is knowledge of trig identities for use in Calculus

Can an untrusted VPN client monitor my network activity?

The answer is a girl's name (my future granddaughter) - can anyone help?

GPLv3 forces us to make code available, but to who?

Sending mail to the Professor for PhD, after seeing his tweet

How to interpret the challenge rating of creatures?

Is there a way to remove Smite from a weapon?

Parent asking for money after moving out

Job interview by video at home and privacy concerns

What's the global, general word that stands for "center tone of a song"?

Why does `FindFit` fail so badly in this simple case?

How to level a picture frame hung on a single nail?

Avoiding dust scattering when you drill

Can anyone give me the reason why music is taught this way?

Could the Queen overturn the UK Supreme Court ruling regarding prorogation of Parliament?

What action is recommended if your accommodation refuses to let you leave without paying additional fees?

Are there types of animals that can't make the trip to space? (physiologically)

Why aren't faces sharp in my f/1.8 portraits even though I'm carefully using center-point autofocus?

Can I cast Death Ward on additional creatures without causing previous castings to end?



An alternative to (%%…%) (k times)


how to print stack trace when TimeConstrained times outAlternative to using global variables in functions?Alternative to NotebookLocate or NotebookFindManipulate executes expressions multiple timesNeed to run evaluation 2 timesWhy does `Times` evaluate within `Hold` when doing replacement?How to evaluate a notebook several times with distinct parameters?How do I make $0 times (mathsf{anything})=0$?How to Open, Evaluate and Close the same Notebook 100 times in a row?Evaluate calls my function multiple times when the function generates an error






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}
.everyonelovesstackoverflow{position:absolute;height:1px;width:1px;opacity:0;top:0;left:0;pointer-events:none;}








3












$begingroup$


Sometimes it may be useful to use (%%…%) (k times) to get the kth previous result in a notebook instead of setting a variable.



However, if I want to get the 8th previous result, for example, I would have to type (%) eight times (%%%%%%%%) and I could get lost. Needless to remember that every time (%) is needed (Shift)(5) must be pressed, which demands both hands and is somewhat inconvenient.



So, in the code below, I have defined a new command.



Now, when I want the previous 4th result I just type (o4) instead of (%%%%). If I wanted a previous result before the 9th, say the 14th, I would have to change the Range[9] in the command to Range[14] and generate (o1…o14). I could also obtain only the previous 3rd to the 7th values using Range[3, 7], getting (o3…o7).



This command should be run every time a new session of Mathematica is initiated. It could be written in an initialization cell in the notebook.
Remember that you should not redefine or clear (o1…o9) at the cost of getting unexpected errors. You must consider them as "system variables".



(* Define o1,o2,...,o9 as "%","%%",...,"%%%%%%%%%" *)
Map[ToExpression[StringJoin["o", ToString[#], " := ", "Out[$Line - ", ToString[#], "]"]] &, Range[9]];


Example:



Pi/6.
{Sin[%], Sin[o1]}
{Cos[%%], Cos[o2]}
{Tan[%%%], Tan[o3]}
{Sin[2 %%%%], Sin[2 o4]}
{Cos[2 %%%%%], Cos[2 o5]}
{Tan[2 %%%%%%], Tan[2 o6]}

0.523599
{0.5, 0.5}
{0.866025, 0.866025}
{0.57735, 0.57735}
{0.866025, 0.866025}
{0.5, 0.5}
{1.73205, 1.73205}









share|improve this question









$endgroup$










  • 5




    $begingroup$
    Just use Out. See the "Details" section.
    $endgroup$
    – Alan
    11 hours ago








  • 3




    $begingroup$
    As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
    $endgroup$
    – Michael E2
    11 hours ago












  • $begingroup$
    Maybe try With[ { foo = Pi/6 }, { {Sin[ foo ], Sin[ o1 ]}, ... } ] and use Column to arrange the output.
    $endgroup$
    – LouisB
    11 hours ago










  • $begingroup$
    Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
    $endgroup$
    – Caio
    9 hours ago




















3












$begingroup$


Sometimes it may be useful to use (%%…%) (k times) to get the kth previous result in a notebook instead of setting a variable.



However, if I want to get the 8th previous result, for example, I would have to type (%) eight times (%%%%%%%%) and I could get lost. Needless to remember that every time (%) is needed (Shift)(5) must be pressed, which demands both hands and is somewhat inconvenient.



So, in the code below, I have defined a new command.



Now, when I want the previous 4th result I just type (o4) instead of (%%%%). If I wanted a previous result before the 9th, say the 14th, I would have to change the Range[9] in the command to Range[14] and generate (o1…o14). I could also obtain only the previous 3rd to the 7th values using Range[3, 7], getting (o3…o7).



This command should be run every time a new session of Mathematica is initiated. It could be written in an initialization cell in the notebook.
Remember that you should not redefine or clear (o1…o9) at the cost of getting unexpected errors. You must consider them as "system variables".



(* Define o1,o2,...,o9 as "%","%%",...,"%%%%%%%%%" *)
Map[ToExpression[StringJoin["o", ToString[#], " := ", "Out[$Line - ", ToString[#], "]"]] &, Range[9]];


Example:



Pi/6.
{Sin[%], Sin[o1]}
{Cos[%%], Cos[o2]}
{Tan[%%%], Tan[o3]}
{Sin[2 %%%%], Sin[2 o4]}
{Cos[2 %%%%%], Cos[2 o5]}
{Tan[2 %%%%%%], Tan[2 o6]}

0.523599
{0.5, 0.5}
{0.866025, 0.866025}
{0.57735, 0.57735}
{0.866025, 0.866025}
{0.5, 0.5}
{1.73205, 1.73205}









share|improve this question









$endgroup$










  • 5




    $begingroup$
    Just use Out. See the "Details" section.
    $endgroup$
    – Alan
    11 hours ago








  • 3




    $begingroup$
    As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
    $endgroup$
    – Michael E2
    11 hours ago












  • $begingroup$
    Maybe try With[ { foo = Pi/6 }, { {Sin[ foo ], Sin[ o1 ]}, ... } ] and use Column to arrange the output.
    $endgroup$
    – LouisB
    11 hours ago










  • $begingroup$
    Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
    $endgroup$
    – Caio
    9 hours ago
















3












3








3





$begingroup$


Sometimes it may be useful to use (%%…%) (k times) to get the kth previous result in a notebook instead of setting a variable.



However, if I want to get the 8th previous result, for example, I would have to type (%) eight times (%%%%%%%%) and I could get lost. Needless to remember that every time (%) is needed (Shift)(5) must be pressed, which demands both hands and is somewhat inconvenient.



So, in the code below, I have defined a new command.



Now, when I want the previous 4th result I just type (o4) instead of (%%%%). If I wanted a previous result before the 9th, say the 14th, I would have to change the Range[9] in the command to Range[14] and generate (o1…o14). I could also obtain only the previous 3rd to the 7th values using Range[3, 7], getting (o3…o7).



This command should be run every time a new session of Mathematica is initiated. It could be written in an initialization cell in the notebook.
Remember that you should not redefine or clear (o1…o9) at the cost of getting unexpected errors. You must consider them as "system variables".



(* Define o1,o2,...,o9 as "%","%%",...,"%%%%%%%%%" *)
Map[ToExpression[StringJoin["o", ToString[#], " := ", "Out[$Line - ", ToString[#], "]"]] &, Range[9]];


Example:



Pi/6.
{Sin[%], Sin[o1]}
{Cos[%%], Cos[o2]}
{Tan[%%%], Tan[o3]}
{Sin[2 %%%%], Sin[2 o4]}
{Cos[2 %%%%%], Cos[2 o5]}
{Tan[2 %%%%%%], Tan[2 o6]}

0.523599
{0.5, 0.5}
{0.866025, 0.866025}
{0.57735, 0.57735}
{0.866025, 0.866025}
{0.5, 0.5}
{1.73205, 1.73205}









share|improve this question









$endgroup$




Sometimes it may be useful to use (%%…%) (k times) to get the kth previous result in a notebook instead of setting a variable.



However, if I want to get the 8th previous result, for example, I would have to type (%) eight times (%%%%%%%%) and I could get lost. Needless to remember that every time (%) is needed (Shift)(5) must be pressed, which demands both hands and is somewhat inconvenient.



So, in the code below, I have defined a new command.



Now, when I want the previous 4th result I just type (o4) instead of (%%%%). If I wanted a previous result before the 9th, say the 14th, I would have to change the Range[9] in the command to Range[14] and generate (o1…o14). I could also obtain only the previous 3rd to the 7th values using Range[3, 7], getting (o3…o7).



This command should be run every time a new session of Mathematica is initiated. It could be written in an initialization cell in the notebook.
Remember that you should not redefine or clear (o1…o9) at the cost of getting unexpected errors. You must consider them as "system variables".



(* Define o1,o2,...,o9 as "%","%%",...,"%%%%%%%%%" *)
Map[ToExpression[StringJoin["o", ToString[#], " := ", "Out[$Line - ", ToString[#], "]"]] &, Range[9]];


Example:



Pi/6.
{Sin[%], Sin[o1]}
{Cos[%%], Cos[o2]}
{Tan[%%%], Tan[o3]}
{Sin[2 %%%%], Sin[2 o4]}
{Cos[2 %%%%%], Cos[2 o5]}
{Tan[2 %%%%%%], Tan[2 o6]}

0.523599
{0.5, 0.5}
{0.866025, 0.866025}
{0.57735, 0.57735}
{0.866025, 0.866025}
{0.5, 0.5}
{1.73205, 1.73205}






evaluation notebooks editing






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 11 hours ago









CaioCaio

414 bronze badges




414 bronze badges











  • 5




    $begingroup$
    Just use Out. See the "Details" section.
    $endgroup$
    – Alan
    11 hours ago








  • 3




    $begingroup$
    As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
    $endgroup$
    – Michael E2
    11 hours ago












  • $begingroup$
    Maybe try With[ { foo = Pi/6 }, { {Sin[ foo ], Sin[ o1 ]}, ... } ] and use Column to arrange the output.
    $endgroup$
    – LouisB
    11 hours ago










  • $begingroup$
    Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
    $endgroup$
    – Caio
    9 hours ago
















  • 5




    $begingroup$
    Just use Out. See the "Details" section.
    $endgroup$
    – Alan
    11 hours ago








  • 3




    $begingroup$
    As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
    $endgroup$
    – Michael E2
    11 hours ago












  • $begingroup$
    Maybe try With[ { foo = Pi/6 }, { {Sin[ foo ], Sin[ o1 ]}, ... } ] and use Column to arrange the output.
    $endgroup$
    – LouisB
    11 hours ago










  • $begingroup$
    Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
    $endgroup$
    – Caio
    9 hours ago










5




5




$begingroup$
Just use Out. See the "Details" section.
$endgroup$
– Alan
11 hours ago






$begingroup$
Just use Out. See the "Details" section.
$endgroup$
– Alan
11 hours ago






3




3




$begingroup$
As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
$endgroup$
– Michael E2
11 hours ago






$begingroup$
As in Out[-5] (i.e., five lines ago). Though frankly, in such a situation, I would start with foo = Pi/6. and then use foo instead of % or Out.
$endgroup$
– Michael E2
11 hours ago














$begingroup$
Maybe try With[ { foo = Pi/6 }, { {Sin[ foo ], Sin[ o1 ]}, ... } ] and use Column to arrange the output.
$endgroup$
– LouisB
11 hours ago




$begingroup$
Maybe try With[ { foo = Pi/6 }, { {Sin[ foo ], Sin[ o1 ]}, ... } ] and use Column to arrange the output.
$endgroup$
– LouisB
11 hours ago












$begingroup$
Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
$endgroup$
– Caio
9 hours ago






$begingroup$
Out[-k] is not as convenient as the command presented. What I wanted to show is a simpler form of getting previous values writing only o1, o2 &c, with only 2 keystrokes instead of having to use 8 keystrokes every time I use Out[-k] or (k +1) keystrokes when I use (%).
$endgroup$
– Caio
9 hours ago












1 Answer
1






active

oldest

votes


















6














$begingroup$

% is just a shorthand for Out[-1] or even Out[]. And so on, Out[-k] gives the k-th previous result. Or from the details section of Out




Out[-k] is equivalent to %%...% (k times).




One way I've used Out, along with the way you can get multiple outputs by giving it a list of negative integers, before is testing timing and equality between different methods.



ClearSystemCache[]
Range[-10^6, 10^6]~Complement~{0} // AbsoluteTiming;
Join @@ {-Reverse@#, #} &@Range[10^6] // AbsoluteTiming;
Out[{-1, -2}][[;; , 1]]
SameQ @@ Out[{-1, -2} - 1][[;; , 2]]



{0.0201598, 0.0370587}



True




Or maybe a more clear example



a;
b;
Out[{-1, -2}]



{b, a}







share|improve this answer









$endgroup$

















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "387"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });















    draft saved

    draft discarded
















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206864%2fan-alternative-to-k-times%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    6














    $begingroup$

    % is just a shorthand for Out[-1] or even Out[]. And so on, Out[-k] gives the k-th previous result. Or from the details section of Out




    Out[-k] is equivalent to %%...% (k times).




    One way I've used Out, along with the way you can get multiple outputs by giving it a list of negative integers, before is testing timing and equality between different methods.



    ClearSystemCache[]
    Range[-10^6, 10^6]~Complement~{0} // AbsoluteTiming;
    Join @@ {-Reverse@#, #} &@Range[10^6] // AbsoluteTiming;
    Out[{-1, -2}][[;; , 1]]
    SameQ @@ Out[{-1, -2} - 1][[;; , 2]]



    {0.0201598, 0.0370587}



    True




    Or maybe a more clear example



    a;
    b;
    Out[{-1, -2}]



    {b, a}







    share|improve this answer









    $endgroup$




















      6














      $begingroup$

      % is just a shorthand for Out[-1] or even Out[]. And so on, Out[-k] gives the k-th previous result. Or from the details section of Out




      Out[-k] is equivalent to %%...% (k times).




      One way I've used Out, along with the way you can get multiple outputs by giving it a list of negative integers, before is testing timing and equality between different methods.



      ClearSystemCache[]
      Range[-10^6, 10^6]~Complement~{0} // AbsoluteTiming;
      Join @@ {-Reverse@#, #} &@Range[10^6] // AbsoluteTiming;
      Out[{-1, -2}][[;; , 1]]
      SameQ @@ Out[{-1, -2} - 1][[;; , 2]]



      {0.0201598, 0.0370587}



      True




      Or maybe a more clear example



      a;
      b;
      Out[{-1, -2}]



      {b, a}







      share|improve this answer









      $endgroup$


















        6














        6










        6







        $begingroup$

        % is just a shorthand for Out[-1] or even Out[]. And so on, Out[-k] gives the k-th previous result. Or from the details section of Out




        Out[-k] is equivalent to %%...% (k times).




        One way I've used Out, along with the way you can get multiple outputs by giving it a list of negative integers, before is testing timing and equality between different methods.



        ClearSystemCache[]
        Range[-10^6, 10^6]~Complement~{0} // AbsoluteTiming;
        Join @@ {-Reverse@#, #} &@Range[10^6] // AbsoluteTiming;
        Out[{-1, -2}][[;; , 1]]
        SameQ @@ Out[{-1, -2} - 1][[;; , 2]]



        {0.0201598, 0.0370587}



        True




        Or maybe a more clear example



        a;
        b;
        Out[{-1, -2}]



        {b, a}







        share|improve this answer









        $endgroup$



        % is just a shorthand for Out[-1] or even Out[]. And so on, Out[-k] gives the k-th previous result. Or from the details section of Out




        Out[-k] is equivalent to %%...% (k times).




        One way I've used Out, along with the way you can get multiple outputs by giving it a list of negative integers, before is testing timing and equality between different methods.



        ClearSystemCache[]
        Range[-10^6, 10^6]~Complement~{0} // AbsoluteTiming;
        Join @@ {-Reverse@#, #} &@Range[10^6] // AbsoluteTiming;
        Out[{-1, -2}][[;; , 1]]
        SameQ @@ Out[{-1, -2} - 1][[;; , 2]]



        {0.0201598, 0.0370587}



        True




        Or maybe a more clear example



        a;
        b;
        Out[{-1, -2}]



        {b, a}








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 11 hours ago









        That Gravity GuyThat Gravity Guy

        2,4011 gold badge6 silver badges15 bronze badges




        2,4011 gold badge6 silver badges15 bronze badges


































            draft saved

            draft discarded



















































            Thanks for contributing an answer to Mathematica Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f206864%2fan-alternative-to-k-times%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Ciclooctatetraenă Vezi și | Bibliografie | Meniu de navigare637866text4148569-500570979m