.. _FunctionPointer: https://www.geeksforgeeks.org/function-pointer-in-c/ ******************************************************************************* PlantUML Stdlib Under The Hood 2 ******************************************************************************* .. _StdlibProposalCode: http://www.plantuml.com/plantuml/uml/j911YiCm34NtFiLV36ILP3ymCCnD54U93OhjiUI6thvk2hr1XK0WwIt--rMZQkqGDv08jDHeh8W914_6UwvtdBd9YeNxsajRURtklKMcqbbiKHXRhh10zkRSyFFnScxmbSaO_D_YZOIJ8M-8FYU5Xdmc1AwCO5RqUvxtQA4jay_7JASABVgSu_K_zWXZ4KgNa9SBVFsH-O07g_Ioyo1JW75ytwlm1l0TpcL9Mw052hJ0q6BC15xEC2q71XYCzwunCT5lP-BcMJpBVtv_aOHD4dvOQV_hd_vssEo7d3Orvi4vs_KTpXfaQstqMhCFvFgDnIIwMDgJD7eidlhZk_MNEs1PMDnt_qAv-ygQTPQU3NN6NOTJZzpQxmqtr0WdUeA23HKHlJvK16aV2IHugerhaIER7bu9MD8Nxrgw8Px1xUxOT7kfYFUMIAo6g-_g9m-vIoi0NghUDUZDB3YNmqLIGIde3r2vAoqtlsuDD_ciBAkIPVxYxTKuzVEYdV67OxSjQ4qFECASKTR0H0mu8pf8jDHjD0tfnZkBYdGupsYiaSwUOsTC61O4lLCjSEGiuvV2ivjzJzJl-eLfpcpimoLtUGdfQmf2rH-CmG2FlZ1BZzE-4Y2YmXGs_EvLbJaj5mNvfHyuLr9L6nq8b2t3SrokemahbplRt-iB2x7kN9NRoNPoVbFv0SYvCzqfYhANvg-Xq3nnbcajeuV4qvjchkf1rGmOxiUn6_1aiPzgVdTjj_Jo4ZsBDW5DwDo2C0lsSjFfRcy7vjPMw9tXzuWeC0v__oUr_ndHJzfzqn-SJ7C-_cJrDF-eJ_Zyr_ov_qzawhYCVpGM67nKNu4eEDUTp1wQA_bvROi9VxHCOw_nFPvk7u0kneKGECNc-hb3an7bUIF46YTF21OMDntlh08_nDsN5MJeAfj7SagE3Tln3POXC6PFZ_8Z2gszj_bn_pq4hj21CjPs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antuml.com/preprocessing#ajlk3nchu0zkka0ybjng .. _DefaultArgumentValue: https://plantuml.com/preprocessing#ae1b47605326b65f Step-by-step Towards A Standard Macro =============================================================================== .. uml:: ProcedureBuildup.puml :align: center :caption: *each output is numbered to match the procedure e.g. 51 is output for ffoo51()* .. literalinclude:: ProcedureBuildup.puml :linenos: Close But... =============================================================================== We can use the DefaultArgumentValue_ to avoid having to specify a parameter value when we call our procedure. BUT this only works if the default parameters are at the end i.e. it is all based on the order of the procedure parameters. *In other words, the user has to know/care about the order of parameters.* See :ref:`Standard Library - What We Have And What We Want`. To specify color blue I need to do ```$ffoo6("myaliasbatch2", "mydescription", "mylabel", "mytechnology", 2, blue)``` What I want to do ```$ffoo6($color=blue)``` or ```$ffoo6($scale=2)``` Procedure Keyword Arguments =============================================================================== To enable the StdLib standardisation, I suggested the *keyword arguments* and Arnaud produced a release to play with next day - and this became part of an official release: .. uml:: pre-processing.puml :align: center :caption: *each output is numbered to match the procedure e.g. 51 is output for ffoo51()* .. literalinclude:: pre-processing.puml :linenos: Extensibility =============================================================================== So now we have a way for the user to specify any or all of the sprite parameters. But what happens if we want to add new parameters in the future? Option 1: Reserve Parameters ------------------------------------------------------------------------------- One option is to reserve parameters in the procedure definition: .. code-block:: !unquoted procedure $SpriteDecorator($MySprite, $alias, $description="", $label="", $technology="", $scale=1, $colour="red", $res1="", $res2="", $res3="", $res4="") and used a function/procedure to map the new parameter feature to a reserved word. We're not smart enough to predict the future, and we don't want to impose limits, so we won't be doing this. Option 2: Dynamic Invocation ------------------------------------------------------------------------------- See :ref:`stdlibreqs-label` for requirements for stdlib. Let's define 3 SpriteDecorator Procedures that change the sprite parameters per :ref:`stdlibreqs-label`, where each procedure adds more parameters than the previous one. :: !unquoted procedure $SpriteDecorator($MySprite, $alias, $description="", $label="", $technology="", $scale=1, $colour="red") !unquoted procedure $SpriteDecorator2($MySprite, $alias, $description="", $label="", $technology="", $scale=1, $colour="green", $shape="node") !unquoted procedure $SpriteDecorator3($MySprite, $alias, $description="", $label="", $technology="", $scale=1, $colour="blue", $shape="cloud", $textsize="18") When we define the procedure for the user to call e.g. $BATCH_DYN, we specify which SpriteDecorator to be used via $dynN dynamic invocation. If at some point later, a new SpriteDecorator becomes available with same parameters but different processing, or with new parameters, then we can change this dynN to the new procedure. User code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parameters #. can use ordered list of parameters up to the one they want to specify. #. can use named arguments to specify only the parameter(s) they care about. Existing code does not need to know or care that the SpriteDecorator has changed. New code can use the new decorator functionality if desired. Play with StdlibProposalCode_ online. .. uml:: dynamic1.0.puml :align: center :caption: *decorators separated from sprite* .. literalinclude:: dynamic1.0.puml :linenos: :emphasize-lines: 37, 50, 63, 102, 106,110, 83, 86, 89