Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

List of languages that compile to python

NotificationsYou must be signed in to change notification settings

vindarel/languages-that-compile-to-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 

Repository files navigation

We have variants of Python that can use Python libs: welcome toDogelang,Mochi,Hy,Coconut andHask.

We can also have languages that target the Python platform withoutbeing necessarily compatible with Python, and domain-specificlanguages.

For more ressources related to functional programming in Python, seetheAwesome Functional Pythonlist.

Table of Contents

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 !

NOT'REALLY®

Dogelang 
sourceshttps://github.com/pyos/dg
dochttps://pyos.github.io/dg/
v1 ?yes, april 2015
createdjune, 2012
  • compiles to CPython 3.4. Dg is an alternative syntax to Python 3.
  • compatible with all the libraries
  • runs on PyPy

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 =arg1arg2 -> : print (arg1.replace"Do ""Did ")arg2sep:", "end:".\n"function"Do something""dammit"
  • infix notation (with backticks)
  • function composition (with<-)
  • first class operators
f = (+)f12 ==3
  • partial application (andbind isfunctools.partial)
f = (2 *)f10 ==20
  • new functional builtins:foldl andfoldl1,scanl,flip,takewhile anddropwhile (fromitertools),take anddrop,iterate,head andfst,tail,snd,last andinit.

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

    wtf = the~decorator~ $ ->

Install

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

Editors

Editor 
Gedithttps://github.com/pyos/dg-gedit/
Sublimehttps://github.com/pyos/dg-textmate/

Pygments support.

Example projects

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

Hissp - It's Python with a Lissp!

Hissp is a modular Lisp implementation that compiles to a functional subset of Python—Syntactic macro metaprogramming with full access to the Python ecosystem!

Hissp 
sourceshttps://github.com/gilch/hissp
dochttps://hissp.readthedocs.io/
v1 ?no, v0.2 as of May 2021
created2019
discussgitter

The Hissp compiler is written in Python 3.8.

Language features

The Hissp compiler should include what it needs to achieve its goals, but no more. Bloat is not allowed.

Hissp compiles to an unpythonic functional subset of Python.

Hissp's basic macros are meant to be just enough to bootstrap native unit tests and demonstrate the macro system. They may suffice for small embedded Hissp projects, but you will probably want a more comprehensive macro suite for general use.

You do not need Hissp installed to run the final compiled Python output

