2025-01-26:

CLI params and Racket Language

Experienced unstoppable need to write a tiny binary executable file. It couldn't be a PHP as we all there are mentally passable people.

Next obvious choice was Racket language, so let's open the official Racket documentation:

(command-line optional-name-expr optional-argv-expr
              flag-clause ...
              finish-clause)

optional-name-expr = | #:program name-expr

optional-argv-expr = | #:argv argv-expr

   flag-clause = #:multi flag-spec ...
               | #:once-each flag-spec ...
               | #:once-any flag-spec ...
               | #:final flag-spec ...
               | #:usage-help string ...
               | #:help-labels string ...
               | #:ps string ...

     flag-spec = (flags id ... help-spec body ...+)
               | (flags => handler-expr help-expr)

         flags = flag-string
               | (flag-string ...+)

     help-spec = string
               | (string-expr ...+)

 finish-clause =
               | #:args arg-formals body ...+
               | #:handlers handlers-exprs

   arg-formals = rest-id
               | (arg ...)
               | (arg ...+ . rest-id)

           arg = id
               | [id default-expr]

handlers-exprs = finish-expr arg-strings-expr
               | finish-expr arg-strings-expr help-expr
               | finish-expr arg-strings-expr help-expr
                 unknown-expr

Please, take a minute to visually contemplate the beauty of formatting.

Okay, that's enough. If you still have no idea how does it exactly work, there is a real example of someone who ascended:

(define parser
  (command-line
   #:usage-help
   "Here you can write a general description of your program"
   "You can have multiple strings to make multiple lines"

#:once-each [("-m" "--my-parameter") MY-PARAMETER-NAME "write a short description of what setting MY-PARAMETER-NAME does" (my-parameter (string->number MY-PARAMETER-NAME))] [("-a" "--another-parameter") ANOTHER-PARAM "a little description of ANOTHER-PARAM" (another-parameter (string=? "true" ANOTHER-PARAM))] [("-s" "--string") A-STRING "what is A-STRING?" (a-string A-STRING)]

#:args () (void)))

Love very much the racket's usage of magic stings like #:once-each which definitely do something, but avoid autocompletion of official IDE. Wish you happy developing!

Very, very deep. I think it more than enough racket for me.

#racket #code #why #wtf #way