aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2024-05-26 21:22:40 +0100
committerJuan J. Martinez <jjm@usebox.net>2024-05-26 21:22:40 +0100
commit00680c131470b7f14243cdc3271fb302d8cfc4f7 (patch)
tree8fddf0c68eb7e29f8941917d694909f8b302199e
parent3283d727e74c3812efd19102cccbd4dd08684e92 (diff)
downloadfunco-00680c131470b7f14243cdc3271fb302d8cfc4f7.tar.gz
funco-00680c131470b7f14243cdc3271fb302d8cfc4f7.zip
A range function
-rw-r--r--README.md1
-rwxr-xr-xfunco3
2 files changed, 4 insertions, 0 deletions
diff --git a/README.md b/README.md
index fa84f62..316f5bf 100644
--- a/README.md
+++ b/README.md
@@ -103,6 +103,7 @@ Other built-in functions are:
* `take(n list)`: return the first n elements of a list
* `drop(n list)`: return the list dropping the n first elements
* `display(value)`: prints its arguments to the screen, for example `display("hello" "world")`
+* `..(i j)`: generate a list of integers from i to j
See the examples in `./examples`.
diff --git a/funco b/funco
index 55e22ab..0c27211 100755
--- a/funco
+++ b/funco
@@ -411,6 +411,9 @@ def default_env():
"take": lambda n, xs: xs[:n],
"drop": lambda n, xs: xs[n:],
"display": print,
+ "..": lambda f, t: list(range(f, t + 1, 1) if f < t else range(f, t - 1, -1)) if (
+ isinstance(f, int) and isinstance(t, int)
+ ) else None
}
)
return env