GithubHelp home page GithubHelp logo

macropy's Introduction

MacroPy3 1.1.0b2

image

MacroPy is an implementation of Syntactic 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 a Python program at import time. This is an easy way to enhance the semantics of a Python program in ways which are otherwise impossible, for example providing an extremely concise way of declaring classes.

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(list(map(f[_[0]], ['omg', 'wtf', 'bbq'])))
# ['o', 'w', 'b']

print(list(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! See the docs at http://macropy3.readthedocs.io/en/latest/.

Requirements

MacroPy3 is tested to run on CPython 3.4 or newer and PyPy 3.5. I has no current support for Jython. MacroPy3 is also available on PyPI.

Installation

Just execute a:

$ pip install macropy3

if you want to use macros that require external libraries in order to work, you can automatically install those dependencies by installing one of the pinq or pyxl extras like this:

$ pip install macropy3[pinq,pyxl]

then have a look at the docs at http://macropy3.readthedocs.io/en/latest/.

How to contribute

We're open to contributions, so send us your ideas/questions/issues/pull-requests and we'll do our best to accommodate you! You can ask questions on the Google Group and on the Gitter channel or file bugs on thee issues page.

Credits

MacroPy was initially created as a final project for the MIT class 6.945: Adventures in Advanced Symbolic Programming, taught by Gerald Jay Sussman and Pavel Panchekha. Inspiration was taken from project such as Scala Macros, Karnickel and Pyxl.

The MIT License (MIT)

Copyright (c) 2013-2018, Li Haoyi, Justin Holmgren, Alberto Berti and all the other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

macropy's People

Contributors

lihaoyi avatar azazel75 avatar jnhnum1 avatar ceridwen avatar thedrow avatar rctay avatar whart222 avatar avdn avatar durden avatar fjarri avatar mhinz avatar mattfenwick avatar kotnik avatar pavpanchekha avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.