On 06/03/2025 02:28, Lawrence D'Oliveiro wrote:
On Wed, 5 Mar 2025 11:46:08 +0000, bart wrote:
* Compile-time enumerations, and parallel tables of enums and data
Python doesn’t have enumerations as a language primitive; instead, they
are implemented in a library module, written in pure Python -- it doesn’t
do anything you can’t do in your own code. But it supports arbitrary
attributes attached to enum instances, and subclassing of enums.
* Jump-table-based 'switch' (this requires those named consts or enums)
Does it do switched expressions? You can do those in Python.
Do you mean 'match case'? This was recently added after some 30 years. But when I tested it, it wasn't significantly faster than an if-elseif chain.
The point of a jump-table-based switch is to do all tests simultaneously, rather than sequentially, which is a big advantage for interpreted code.
And for that to be possible when the switch values are names (such as enumeration codes) requires those values to be known to the bytecode compiler. (Switch values that are integer constants only are not practical.)
In Python they are not known until runtime, but even then, they can change and so could be different each time the switch is encountered.
In Python *every identifier is a variable*, one which can be assigned a new value at any time, even if some variable values are immutable. That means you can't modify the value that A currently holds, but you can replace the whole thing.
With my language, it is known at compile-time whether any top-level identifier is a function, module, type, record, variable, named constant, imported function, macro or label.
If I wanted to do the equivalent of this:
def F(): return "hi"
....
F = 42
then I'd have to write it as:
fun G = "hi"
F := G
....
F := 42
Here, F is a variable name; G is a function name.
* Character constants: 'A' and 'ABCDEFGH' (Python needs 'ord("A")')
Python also has “\u” and “\U” for Unicode.
I have this:
println "\u20AC" # string (shows €)
println '\u20AC' # integer
println '\u20AC':"m" # shows € (interpret as multibyte char)
With \v used for 6-digit hex codes. But the encoding with these is UTF8, so this is stored as a 3-byte sequence, or taking up 24 bits of an integer.
* Built-in maths functions and constants like 'pi'
Complex arithmetic? <https://docs.python.org/3/library/cmath.html>
Hyperbolic functions? Gamma/log-gamma?
<https://docs.python.org/3/library/math.html>
There’s a reason why we don’t want to build all these into the core
language, since there are so many of them that are needed nowadays.
Are they? I find I only need the basics! I don't think the 'hyp' button on my Casio has ever been pressed (I've only just noticed it).
Actually, my language started off as a DSL for my 3D graphics apps so it had a lot of special purpose types built-in. So if p and q were 3D points, m was a transformation matrix, and e/f were edges (lines, arcs, circles) then:
(p + q)/2 # was the midpoint of pq
m * p # transformed the point p
intersect(e, f) # return points of interesections of e and f
Yes, Python has acquired 1000s of libraries because of the number of people who used it or develop stuff for it. It's an industrial scale product.
I'm not competing with that. Mine is a personal tool.
* Expression-based macros
Really only necessary if your language is not dynamic enough.
I notice no mention of coroutines or iterators. Those are quite useful
nowadays.
I've played around with closures, generators and iterators. I decided they were too clunky in my implementation and a poor fit for my product and style of coding.
But regarding closures, there is a famous test 'man or boy' which relies heavily on them (
https://en.wikipedia.org/wiki/Man_or_boy_test).
I tested the Python 3 code from Rosetta Code, set up to print the results for k=0 to 20 inclusive.
Python 3.14 took 10 seconds. I emulated what was needed in my language, and it took 0.8 seconds. (PyPy crashed at k=16, but the timing up to k=15 suggested it was a little faster than CPython.)