diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2014-11-17 01:19:21 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2014-11-17 01:19:21 -0800 |
commit | 08b48a8d56e6e683a1d3bfa118334b48937b12bd (patch) | |
tree | fb735473dde29499a42c24181b28dfcce251532c | |
parent | ea36397b5010be4d79dcb07be5ed2b3b84217040 (diff) | |
download | mu-08b48a8d56e6e683a1d3bfa118334b48937b12bd.tar.gz |
268 - recursive function: factorial
Is this really harder to reason about by being somehow 'operational' and 'abstraction free'? http://cacm.acm.org/magazines/2010/8/96632-an-interview-with-edsger-w-dijkstra/fulltext
-rw-r--r-- | factorial.mu | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/factorial.mu b/factorial.mu new file mode 100644 index 00000000..25ab1eba --- /dev/null +++ b/factorial.mu @@ -0,0 +1,15 @@ +(factorial + ((default-scope scope-address) <- new (scope literal) (30 literal)) + ((n integer) <- arg) + { begin + ((zero? boolean) <- eq (n integer) (0 literal)) + (break-unless (zero? boolean)) + (reply (1 literal)) + } + ((x integer) <- sub (n integer) (1 literal)) + ((subresult integer) <- factorial (x integer)) + ((result integer) <- mul (subresult integer) (n integer)) + (reply (result integer))) + +(main + ((1 integer) <- factorial (5 literal))) |