https://github.com/totalverb/pythonsyntax.jl
A pythonic syntax for Julia (for fun, not for serious use)
https://github.com/totalverb/pythonsyntax.jl
Last synced: 2 months ago
JSON representation
A pythonic syntax for Julia (for fun, not for serious use)
- Host: GitHub
- URL: https://github.com/totalverb/pythonsyntax.jl
- Owner: TotalVerb
- License: other
- Created: 2016-05-17T04:37:01.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-08-20T21:32:49.000Z (over 5 years ago)
- Last Synced: 2024-11-08T12:50:57.555Z (6 months ago)
- Language: Julia
- Size: 19.5 KB
- Stars: 14
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# PythonSyntax
[](https://travis-ci.org/TotalVerb/PythonSyntax.jl)
[](https://coveralls.io/github/TotalVerb/PythonSyntax.jl?branch=master)
[](http://codecov.io/github/TotalVerb/PythonSyntax.jl?branch=master)
This package is under development and anything might change at any time. It also currently doesn't work on any release version of Julia, except for 0.5.2.
PythonSyntax.jl is a little like [LispSyntax.jl](https://github.com/swadey/LispSyntax.jl), where this package gets its inspiration. But this isn't lisp syntax, it's Python syntax.
You need to use Python 3 with, e.g. by (and then restarting Julia after):
```
ENV["PYTHON"] = "/usr/bin/python3"
Pkg.build("PyCall")
```The easiest way to use this package is to define modules:
```julia
using PythonSyntaxpymodule"""
FizzBuzzdef fizzbuzz(n):
# this is still Julia, even though it looks like Python!
# so range includes 1 and has length n — very different from Python.
for i in range(1, n):
if i % 15 == 0:
println("FizzBuzz")
elif i % 3 == 0:
println("Fizz")
elif i % 5 == 0:
println("Buzz")
else:
println(i)
"""FizzBuzz.fizzbuzz(10)
```Remember: this is Julia, not Python. The syntax is Pythonic but the semantics are Julian.
## Rewriting
Some identifiers are rewritten. Currently, the only rewriting is that `_b` suffixes in Python get mapped to `!` suffixes in Julia.## Magic Syntax
`PythonSyntax` introduces some magic syntax that is unlike anything else in the Python language.
* `__jl__("2:2:10")` escapes to Julia syntax. This can be useful if something has no clean way of being expressed pythonically. Note that this is not a runtime method: only string literals, and not strings computed at runtime, can be used.
* `__mc__(time, [i**2 for i in range(1, 10)])` allows calling Julia macros. Any number of arguments can be provided; they are given to the macro as expressions and are not evaluated, exactly as in Julia.