Coconut – Espressioni


Ho fatto un po’ di prove e Coconut funziona 😀
Deve crescere ma mi sa che lo userò per compiti particolari ( case) intanto continuo a studiarlo, copiando qui.

Lazy lists
Coconut supports the creation of lazy lists, where the contents in the list will be treated as an iterator and not evaluated until they are needed. Lazy lists can be created in Coconut simply by simply surrounding a comma-seperated list of items with (| and |) (so-called “banana brackets”) instead of [ and ] for a list or ( and ) for a tuple.

Lazy lists use the same machinery as iterator chaining to make themselves lazy, and thus the lazy list (| x, y |) is equivalent to the iterator chaining expression (x,) :: (y,), although the lazy list won’t construct the intermediate tuples.

Lazy lists, where sequences are only evaluated when their contents are requested, are a mainstay of functional programming, allowing for dynamic evaluation of the list’s contents.


In Python can’t be done without a complicated iterator comprehension in place of the lazy list. See the compiled code for the Python syntax.
Ecco un altro caso in cui torna utile 😀

Applicazione parziale implicita
Coconut supports a number of different syntactical aliases for common partial application use cases. These are:

.attr         =>  operator.attrgetter("attr")
.method(args) =>  operator.methodcaller("method", args)
obj.          =>  getattr$(obj)
func$         =>  ($)$(func)
seq[]         =>  operator.__getitem__$(seq)
iter$[]       =>  # the equivalent of seq[] for iterators


Vuoi vedere che manca un modulo…


OK, come previsto 😀

Set Literals
Coconut allows an optional s to be prepended in front of Python set literals. While in most cases this does nothing, in the case of the empty set it lets Coconut know that it is an empty set and not an empty dictionary. Additionally, an f is also supported, in which case a Python frozenset will be generated instead of a normal set.


Imaginary Literals
In addition to Python’s <num>j or <num>J notation for imaginary literals, Coconut also supports <num>i or <num>I, to make imaginary literals more readable if used in a mathematical context.

Imaginary literals are described by the following lexical definitions:
imagnumber ::= (floatnumber | intpart) ("j" | "J" | "i" | "I")

An imaginary literal yields a complex number with a real part of 0.0. Complex numbers are represented as a pair of floating point numbers and have the same restrictions on their range. To create a complex number with a nonzero real part, add a floating point number to it, e.g., (3+4i). Some examples of imaginary literals:
3.14i   10.i    10i     .001i   1e100i  3.14e-10i


Underscore Separators
Coconut allows for one underscore between digits and after base specifiers in numeric literals. These underscores are ignored and should only be used to increase code readability. Comodo, pochi linguaggi lo usano, Ada.




Posta un commento o usa questo indirizzo per il trackback.



Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo di

Stai commentando usando il tuo account Chiudi sessione /  Modifica )

Google photo

Stai commentando usando il tuo account Google. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

Connessione a %s...

Questo sito utilizza Akismet per ridurre lo spam. Scopri come vengono elaborati i dati derivati dai commenti.

%d blogger hanno fatto clic su Mi Piace per questo: