From 00680c131470b7f14243cdc3271fb302d8cfc4f7 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 26 May 2024 21:22:40 +0100 Subject: A range function --- README.md | 1 + funco | 3 +++ 2 files changed, 4 insertions(+) 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 -- cgit v1.2.3