Sujet : Re: Python recompile
De : ldo (at) *nospam* nz.invalid (Lawrence D'Oliveiro)
Groupes : comp.lang.cDate : 06. Mar 2025, 23:17:20
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vqd6tg$35gif$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
User-Agent : Pan/0.162 (Pokrosvk)
On Thu, 6 Mar 2025 11:15:39 +0000, bart wrote:
On 06/03/2025 02:28, Lawrence D'Oliveiro wrote:
>
Does it do switched expressions? You can do those in Python.
>
Do you mean 'match case'?
That’s a generalization of the concept, but it’s a statement, not an
expression.
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.
I forgot about \N:
>>> print("\N{LATIN SMALL LETTER T}\N{LATIN SMALL LETTER E}\N{LATIN SMALL LETTER S}\N{LATIN SMALL LETTER T}")
test
Actually, my language started off as a DSL for my 3D graphics apps so it
had a lot of special purpose types built-in.
The Python approach is to allow you to define such DSLs using
libraries. Classes can define custom overloads for language operators
and subscripting. So you can define your own “vector” and “matrix”
types, and write arithmetic expressions with those types, using
standard operators like “+”, “*” and “@” with type-specific meanings.
On top of which, I came up with a way to add constructs that look like
new user-defined operators (i.e. without the need to add extra
parentheses around their operands).
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
Yup, I have done the same sort of thing. Python introduced “@” as a
new operator in 3.5, with the intention that it be used to represent
dot products. They haven’t done a special one for cross products,
though.
Does your system have quaternions?
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.
Iterators/generators are a natural thing to use for database queries,
for example. Coroutines greatly simplify event-driven programming. In
my Python code for customers, I have found real-world uses for both.