[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
New mailing list hosting and some updates
Hi,
I've spent some time recently on migrating our mailing list hosting to a
self-hosted mlmmj instance on an existing, project-related machine. The
list was previously maintained using MailmanLists
(https://www.mailmanlists.net), which worked fine but I was paying for
the hosting out of my own pocket. Moving it to our own infrastructure
also means we can add more lists as we see fit, and I've already added a
perlang-announce mailing list where I intended to post release notes
whenever a new release is made. You can find the new web interface for
the mailing lists here: https://lists.perlang.org/
As far as the project is concerned, initial support for interfaces was
merged some week ago -
https://gitlab.perlang.org/perlang/perlang/-/merge_requests/703. The
next upcoming feature I'm thinking about is support for something like
"nullable unions". The initial use case is "char | null", i.e. being
able to have a char variable/field that either contains a (16-bit) char
_or_ a null reference. The underlying C++ representation will likely be
std::optional<T>, so for a char, the actual type will be
std::optional<char16_t>.
So... what will the syntax look like for actually using this type?
ChatGPT suggested to use "type narrowing" for this, so that you would
write something like this:
var c: char | null = 'A';
if (c != null) {
// Inside this block, c would be 'char', not 'char | null'
}
This could probably work, even though it requires some control flow
analysis if you want to support scenarios like "return inside the ==
null block" (because the 'c' variable should be considered 'char' after
the block in that case). Doesn't sound entirely trivial, and one
challenge I see with it is that _it's non-obvious to the reader_, and
that's actually a quite important aspect. In this regard, the Python
folks are right with their "explicit is better than implicit"[1]
principle. Code that is explicit is typically easier to understand and
reason about, particularly for the casual reader. I certainly don't want
Perlang to become a language that only people with a PhD in Perlang
programming can understand. :-)
So, I'm leaning towards something like this instead:
var v: char | null = 'A';
if (v is char c) {
// c can be accessed inside this block
}
The 'is T <variable>' idiom is borrowed from C#, even though that
language doesn't have this particular concept of nullable unions. The
nice part about it is that it's pretty obvious to the reader what is
going on here; the 'c' variable has its type and name explicitly
specified. The not-so-nice part about it is that the variable is
declared *outside* the block (which can be useful for if/else without {}
blocks); it feels like this will make generating the appropriate C++
code slightly harder. I'm thinking about "hoisting" the variable to the
containing block, but decomposing the above to some kind of meaningful
C++ still doesn't feel entirely easy. I'll check with ChatGPT or Claude
before attempting to start the implementation, but this at least
explains what I'm aiming for syntax-wise.
[1] https://peps.python.org/pep-0020/#the-zen-of-python
--
Per Lundberg
Perlang author and maintainer