Giter VIP home page Giter VIP logo

languages-that-compile-to-python's Introduction

We have languages that are variants of Python since they can use Python libs: that's the case of Dogelang, Mochi, Hy and Coconut.

Then, we have languages that target the Python platform and domain-specific languages, fully compatible with Python or not.

Variants of Python. They can use Python libs.

The following languages can make use of the Python libraries.

Dg - it's a Python ! No, it's a Haskell !

<img src="https://pyos.github.io/dg/images/seriousdawg.jpg", title="NOT'REALLY®"

Dogelang  
sources https://github.com/pyos/dg
doc https://pyos.github.io/dg/
v1 ? yes, april 2015
created june, 2012
  • compiles to CPython 3.4. Dg is an alternative syntax to Python 3.
  • compatible with all the libraries
  • runs on PyPy (Got to wait for a JIT-enabled PyPy 3.3 first, though.)

Language features

  • function calls without parenthesis:
print "wow" "two lines" sep: "\n"
  • reverse pipe operator:
print $ "> {}: {}".format "Karkat" "Reference something other than Doge"
  • pipe and reverse pipe (on the same line, unlike Mochi)
print <| 'What' + 'ever.' : 'This is the same thing ' + 'in a different direction.' |> print
  • function notation (arrow -> notation)
function = arg1 arg2 -> : print (arg1.replace "Do " "Did ") arg2 sep: ", " end: ".\n"
function "Do something" "dammit"
  • infix notation (with backticks)
  • function composition (with <-)
  • first class operators
f = (+)
f 1 2 == 3
  • partial application (and bind is functools.partial)
f = (2 *)
f 10 == 20
  • new functional builtins: foldl and foldl1, scanl, flip, takewhile and dropwhile (from itertools), take and drop, iterate, head and fst, tail, snd, last and init.

  • decorators don't need special syntax, they're just called with a function

    wtf = the~decorator~ $ ->
    

Install

    pip3 install git+<https://github.com/pyos/dg>

Editors

Editor  
Gedit https://github.com/pyos/dg-gedit/
Sublime https://github.com/pyos/dg-textmate/

Pygments support.

Example projects

Project  
dogeweb , a functional web framework atop asyncio https://pyos.github.io/dogeweb/

Hy - A dialect of Lisp that's embedded in Python

<img src='http://docs.hylang.org/en/latest/_images/hy-logo-small.png', title=''

Hy  
sources https://github.com/hylang/hy/
doc http://hylang.org/
v1 ? no
created december, 2012
online REPL https://try-hy.appspot.com/
discuss google group
IRC hy on freenode
  • Hy compiles to Python bytecode (AST)
  • Hy can use python libraries, and we can import a Hy module into a Python program.

Language features

  • it's python: context managers, named and keyword arguments, list comprehensions,...
  • macros, reader macros
  • threading macros (like Clojure), with -> and ->> (similar to pipes)
(-> (read) (eval) (print) (loop))
(import [sh [cat grep wc]])
(-> (cat "/usr/share/dict/words") (grep "-E" "^hy") (wc "-l"))  ; => 210
(require hy.contrib.anaphoric)
(list (ap-map (* it 2) [1 2 3]))  ; => [2, 4, 6]
  • fraction literal (like Clojure)
  • unicode support (I mean for symbols)
  • pattern matching (in libraries, like Hyskell)
  • monads (in libraries, like Hymn)

Install

    pip install hy

Editors

Editor  
Emacs https://github.com/hylang/hy-mode
All lisp modes for any editor

Example projects

Project  
Github trending https://github.com/trending/hy
Live coding Blender https://github.com/chr15m/blender-hylang-live-code

Good reads

Title  
How Hy backported "yield from" to Python 2 http://dustycloud.org/blog/how-hy-backported-yield-from-to-python2/

Mochi - Dynamically typed programming language for functional programming and actor-style programming

Mochi  
sources https://github.com/i2y/mochi
doc many examples
v1 ? no
created v0.1 on december, 2014
  • translates to Python3's AST/bytecode

Language features

  • Python-like syntax
  • pipeline operator (multiline ok)
range(1, 31)
|> map(fizzbuzz)
|> pvector()
|> print()
  • tail-recursion optimization (self tail recursion only)
  • no loop syntax
  • re-assignments are not allowed in function definition
  • persisent data structures (using Pyrsistent)
  • Pattern matching / Data types, like algebraic data types
  • Syntax sugar of anonymous function definition (-> notation and $1 for the arguments)
  • Actor, like the actor of Erlang (using Eventlet)
  • Macro, like the traditional macro of Lisp
  • Anaphoric macros
  • Builtin functions includes functions exported by itertools module, recipes, functools module and operator module

Install

    pip3 install mochi

Editors

Editor  
Atom https://github.com/i2y/language-mochi

Good reads

Coconut - Simple, elegant, Pythonic functional programming

Coconut  
sources https://github.com/evhub/coconut
doc https://coconut.readthedocs.io
v1 ? yes, on june, 2016
created february, 2015 (v0.1)
  • Coconut compiles to Python (not CPython bytecode, so it supports other Python implementations: PyPy, Jython, etc)

  • Coconut code runs on any major Python version, 2 or 3

  • all valid Python 3 is valid Coconut: you can write standard Python3 in Coconut.

  • ipython / jupyter support (installed by default)

Language features

  • pipelines
(1, 2) |*> (+) |> sq |> print

For multiline pipes, surround them with parenthesis (python rule that every newline inside parenthesis is ignored):

(
    "hello"
    |> print
)
  • pattern matching (match x in value:), guards
  • algeabric data types
  • partial application ($ sign right after a function name)
