Download presentation
Presentation is loading. Please wait.
1
Coconut Sandor aguilar
2
What is Coconut? Open source derivative of Python
Introduces friendlier functional programming to Python by adding built-in syntactical support Compiles to Python Unique in that it is Python version agnostic Works ALMOST the same on any version of Python “
3
Why Coconut? “… if you look at the top 20 most popular programming languages, not a single one is functional. But there are functional alternatives to a lot of them. Java has Scala. C# has F#. Python has ... nothing.” - Evan Hubinger, creator of Coconut
4
Pipeline and Lambdas Pipeline style programming Prettier Lambdas
“Hello, World!” |> print instead of print(“Hello, World!) In Coconut for multiple argument: def sq(x) = x** (1, 2) |*> (+) |> sq |> print In Python: import operator def sq(x): return x** print(sq(operator.add(1, 2))) Prettier Lambdas (x) -> x**2 instead of lamda x: x**2 In Python: map(lambda x: x * x, [0, 1, 2, 3, 4]) In Coconut: map(x -> x*x, [0, 1, 2, 3, 4]) |> list
5
Partial Application and Infix
Partial Application (i.e. currying) In Coconut: range(5) |> map$((x) -> x*2) |> list produces [0, 2, 4, 6, 8] In Python: import functools print(map(functools.partial(lambda x: x*2), range(5))) Infix notation def a `mod` b = a % b 5 ‘mod’ 3 == 2
6
Lazy Lists and Pattern Matching
In Coconut: (| range(100) |> list |) In Python: Need to import python package Destructing Assignment {”list”: [0] + rest} = {“list”: [0, 1, 2, 3]} rest = [1, 2, 3] Pattern matching match [head] + tail in [0, 1, 2, 3]: print(head, tail) produces [1, 2, 3] 0
7
And More Parallel programming Tail recursion optimization
range(10) |> parallel_map$( (**)$(2)) |> list produces [1, 2, 4, 8, 16, 32, 64, 128, 256, 512] Tail recursion optimization
8
Further Information Coconut Documentation: Coconut Tutorial: Coconut Github repository:
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.