2025.03.30

egyptoglyphs vs japanoglyphs

You may not know this, but the Egyptians had already used tiny image-based communication long before it became mainstream. There's even a block in unicode specifically for it!

And I can't say it was bad:

𓆏 🐸

They even have a tiny image for a segway:

𓌝

Unimpressed by modern times.

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

2024.12.10

The weird evolution of PHP

PHP is kinda weird-ish language of weird-ish evolution.

$a = new class {
    public readonly object $b;
    public readonly object $c;

    public function __construct() {
        $this->b = new class {
            public function helloworld() {
                return 'hello world';
            }
        };
    }
};

Let's assume you found yourself with 2 properties in an object and only one of them was initialized (thrift times).

Everything is clear with the lucky initialized:

echo $a->b?->helloworld(); // hello world

But if you will do the same with non-initialized property then everything will abrupt:

echo $a->c?->helloworld(); // Typed property class@anonymous::$c must not be accessed before initialization

Not the best expectations fulfillment when there is nothing after so you are forced to check an extra check:

if (isset($a->c)) {
   echo echo $a->c->helloworld();
}

And what we want to check something inside this propery right in check?

if (isset($a->c) && $a->c->isValid()) {
   return true;
}

No reasonable explanation can explain why ?-> dies if propery wasn't initialized and you have to add isset(), but ?? just doesn't care about property initialization and it's an actual replace for isset(). So..

echo ($a->c ?? null)?->helloworld();
if (($a->c ?? null)?->isValid()) {
   return true;
}

Very noice, very butiful!

#php #code