aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2024-06-18 16:05:47 +0100
committerJuan J. Martinez <jjm@usebox.net>2024-06-18 16:05:47 +0100
commit976fe910d3fa77909d847ab32e21c1627fed97ab (patch)
tree38c955905647605c35c5e2b117c3639dbbf8c4be
parent6567df27bb924d17a41b21ac012d88bfee4cbe34 (diff)
downloadfunco-976fe910d3fa77909d847ab32e21c1627fed97ab.tar.gz
funco-976fe910d3fa77909d847ab32e21c1627fed97ab.zip
Added last function
-rw-r--r--README.md1
-rw-r--r--examples/sentences.fco2
-rwxr-xr-xfunco3
3 files changed, 4 insertions, 2 deletions
diff --git a/README.md b/README.md
index 68e4fbf..6106026 100644
--- a/README.md
+++ b/README.md
@@ -90,6 +90,7 @@ Other built-in functions are:
* `function?(value)`: returns true if a value is a function
* `head(list)`: returns the first element of a list
* `tail(list)`: returns the end of a list excluding the first element
+* `last(n)`: get last item of n (for lists and strings)
* `empty?(list)`: returns true if a list is empty
* `size(list)`: returns the size of a list or a string
* `min(list)`: returns the smaller value in a list
diff --git a/examples/sentences.fco b/examples/sentences.fco
index 6b6e448..91aa3bd 100644
--- a/examples/sentences.fco
+++ b/examples/sentences.fco
@@ -3,7 +3,7 @@
def classify(xs)
def sentence_type(s)
def ends_with?(s c)
- =([](s -(size(s) 1)) c)
+ =(last(s) c)
end
if ends_with?(s "?")
+(s " -> Q")
diff --git a/funco b/funco
index 808483a..bf40a12 100755
--- a/funco
+++ b/funco
@@ -428,7 +428,8 @@ def default_env():
"..": 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,
- "[]": lambda i, n: i[n]
+ "[]": lambda i, n: i[n],
+ "last": lambda i: i[-1]
}
)
return env