GetPoplog / Seed

Scripts for getting Poplog onto your Linux machine
MIT License
8 stars 3 forks source link

Implementation of kwargs #139

Open sfkleach opened 1 year ago

sfkleach commented 1 year ago

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 commented 1 year ago

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.