[NTG-context] How to let a macro check the previous value of #1 the last time the same macro was called?

Joel uaru99 at yahoo.com
Sun Jan 9 15:16:37 CET 2022


Is there a way for a macro to check the previous value of #1, the last time that same macro was called?

Here is a minimum working example, pretending that `\previousvalue` is equal to #1 from the last time the same macro was called:

    \define[1]\mymacro{
        \if\previousvalue=#1
        same as last time
    \else
        it is different from last time
    \fi
    }

\starttext

    \mymacro{cat}
    \mymacro{cat}
    \mymacro{mouse}
    \mymacro{mouse}
    \mymacro{cat}

\stoptext

This would print:

    it is different from last time <--it was never called previously
    same as last time
    it is different from last time
    same as last time
    it is different from last time

--Joel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ntg.nl/pipermail/ntg-context/attachments/20220109/bc12b74b/attachment.htm>


More information about the ntg-context mailing list