Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

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

Oink is a Python to Javascript translator.

License

NotificationsYou must be signed in to change notification settings

alecthomas/oink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Oink attempts to translate Python source to idiomatic Javascript.

It consists of the translator itself and a JS runtime.

Examples

Here are a couple of examples fromProject Euler:

Project Euler 1

Python source for solution 1:

defeuler1():"""Add all the natural numbers below 1000 that are multiples of 3 or 5"""multiple=lambdax,y:x%y==0returnsum(xforxinxrange(1,1000)ifmultiple(x,3)ormultiple(x,5))printeuler1()

Runningoink euler1.py on this example produces the following #"auto" data-snippet-clipboard-copy-content="/** Add all the natural numbers below 1000 that are multiples of 3 or 5 */function euler1() { var multiple = function (x, y) { return x % y == 0; }; return Oink.sum(Oink.listComprehension(Oink.range(1, 1000), function (x) { return x; }, function (x) { return multiple(x, 3) || multiple(x, 5); }));};console.log(euler1());">

/** Add all the natural numbers below 1000 that are multiples of 3 or 5 */functioneuler1(){varmultiple=function(x,y){returnx%y==0;};returnOink.sum(Oink.listComprehension(Oink.range(1,1000),function(x){returnx;},function(x){returnmultiple(x,3)||multiple(x,5);}));};console.log(euler1());

Project Euler 6

Python source for solution 6:

defeuler6(op,end):returnop(sum(xrange(end+1)))-sum(op(x)forxinxrange(end+1))printeuler6(lambdax:x**2,100)

Runningoink euler6.py on this example produces the following #"auto" data-snippet-clipboard-copy-content="function euler6(op, end) { return op(Oink.sum(Oink.range(end + 1))) - Oink.sum(Oink.listComprehension(Oink.range(end + 1), function (x) { return op(x); }));};console.log(euler6(function (x) { return Math.pow(x, 2); }, 100));">

functioneuler6(op,end){returnop(Oink.sum(Oink.range(end+1)))-Oink.sum(Oink.listComprehension(Oink.range(end+1),function(x){returnop(x);}));};console.log(euler6(function(x){returnMath.pow(x,2);},100));

About

Oink is a Python to Javascript translator.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp