Skip to main content

Macros for Python: Quasiquotes, Case Classes, LINQ and more!

Project description

MacroPy is an implementation of Macros in the Python Programming Language. MacroPy provides a mechanism for user-defined functions (macros) to perform transformations on the abstract syntax tree(AST) of Python code at module import time. This is an easy way to modify the semantics of a python program

Python like you’ve never seen before

MacroPy allows you to create constructs which are impossible to have in normal python code, such as:

Tracing

with trace:
    sum([x + 5 for x in range(3)])

# sum([x + 5 for x in range(3)])
# range(3) -> [0, 1, 2]
# x + 5 -> 5
# x + 5 -> 6
# x + 5 -> 7
# [x + 5 for x in range(3)] -> [5, 6, 7]
# sum([x + 5 for x in range(3)]) -> 18

Quick Lambdas

print map(f[_[0]], ['omg', 'wtf', 'bbq'])
# ['o', 'w', 'b']

print reduce(f%[_ + _], ['omg', 'wtf', 'bbq'])
# 'omgwtfbbq

Case Classes

@case
class Point(x, y): pass

p = Point(1, 2)

print str(p)    #Point(1, 2)
print p.x       #1
print p.y       #2
print Point(1, 2) == Point(1, 2) # True

And more! All this runs perfectly on vanilla Python 2.7 or PyPy 2.0. For more details, see the GitHub page.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MacroPy-1.0.1.1.zip (46.1 kB view details)

Uploaded Source

File details

Details for the file MacroPy-1.0.1.1.zip.

File metadata

  • Download URL: MacroPy-1.0.1.1.zip
  • Upload date:
  • Size: 46.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for MacroPy-1.0.1.1.zip
Algorithm Hash digest
SHA256 b909a933bebfa92d1815f3712c9540b25c2f4b831ad26a0f2b18a69b9e7a7a83
MD5 61470138133c78c0f6ec7807ab6845b6
BLAKE2b-256 b072be827f3a36ad9b282898713797dc3e069a1581702aa7dab3427172fd7584

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page