Skip to content

Instantly share code, notes, and snippets.

@Xliff
Created August 12, 2021 11:11

Revisions

  1. Xliff created this gist Aug 12, 2021.
    54 changes: 54 additions & 0 deletions EXPORTINGisn'tEASY.MD
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    ```raku
    use v6;

    package Bizzell::Operators {

    multi sub postfix:<seconds> ($a) {
    $a;
    }

    multi sub postfix:<minutes> ($a) {
    $a * 60;
    }

    multi sub postfix:<hours> ($a) {
    $a * 3600 * 3600
    }

    multi sub postfix:<days> ($a) {
    $a * 86400;
    }

    }

    sub EXPORT {
    Map.new(
    '&postfix:<seconds>' => &Bizzell::Operators::postfix:<seconds>,
    '&postfix:<s>' => &Bizzell::Operators::postfix:<seconds>,

    '&postfix:<minutes>' => &Bizzell::Operators::postfix:<minutes>,
    '&postfix:<m>' => &Bizzell::Operators::postfix:<minutes>,

    '&postfix:<hours>' => &Bizzell::Operators::postfix:<hours>,
    '&postfix:<h>' => &Bizzell::Operators::postfix:<hours>,

    '&postfix:<days>' => &Bizzell::Operators::postfix:<days>,
    '&postfix:<d>' => &Bizzell::Operators::postfix:<days>
    )
    }
    ```

    Now getting the basics of this is easy. I could add "is export" to the definitions in Bizzell::Operators and call it a day, but
    what would be the easy way of adding the associated aliases that would make this expression:

    ```
    4days + 8hours + 10minutes - 1second
    ```

    Turn into the much more elegant:

    ```
    4d + 8h + 10m - 1s
    ```

    BTW -- the above does NOT work.