evhub / coconut Goto Github PK
View Code? Open in Web Editor NEWSimple, elegant, Pythonic functional programming.
Home Page: http://coconut-lang.org
License: Apache License 2.0
Simple, elegant, Pythonic functional programming.
Home Page: http://coconut-lang.org
License: Apache License 2.0
Include tracing information in compilation error messages.
All the different targets should be tested with all the different --target
parameters that they are supposed to support, and in cases such as for Python 3 where special syntax is supported, that should be tested.
Website should be rewritten to not be the readme.
Features to Include:
=
Module docstrings should be automatically moved to the top of the compiled Python.
iterobj$[0:5:-1] <=> iterobj$[slice(0, 5, -1)]
Use match <item> with <match>
instead of match <match> in <item>
. This is more standard wording.
Suggested flags are -c, --cython
.
Just like sequences can be unpacked using simple assignment, most pattern-matching constructs should work as well, like dictionary unpacking.
Always inherit from object
in all classes.
Proposed usage:
$ coconut --target 2.7
$ coconut -t 2.7
It would make the compiled Python more readable if references to __coconut__
were removed.
Suggested Syntax:
{| match |} = 5
name . {| data |} = 10
Otherwise no checks are performed and non-iterators won't fall through.
Suggested Syntax:
s{} == set()
f{1,2} == frozenset([1,2])
Should also appear in match statements.
Suggested Syntax:
match <const> or <const> in <value>:
<body>
All compiled files should store a hash of the coconut code and coconut version that were used in compiling the file as a comment after the hashbang and encoding declaration. Then, when compiling files, the compiler should check if the file is already there with the same hash, and if it is, not recompile. A new flag -f
or --force
should be added to override this behavior and always recompile files.
Something like this
(> x, y, z <)
should compile to something like this
(f() for f in (lambda: x, lambda: y, lambda: z))
Suggested Syntax:
def <arg> ` <op> ` <arg>:
<body>
<arg> ` <op> ` <arg> = <body>
(< 5) => (lambda x: x < 5)
(5 +) => (lambda x: 5 + x)
The suggested flags are -m
or --module
(in a package) and -a
or --standalone
(file).
Like so:
\\cdef f(
x, y):
<code>
If --strict
is enabled, errors should be generated on all Python syntax that Coconut intends to replace, such as non-decimal integers.
Problems left to address:
__unicode__
vs __str__
Multiple pipe operator:
(1, 2) |*> func
Reverse pipe operator (and multiple reverse):
func <| 5
Instead of the globals()
and locals()
hacks that are currently employed, a separate process should be used to run code in the interpreter.
This should hopefully resolve execution errors in code like:
def f(x) = x
def g(x) = f(x)
f(1)
That is, allow for the use of the lambda
statement.
Proposed syntax:
x = 3
match [a, ^x] in [1, 2]:
print("this match never succeeds")
match [x, ^x] in [1, 3]:
print(x) # prints 1
Syntax should be
meta <lhs>:
<body>
<return rhs>
which should have its <body>
run and then compiled to
parse(lhs + " = " + ascii(rhs))
Matching should support syntax like:
[1, 2] + a + [4, 5] = l
Instead of providing a recursive
decorator, recursive
should be made a keyword allowed before def
that compiles the function in a tail-recursively-optimized style.
Proposed syntax:
case to_match:
match (x, y):
print("tuple of "+str(x)+" and "+str(y))
match (x, x) if x:
print("tuple of double true value "+str(x))
Enforcing the use of
def f(x) = x
over the use of
f(x) = x
would help disambiguate with
point(x, y) = p
which right now would need to be
match point(x, y) = p
as well as help solve the problem of match function definition such as
f(x is int) = x
being parsed like
point(x is int, y is int) = p
Proposed Syntax:
def func$(x,y):
return x + y
def func$(x, y) = x + y
func = $(x, y) -> x + y
Should translate to:
def func(x):
def _coconut_curried(y):
return x + y
return _coconut_curried
func = lambda x: lambda y: x + y
New keywords async
and await
plus new operator @
.
The command.cli
object should compile each file in a separate compiler.processor
object in a separate process.
Use sys = _coconut_sys
in __coconut__
.
Not necessarily at the same points, but they would make the compiled code much more readable.
That way documentation for all versions is always available, master is always the documentation for the most recent release, and development is separate from production.
Examples include linked lists and immutable dictionaries.
Examples are enhanced decorators for normal decorators and extra checks in match statements.
Coconut's pattern-matching checks against Python's abstract base classes, allowing new classes to be registered using the normal Python abcs. This should be tested and documented.
These would be things that Python allows that Coconut discourages, such as lambda
. The syntax would be something like:
$ coconut -w lambda
or
$ coconut --warn lambda
Allow commas in except
statements to be translated into different errors to catch.
Examples:
.join => __coconut__.operator.attrgetter("join")
"". => __coconut__.functools.partial(__coconut__.getattr, "")
func$ => __coconut__.functools.partial(__coconut__.functools.partial, func)
Proposed syntax:
x = (a if c else b)
x = (a if c)
Compiles to:
if c:
coconut_if = a
else:
coconut_if = b
x = coconut_if
if c:
coconut_if = a
else:
coconut_if = None
x = coconut_if
If -o
or --optimize
is specified, optimizations should be applied that could potentially invalidate code, such as not supporting index-by-slice and removing assert
statements.
This existed in Python 2 but was removed in Python 3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.