aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2024-06-18 16:03:31 +0100
committerJuan J. Martinez <jjm@usebox.net>2024-06-18 16:03:31 +0100
commit6567df27bb924d17a41b21ac012d88bfee4cbe34 (patch)
tree4d0250309f2cd287cf02cf5e7ee864d26aa58b44
parent96362daa03ca36a94ca7c5939446f772d95229b5 (diff)
downloadfunco-6567df27bb924d17a41b21ac012d88bfee4cbe34.tar.gz
funco-6567df27bb924d17a41b21ac012d88bfee4cbe34.zip
Added index function
-rw-r--r--README.md1
-rw-r--r--examples/sentences.fco6
-rwxr-xr-xfunco3
3 files changed, 4 insertions, 6 deletions
diff --git a/README.md b/README.md
index dd6fb76..68e4fbf 100644
--- a/README.md
+++ b/README.md
@@ -102,6 +102,7 @@ Other built-in functions are:
* `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
+* `\[](l n)`: get item n in l (n is zero based)
See the examples in `./examples`.
diff --git a/examples/sentences.fco b/examples/sentences.fco
index afb2d4f..6b6e448 100644
--- a/examples/sentences.fco
+++ b/examples/sentences.fco
@@ -3,11 +3,7 @@
def classify(xs)
def sentence_type(s)
def ends_with?(s c)
- if =(tail(s) "")
- =(s c)
- else
- @ends_with?(tail(s) c)
- end
+ =([](s -(size(s) 1)) c)
end
if ends_with?(s "?")
+(s " -> Q")
diff --git a/funco b/funco
index 86da6a6..808483a 100755
--- a/funco
+++ b/funco
@@ -427,7 +427,8 @@ def default_env():
"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
+ ) else None,
+ "[]": lambda i, n: i[n]
}
)
return env