This is an initial version of keyword arguments for Pop-11. The objective is to create an easy-to understand, reasonably efficient, reasonably robust mechanism for defining functions with optional arguments. This feature is very helpful in designing clean interfaces and I am looking to make use of it in cleaning up some of the tech-debt I created with the findhelp subcommand.
The strategy I have utilized is to pass optional arguments in a distinctive "pile" of paired keyword and value items that look like this:
BOTTOM, K1, V1, ... Kn, Vn, TOP
Note that TOP & BOTTOM are unique values that are dedicated to marking kwarg-piles. This design makes popping values in the callee reasonably quick when the paired arguments are unique and ordered and the syntax-words all enforce that ordering and non-duplication. This design leads to relatively compact code whilst also coping with situations such as the arguments being duplicated and out of order.
Aside: The main weak point of this design is that it is potentially fragile when dealing with buggy code that steals arguments.
The weakness of this PR is the lack of unit tests. I had reservations over the unit test code I wrote last year though. So for the moment I am just moving forward anyway.
This is an initial version of keyword arguments for Pop-11. The objective is to create an easy-to understand, reasonably efficient, reasonably robust mechanism for defining functions with optional arguments. This feature is very helpful in designing clean interfaces and I am looking to make use of it in cleaning up some of the tech-debt I created with the findhelp subcommand.
The strategy I have utilized is to pass optional arguments in a distinctive "pile" of paired keyword and value items that look like this:
Note that TOP & BOTTOM are unique values that are dedicated to marking kwarg-piles. This design makes popping values in the callee reasonably quick when the paired arguments are unique and ordered and the syntax-words all enforce that ordering and non-duplication. This design leads to relatively compact code whilst also coping with situations such as the arguments being duplicated and out of order.
Aside: The main weak point of this design is that it is potentially fragile when dealing with buggy code that steals arguments.