From when I first started using batch I've always been saving tricks and optimizing functions.
When we write a function we don't just want it to return the result.
We want it to return the result correctly, whether the function was called with delayed expansion enabled or disabled.
So to prevent repetitive code I wrote a function that would inspect the original environment's delayed state and then adjust the variables accordingly and push them over endlocal.
So at a certain point in time I had written about 300 functions.
And many functions would delegate to other functions which involved many calls and large sections of code would have to be plowed through to find the correct label.
This became unworkable, I thought about saving each function in it's own separate file, but I never did.
I knew it was possible to save primitive tasks in a variable, how to execute it, and that it is much faster to execute a variable ( there is no call ).
Variables that can be called like functions are called macros.
A big breakthrough was when I figured out a way to pass arguments to this variable and have it be able to change it's behavior depending on the arguments.
I now had something similar to a function but inside a variable.
I started converting all functions that were called very often and would fit within 8191 bytes.
These macros all needed to be loaded, and I did not want to force the caller to use a specific delayed state.
When I write a macro I often want to delegate to other functions and thus need to swith delayed expansion.
So now I needed to push the entire variable over endlocal back to the caller's environment.
This process is so cpu intensive that at a certain point it would take minutes to load and push everything over endlocal.
This became unworkable, the need raised to selectively load the function I actually was going to use.
Rewriting it like this saved me some time but still it was all too slow.
I decided to dump all these variables from the memory to files.
One folder for files that were prepared to be loaded with delayed expansion disabled and one folder for enabled.
I then wrote a batch file that if it was called would not set the delayed state but figure out the caller's delayed state to figure out which dumps to call.
I then decided to organize these functions and am currently working out the concept.
So this could become the start of some batch program:
Code: Select all
echo off &set "@include=call %%~dp0\doskit\includer.CMD"
( %@include% %= load the includer =% )
( %@include_% "thread\singleton_" )
( %@include_% "function\*" )
( %@include_% "system\*" )
:main
:: (
( %while_% singleton_ )
( %necho_% The program has been serialized. )
:: )
( %exit_% §e )
To get a list of available commands or help on a specific command you can use the interactive help by opening a cmd prompt where the library is and type: 'man'.
This help may in the future also be available and provided as html pages.
I can choose to build the project which replaces the includes with the code all into a single file.
You like the idea, the concept ?