Comment

Comment by pcr910303

Wait... looking at this, doesn't this mean that by deliberately misusing the `codec` module, meta programming at compile-time (somewhat like Lisp macros) is possible in Python?

By using a custom parser, people are able to add custom syntax in python (which is... undoubtedly unpythonic) with just a decorator(or a magic comment) on front. I can't wait to start abusing this... :-)

Edit: Looks like a pattern matching syntax that hooks in pampy would be my first hacking project :-)

    # coding: patmatch
    import patmatch
    
    input = [1, 2, 3]
    patmatch input:
        case [1, 2, x]:
            print(f"{x} is matched!") #=> 3 is matched!
    
    def fibonacci(n):
        patmatch n:
            case 1: return 1
            case 2: return 1
            case _: return fibonacci(n - 1) + fibonacci(n - 2)
parent pcr910303 6 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton