Skip to content

Conversation

@sfkleach
Copy link
Member

@sfkleach sfkleach commented Jan 5, 2023

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.

@sfkleach sfkleach self-assigned this Jan 6, 2023
@sfkleach sfkleach added the enhancement New feature or request label Jan 6, 2023
@sfkleach sfkleach marked this pull request as ready for review January 6, 2023 10:13
@sfkleach
Copy link
Member Author

sfkleach commented Jan 6, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants