[Python-Dev] Re: PEP 638: Syntactic macros

2023-01-29 Thread cdp49
It looks like this hasn't gone anywhere in the past few years, which is a 
shame. Syntactic macros are one of the 2 or 3 "Killer features" that pushed me 
out of Python and into Julia (along with JITting inferred types and multiple 
dispatch). Math+data science code written in Julia is a lot more readable 
because of this.
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/PPCXZJYPNNT6XZ6EQ35OQE4SG2QBAZRT/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 638: Syntactic macros

2023-02-01 Thread cdp49
Unfortunately, it's no longer being maintained.
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/UEPTBUIK67NLNE4JBNN6JNJON3BRGSUK/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 638: Syntactic macros

2023-02-01 Thread cdp49
I think that's exactly the problem with a lack of Python macros. The full 
quote, of course, goes: "There should be one-- and preferably only one 
--*obvious* way to do it."

Often, there's a mathematical notation for something, and *this* is the only 
obvious way to write anything out. But this doesn't work if you force every 
package to adopt the same syntax. For example, if you'd like a package to work 
with probabilities, it's very reasonable to want to write `x ~ Normal(0, 1)` to 
say x follows a normal distribution. This is the only syntax I consider natural 
for this problem; but packages can't do that, since `~` already has a meaning 
outside of probability.

Not to mention, DSLs are forced to adopt all kinds of weird syntax when the 
behavior of base Python doesn't align with what the DSL needs to do. Obviously, 
the only way to write out a `for` loop should be to use the `for` keyword. This 
doesn't work in JAX. If you want to use a `for` loop in JAX, you have to use 
the `lax.fori_loop` function, or else `for` will end up being unrolled, because 
of various requirements of the JAX compiler. Having to use `lax.fori_loop` is, 
to put it mildly, *incredibly* unpythonic.

This really is the biggest reason I switched to Julia: Python math is 
unpythonic. I don't want to be forced to learn lots of weird little functions 
like `np.matmul(x1, x2)` when there's already one obvious syntax I'm very 
familiar with: `x1 *  x2`.
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/6QM4GMH5FDX2H5OZHCE33EOJHCV3TI2R/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-Dev] Re: PEP 638: Syntactic macros

2023-02-05 Thread cdp49
> Python has consistently refused to be turned into a platform for DSLs for 
> almost 3 decades. 

I think SymPy, PyMC, Pyomo, Pyro, and many more packages would all be very 
surprised to hear they're no longer welcome in Python. Still, it seems like it 
would be quite hard to kick them out, and would probably make the scientific 
programming community pretty angry. If you don't like having DSLs in Python, I 
think you're trying to close the barn door after the horse has bolted; you'd 
have to go back in time to the creation of NumPy. 

Syntactic macros aren't necessary for DSLs; it just makes them better. Without 
syntactic macros, DSLs are forced to use clunky, complicated, and error-prone 
string manipulation, rather than cleaner syntactic transformations.  For 
instance, here's NumPy's einsum, effectively behaving like a string macro:
```
X = np.einsum('ij,jk->ik', A, B, optimize='optimal')
```

And now here's the same thing in Julia:
```
@einsum X[i, k] := A[i, j] * B[j, k]
```

Which is more readable? Which is more Pythonic? 

It's not that Python doesn't have DSLs (NumPy is effectively a DSL for linear 
algebra). It's just that their syntax is sufficiently obscure that it's not at 
all clear that's what they're doing.
___
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/RWSSY4KZLQYXHFF34AR544C44NZ6K7XE/
Code of Conduct: http://python.org/psf/codeofconduct/