Saturday, April 29, 2017

nonstandard module and PEP 542


PEP 542 proposes a shortcut notation when defining functions that would be added to a class. A discussion of this idea can be found here.   Personally, I am not too fond of the idea ... but it's a good test case to see if I my nonstandard module, which I have mentioned before on this blog, could allow the proposed syntax to be used right now.

$$ type pep542_testfile.py
from __nonstandard__ import pep542

def test_pep542():
    class MyClass:
        pass

    def MyClass.square(self, x):
        return x**2

    a = MyClass()

    def a.out():
        return 42

    assert a.out() == 42
    assert a.square(3) == 9
$$ python test_pep542.py
Successfully tested function test_pep542


The answer seems to be yes ...



Monday, April 24, 2017

Easily modifiable Python

You want to try out some new syntactic construction in Python but do NOT want to have to go through the trouble of

1. modifying Python's grammar file
2. modifying Python's lexer
3. modifying Python's parser
4. modifying Python's compiler
5. re-compile all the sources  so as to create a new Python interpreter?

(These steps are described in these two blog  posts.)

It can be done much more easily using any existing Python interpreter! ;-)


More details soon...