Skip to content

Commit

Permalink
Improves formatting for RTD, adds more tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
evhub committed Jan 26, 2016
1 parent 0d4d577 commit 3ae9cdc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
26 changes: 26 additions & 0 deletions HELP.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ Although the imperative approach is a fundamentally ugly method, Python does a s

### Recursive Method

Recursion is one of the most fundamental tools of functional programming, and is thus a place where Coconut can really help clear up confusing code. Here's the recursive approach in pure Python:

```python
def factorial(n):
"""Compute n! where n is an integer >= 0."""
if n == 0:
return 1
elif isinstance(n, int) and n > 0:
return n * factorial(n-1)
else:
raise TypeError("the argument to factorial must be an integer >= 0")
```

```python
def factorial(n):
"""Compute n! where n is an integer >= 0."""
Expand All @@ -219,6 +232,19 @@ def factorial(n):
raise TypeError("the argument to factorial must be an integer >= 0")
```

```python
@recursive
def factorial(n, acc=1):
"""Compute n! where n is an integer >= 0."""
case n:
match 0:
return acc
match n is int if n > 0:
return factorial(n-1, acc*n)
else:
raise TypeError("the argument to factorial must be an integer >= 0")
```

### Iterative Method

```python
Expand Down
12 changes: 6 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Coconut
=======

.. toctree::
:maxdepth: 3

HELP
DOCS

Coconut_ is a variant of Python_ built for **simple, elegant, Pythonic functional programming**.

Coconut is hosted on PyPI_, where it has been downloaded `over 20,000 times <http://pypi-ranking.info/module/coconut>`_. Installing Coconut is as easy as:
Expand All @@ -22,12 +28,6 @@ Coconut is completely open-source, and new contributors are always welcome. Cont
.. _Docs: http://coconut.readthedocs.org/en/master/DOCS.html
.. _GitHub: https://github.com/evhub/coconut

.. toctree::
:maxdepth: 3

HELP
DOCS

Coconut in Action
-----------------

Expand Down

0 comments on commit 3ae9cdc

Please sign in to comment.