diff options
author | Juan J. Martinez <jjm@usebox.net> | 2024-06-18 16:03:31 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2024-06-18 16:03:31 +0100 |
commit | 6567df27bb924d17a41b21ac012d88bfee4cbe34 (patch) | |
tree | 4d0250309f2cd287cf02cf5e7ee864d26aa58b44 | |
parent | 96362daa03ca36a94ca7c5939446f772d95229b5 (diff) | |
download | funco-6567df27bb924d17a41b21ac012d88bfee4cbe34.tar.gz funco-6567df27bb924d17a41b21ac012d88bfee4cbe34.zip |
Added index function
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | examples/sentences.fco | 6 | ||||
-rwxr-xr-x | funco | 3 |
3 files changed, 4 insertions, 6 deletions
@@ -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") @@ -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 |