top | item 20387634

(no title)

mclehman | 6 years ago

Thanks, I'll definitely keep it in mind.

MAIN is probably what I should point to as P6's killer feature for things of this scope. I tend to get sidetracked by math/functional features when I demo things even though stuff like this is a bit more practical and likely to get traction.

I just got around to cleaning up that tmux wrapper I mentioned above (https://gitlab.com/0xFORDCOMMA/sessions) and that might be worth writing something about. It's a miniscule project, but I think it highlights a lot of useful features.

One result of that clean-up that relates to this is the new usage output. It's still automatically generated [1], but adding purpose annotations to the multi-dispatch MAINs in `session` and using a P6 enum as a type constraint in the MAIN in `sessions` resulted in what I consider quite useful documentation pretty much for free.

    λ | -> session --usage
    Usage:
      session -- Create or enter default session 'misc/dev'.
      session <category> <session> -- Create or enter session '<category>/<session>'.
      session <session> -- Search all categories for matching session, switch to result if unique.

    λ | -> sessions --usage
    Usage:
      sessions [--style=<Style> (boxed compact)] -- Default display style is boxed.
The latter example is generated entirely from these two declarations:

    enum Style <boxed compact>;

    #|(Default display style is boxed.)
    sub MAIN(Style :$style = boxed) { ... }
[1] For anyone interested, you can have your cake and eat it too. Defining your own USAGE routine doesn't mean you have to give up the generated one. The generated output is available in the $*USAGE variable.

discuss

order

No comments yet.