Wiki: Coconut
GitHub: edit | view

General

All tips on the Python wiki page also apply to Coconut.

Documentation for Coconut is available here 🥥.

Functions

Use implicit function application (f x instead of f(x)) when every parameter is represented by a variable or constant value, with the exception of string literals.

print(100)
print 100

c="Coconuts"
print(42,c)
print 42c

Use infix representation for functions with two parameters.

print(42,"Coconuts")

42`print`"Coconuts"

Use the implicit form of the => operator in anonymised lambdas with one parameter (can be accessed via _).

*map(x=>print(x+21),range 5)

*map(=>print(_+21),range 5)

Integer coefficients

When multiplying an integer literal and a variable, * can be omitted, such as 2x instead of 2*x.

Arguments

There is no need to import sys to get the list of arguments, as it's possible to access it via an already imported module os.

import sys;*map(print,sys.argv)

*map(print,os.sys.argv)

Coconut provides a few other modules without import, as well as several modules not part of the standard library.

Unicode operators

Some operators have unicode alternatives that could be useful for chars scoring, full list here