From 1f1efaebb27f712e250f4546f48fb5c00f40e558 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Thu, 10 Jul 2025 15:41:04 -0400 Subject: [PATCH] add last_n function to prelude --- assets/prelude.ld | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/assets/prelude.ld b/assets/prelude.ld index 3f10d23..9450709 100644 --- a/assets/prelude.ld +++ b/assets/prelude.ld @@ -854,6 +854,12 @@ fn slice_n { (str as :string, start as :number, n as :number) -> slice (str, start, add (start, n)) } +fn last_n { + "Returns a list or string containing the last n elements of a list or string." + (xs as :list, n as :number) -> slice_n (xs, sub (count (xs), n), n) + (str as :string, n as :number) -> slice_n (str, sub (count (str), n), n) +} + fn butlast { "Returns a list, omitting the last element." (xs as :list) -> slice (xs, 0, dec (count (xs))) @@ -1609,6 +1615,7 @@ fn key_down? { keys_down keyword? last + last_n left! link! list