expnums = map(pow$(2), range(5))
expnums |> list |> print
  • lazy lists (surround coma-separated lists with (| and |))
  • destructuring assignment
  • function composition (with ..)
fog = f..g
  • prettier lambdas (-> syntax)
  • parallel programming
  • tail recursion optimization
  • infix notation (like in Haskell with backticks)
  • underscore digits separators (10_000_000)
  • decorators support any expression
@ wrapper1 .. wrapper2 $(arg)
  • code pass through the compiler
  • ...

Install

    pip install coconut

Editors

  • Pygments support
Editor  
Emacs https://github.com/NickSeagull/coconut-mode
Sublime https://github.com/evhub/sublime-coconut
Vim https://github.com/manicmaniac/coconut.vim

Rabbit - a functional language on top of Python (discontinued in favor of Coconut)

Rabbit  
sources https://github.com/evhub/rabbit
doc no doc
v1 ? yes, on oct, 2014. DISCONTINUED
created v0.1 on may, 2014

From the author's words: (src)

Coconut is my attempt to fix the mistakes I thought I made with Rabbit, namely:

  • Coconut is compiled, while Rabbit is interpreted, making Coconut much faster
  • Coconut is an extension to Python, while Rabbit is a replacement, making Coconut much easier to use

Quicksort:

qsort(l) = (
    qsort: (as ~ \x\(x @ x<=a)) ++ a ++ qsort: (as ~ \x\(x @ x>a))
    $ a,as = l
    ) @ len:l

Other languages that target the Python platform

Haxe, the cross-platform toolkit

Haxe  
sources https://github.com/HaxeFoundation/haxe
official website https://haxe.org/
doc https://haxe.org/documentation/introduction/
online REPL _http://try.haxe.org/
v1 ? v3

Haxe is an open source toolkit that allows you to easily build cross-platform tools and applications that target many mainstream platforms (Python, ActionScript3, C++, C#, Flash, Java, Javascript, NekoVM, PHP, Lua).

class Test {
  static function main() {
    var people = [
      "Elizabeth" => "Programming",
      "Joel" => "Design"
    ];
    for (name in people.keys()) {
      var job = people[name];
      trace('$name does $job for a living!');
    }
  }
}

Domain-specific languages

ProbLog. Probabilistic Logic Programming.

Probabilistic logic programs are logic programs in which some of the facts are annotated with probabilities.

ProbLog  
official website https://dtai.cs.kuleuven.be/problog/
sources https://bitbucket.org/problog/problog
doc http://problog.readthedocs.io/en/latest/
v1 ? yes, even v2
online tutorial and REPL https://dtai.cs.kuleuven.be/problog/tutorial.html

ProbLog is built with Python. Its only requirement is Python2.7 or 3.

One can interact with ProbLog from within Python code.

Install

pip install problog

PyDatalog. Logic programming to use inside your Python program.

PyDatalog  
official website https://sites.google.com/site/pydatalog/
sources https://github.com/pcarbonn/pyDatalog
doc https://sites.google.com/site/pydatalog/Online-datalog-tutorial
v1 ? v0.17 (january, 2016)
PyPy ? yes

pyDatalog adds the logic programming paradigm to Python. Logic programmers can now use the extensive standard library of Python, and Python programmers can now express complex algorithms quickly.

from pyDatalog import pyDatalog
pyDatalog.create_terms('factorial, N')


factorial[N] = N*factorial[N-1]

factorial[1] = 1

print(factorial[3]==N)  # prints N=6

Installation

pip install pyDatalog pip install sqlalchemy

Example projects

No examples found, only testimonials.

Misc

Pixie, a lightweight and native lisp built in RPython

Pixie  
Sources https://github.com/pixie-lang/pixie
Doc Examples: https://github.com/pixie-lang/pixie/tree/master/examples
v0.1 ? no
REPL, installer, test runner,… https://github.com/pixie-lang/dust
IRC #pixie-lang on Freenode

Pixie is built in RPython, the same language PyPy is written in, and as such "supports a fairly fast GC and an amazingly fast tracing JIT".

Inspired by Clojure.

Features

  • Immutable datastructures
  • Protocols first implementation
  • Transducers at-the-bottom (most primitives are based off of reduce)
  • A "good enough" JIT (implemented, tuning still a WIP, but not bad performance today)
  • Easy FFI
  • object system
  • continuations, async I/O inspired by nodejs (see talk)
  • Pattern matching (planned)

From the FAQ:

  • Pixie implements its own virtual machine. It does not run on the JVM, CLR or Python VM. It implements its own bytecode, has its own GC and JIT. And it's small. Currently the interpreter, JIT, GC, and stdlib clock in at about 10.3MB once compiled down to an executable.
  • The JIT makes some things fast. Very fast. Code like the following compiles down to a loop with 6 CPU instructions. While this may not be too impressive for any language that uses a tracing jit, it is fairly unique for a language as young as Pixie.
;;  This code adds up to 10000 from 0 via calling a function that takes a variable number of arguments.
;;  That function then reduces over the argument list to add up all given arguments.

(defn add-fn [& args]
  (reduce -add 0 args))

(loop [x 0]
  (if (eq x 10000)
    x
    (recur (add-fn x 1))))
  • Math system is fully polymorphic. Math primitives (+,-, etc.) are built off of polymorphic functions that dispatch on the types of the first two arguments. This allows the math system to be extended to complex numbers, matrices, etc. The performance penalty of such a polymorphic call is completely removed by the RPython generated JIT.

Good talks

languages-that-compile-to-python's People

Contributors

vindarel avatar

Watchers

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