(defmacroattach (target ::* args)"Attaches the named variables as attributes of the target.  Positional arguments use the same name as the variable.  Names after the ``:`` are key-value pairs."  (let (iargs (iter args)        $target`$#target)    (let (args (itertools..takewhile (lambda (a)                                       (operator..ne a':))                                     iargs))`(let (,$target,target),@(map (lambda (arg)`(setattr,$target',arg,arg))                args),@(map (lambda (kw)`(setattr,$target',kw,(next iargs)))                iargs),$target))))

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

Hy 
sourceshttps://github.com/hylang/hy/
dochttp://hylang.org/
v1 ?no
createddecember, 2012
online REPLhttps://try-hy.appspot.com/
discussgoogle group
IRChy on freenode
  • Hy compiles to Python bytecode (AST)
  • Hy can use python libraries, and we can import a Hy module into aPython program.

Language features

  • it's python: context managers, named and keyword arguments, listcomprehensions,...
  • macros, reader macros
  • threading macros (like Clojure), with-> and->> (similar topipes)
(-> (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 (* it2) [12 3])); => [2, 4, 6]
  • fraction literal (like Clojure)
  • unicode support (I mean for symbols)
  • pattern matching (in libraries, likeHyskell)
  • monads (in libraries, likeHymn)

Install

    pip install hy

Editors

Editor 
Emacshttps://github.com/hylang/hy-mode
Alllisp modes for any editor

Example projects

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

Good reads

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

Basilisp - a Clojure-compatible(-ish) Lisp dialect targeting Python 3.8+

Basilisp 
sourceshttps://github.com/basilisp-lang/basilisp
dochttps://basilisp.readthedocs.io/en/latest/
v1 ?no (as of 2024, Jan) but "generally stable at this point"
createdinitial development release in 2018

Language features

  • Immutable data structures, backed by Immutables and Pyrsistent
  • Strong emphasis on functional programming concepts
  • Access to the vast array of existing Python libraries
  • Seamless interoperability between Python code and Basilisp code
  • Sophisticated REPL for REPL-based development

Planned features:

Basilisp is still young and so lacks many features that more mature languages and runtimes might include. There are many such planned features that will hopefully improve the ergonomics of the project for new developers.

fundamental differences and omissions in Basilisp that make it differ from Clojure:

  • Basilisp does not include Ref types or software transactional memory (STM) support.
  • Basilisp does not include Agent support (support is tracked in #413).
  • All Vars are reified at runtime and users may use the binding macro as in Clojure.
  • Support for Clojure libs is planned.
  • Type hints may be applied anywhere they are supported in Clojure (as the :tag metadata key), but the compiler does not currently use them for any purpose.
(def^{:doc"Returns the second element in a Seq.":arglists'([seq])}second  (fn*second [seq] (first (rest seq))))

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

Mochi 
sourceshttps://github.com/i2y/mochi
docmany examples
v1 ?no
createdv0.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 
Atomhttps://github.com/i2y/language-mochi

Good reads

Coconut - Simple, elegant, Pythonic functional programming

Coconut 
sourceshttps://github.com/evhub/coconut
dochttps://coconut.readthedocs.io
v1 ?yes, on june, 2016
createdfebruary, 2015 (v0.1)
  • Coconut compiles to Python (not CPython bytecode, so it supportsother 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 Python3in Coconut.

  • ipython / jupytersupport(installed by default)

Language features

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

For multiline pipes, surround them with parenthesis (python rule thatevery 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 comma-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 
Emacshttps://github.com/NickSeagull/coconut-mode
Sublimehttps://github.com/evhub/sublime-coconut
Vimhttps://github.com/manicmaniac/coconut.vim

Hask - Haskell language features and standard libraries in pure Python.

Hask 
sourceshttps://github.com/billpmurphy/hask
docon github
v1 ?no
createdjuly, 2015

Hask is a pure-Python, zero-dependencies library that mimics most ofthe core language tools from Haskell, including:

  • Full Hindley-Milner type system (with typeclasses) that will typecheck any function decorated with a Hask type signature. Also, typed functions can bepartially applied.
@sig(H/"a">>"b">>"a")defconst(x,y):returnx
  • Easy creation of newalgebraic data types and new typeclasses, with Haskell-like syntax
  • Pattern matching with case expressions
deffib(x):return~(caseof(x)|m(0)>>1|m(1)>>1|m(m.n)>>fib(p.n-1)+fib(p.n-2))
  • Automagical functioncurrying/partial application and function composition
  • Efficient,immutable, lazily evaluated List type with Haskell-style list comprehensions
  • All your favorite syntax and control flow tools, includingoperator sections,monadic error handling,guards, and more
  • Python port of (some of) the standard libraries from Haskell's base, including:
    • Algebraic datatypes from the Haskell Prelude, including Maybe and Either
    • Typeclasses from the Haskell base libraries, including Functor, Applicative, Monad, Enum, Num, and all the rest
    • Standard library functions from base, including all functions from Prelude, Data.List, Data.Maybe, and more

Features not yet implemented, but coming soon:

- Python 3 compatibility- Better support for polymorphic return values/type defaulting- Better support for lazy evaluation (beyond just the List type and pattern matching)- More of the Haskell standard library (Control.* libraries, QuickCheck, and more)- Monadic, lazy I/O

Install

git clone https://github.com/billpmurphy/haskpython setup.py install

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

Rabbit 
sourceshttps://github.com/evhub/rabbit
docno doc
v1 ?yes, on oct, 2014. DISCONTINUED
createdv0.1 on may, 2014

From the author's words:(src)

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

  • Coconut is compiled, while Rabbit is interpreted, making Coconutmuch 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

MakrellPy - a functional language with metaprogramming support and simplistic syntax

MakrellPy 
sourceshttps://github.com/hcholm/makrell-py
v1 ?no
createdFebruary, 2024

MakrellPy, part of the Makrell language family, is a general-purpose, functional and homoiconic programming language with two-way Python interoperability, metaprogramming support and simple syntax. The language family is based on the Makrell Base Format, a general data format that can be used both for programming languages and data interchange. Other family members include MRON, a lightweight alternative to JSON, and MRML, a lightweight alternative to XML and HTML.

Language features

  • Compiles to Python AST, runs on Python with two-way interoperability.
  • Simple syntax using the Makrell Base Format.
  • Functional programming with multiline lambdas, partial application, and function composition.
  • Metaprogramming support with custom operators, macros and custom metaprogramming functions.
  • Homiconic, with a simple and consistent syntax for data and code.
  • Languages in the Makrell family can be embedded in each other while maintaining the base format.
  • The Makrell package includes MRON and MRML support, an API for working with the Makrell Base Format and a basic language server supporting the Language Server Protocol.
  • REPL, syntax highlighting and basic diagnostics support for Visual Studio Code.

Sample code

{fun add [x y]    x + y}a = {add 2 3}{print a}  # 5a | print  # same, with pipe operatorf = [x y] -> {do    {print "multiline lambda here"}    x * y}{print {f 2 3}}  # function calladd3 = {f 3 _}  # partial application2 | {+ 3} | {* 5}  # operators as functionsadd3mul5 = add3 >> {* 5}  # function composition

Install

pip install makrell

Editors

Editor 
Visual Studio Codehttps://marketplace.visualstudio.com/items?itemName=hcholm.vscode-makrell
OtherMakrellPy is supported by the Language Server Protocol, so it should work with any editor that supports LSP.

Implemented in another language but target the Python platform. They can use Python libs.

Erg - General statically typed multiparadigm rusty programming language

A statically typed language that can deeply improve the Python ecosystem

Erg 
sourceshttps://github.com/erg-lang/erg
dochttps://erg-lang.github.io/
v1 ?no, v0.4.2 as of September 2022
created2022

The Erg compiler is written in Rust.

Language features

Erg is a pure object-oriented language. Everything is an object; types, functions, and operators are all objects. On the other hand, Erg is also a functional language. Erg requires some kinds of markers to be placed on code that causes side effects or changes internal state, which can localize the complexity of code. This will greatly improve the maintainability of your code.

Erg is internally compatible with Python and can import the Python API at zero cost.

# Functional style (immutable), same as `sorted(list)` in Pythonimmut_arr= [1,3,2]assertimmut_arr.sort()== [1,2,3]# Object-oriented style (mutable)mut_arr= ![1,3,2]mut_arr.sort!()assertmut_arr== [1,2,3]i= !1i.update!old->old+1asserti==2# Functions cannot cause side effectsinci:Int!=i.update!old->old+1# SyntaxError: cannot call a procedural method in a function# hint: only methods of mutable types can change the state of objects# Code that uses a lot of side effects is redundant, so you will naturally write pure codeCounter!=InheritInt!Counter!.newi:Int=Self!::__new__ !iinc!ref!self=self.update!old->old+1c=Counter!.new1c.inc!()assertc==2

Other languages that target the Python platform

Haxe, the cross-platform toolkit

Haxe 
sourceshttps://github.com/HaxeFoundation/haxe
official websitehttps://haxe.org/
dochttps://haxe.org/documentation/introduction/
online REPL_http://try.haxe.org/
v1 ?v3

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

classTest {staticfunctionmain() {varpeople= ["Elizabeth"=>"Programming","Joel"=>"Design"    ];for (nameinpeople.keys()) {varjob=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 thefacts are annotated with probabilities.

ProbLog 
official websitehttps://dtai.cs.kuleuven.be/problog/
sourceshttps://bitbucket.org/problog/problog
dochttp://problog.readthedocs.io/en/latest/
v1 ?yes, even v2
online tutorial and REPLhttps://dtai.cs.kuleuven.be/problog/tutorial.html

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

One caninteract with ProbLog from within Python code.

Install

pip install problog

PyDatalog. Logic programming to use inside your Python program.

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

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

frompyDatalogimportpyDatalogpyDatalog.create_terms('factorial, N')factorial[N]=N*factorial[N-1]factorial[1]=1print(factorial[3]==N)# prints N=6

Installation

pip install pyDatalogpip install sqlalchemy

Example projects

No examples found, onlytestimonials.

RBQL: SQL dialect with Python expressions

RBQL 
official websitehttps://rbql.org
sourceshttps://github.com/mechatroner/RBQL
v1 ?no
PyPy ?pip install rbql

RBQL is both a library and a command line tool which provides SQL-like language with Python expressions
RBQL is integrated into "Rainbow CSV" text editor plugins available for VSCode, Vim, Sublime, Atom
Main Features:

  • Allows to use Python expressions insideSELECT,UPDATE,WHERE andORDER BY statements
  • Result set of any query immediately becomes a first-class table on it's own
  • Works out of the box, no external dependencies

Usage example:

importrbqlinput_table= [    ['Roosevelt',1858,'USA'],    ['Napoleon',1769,'France'],    ['Dmitri Mendeleev',1834,'Russia'],    ['Jane Austen',1775,'England'],    ['Hayao Miyazaki',1941,'Japan'],]user_query='SELECT a.name, "birth century: {}".format(a.DOB // 100 + 1) WHERE a.name == "Roosevelt" or re.search("an", a.country, re.IGNORECASE) is not None ORDER BY random.random()'output_table= []warnings= []rbql.query_table(user_query,input_table,output_table,warnings,input_column_names=['name','DOB','country'])forrecordinoutput_table:print(','.join([str(v)forvinrecord]))

Other languages built in RPython

Monte - secure distributed computation

Monte is a "nascent dynamic programming language reminiscent of PythonandE. It is based upon The Principle of LeastAuthority (POLA), which governs interactions between objects, and acapability-based object model, which grants certain essential safetyguarantees to all objects".

Monte 
Sourceshttps://github.com/monte-language
Dochttps://monte.readthedocs.io/en/latest/intro.html
v0.1 ?yes, v2016.1

Built on Pypy.

Pixie, a lightweight and native lisp

Pixie 
Sourceshttps://github.com/pixie-lang/pixie
DocExamples: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 inRPython,the same language PyPy is written in, and as such "supports a fairlyfast 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 theJVM, CLR or Python VM. It implements its own bytecode, has its ownGC and JIT. And it's small. Currently the interpreter, JIT, GC, andstdlib clock in at about 10.3MB once compiled down to an executable.
  • The JIT makes some things fast. Very fast. Code like the followingcompiles down to a loop with 6 CPU instructions. While this may notbe too impressive for any language that uses a tracing jit, it isfairly 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 -add0 args))(loop [x 0]  (if (eq x10000)    x    (recur (add-fn x1))))
  • Math system is fully polymorphic. Math primitives (+,-, etc.) arebuilt off of polymorphic functions that dispatch on the types of thefirst two arguments. This allows the math system to be extended tocomplex numbers, matrices, etc. The performance penalty of such apolymorphic call is completely removed by the RPython generated JIT.

Good talks

RSqueak, a Squeak/Smalltalk VM written in RPython

RSqueak 
Sourceshttps://github.com/HPI-SWA-Lab/RSqueak
Dochttp://rsqueak.readthedocs.io

with all-in-one multiplatform bundles and 32 bits binaries.

About

List of languages that compile to python

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

No packages published

Contributors7


[8]ページ先頭

©2009-2025 Movatter.jp