Skip to content

A pythonic syntax for Julia (for fun, not for serious use)

License

Notifications You must be signed in to change notification settings

LenguajeJulia/PythonSyntax.jl

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PythonSyntax

Build Status

Coverage Status

codecov.io

This package is under heavy development and anything might change at any time. It also currently doesn't work on any release version of Julia. A nightly build is required in the meantime.

PythonSyntax.jl is a little like LispSyntax.jl, where this package gets its inspiration. But this isn't lisp syntax, it's Python syntax.

The easiest way to use this package is to define modules:

using PythonSyntax

pymodule"""
FizzBuzz

def 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.

About

A pythonic syntax for Julia (for fun, not for serious use)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Julia 100.0%