From 396543790dc1c844c726b77a95c6180978232abd Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Fri, 14 Jan 2022 01:06:14 +0000 Subject: =?UTF-8?q?Add=20each=20(=C2=A8)=20operator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- array.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'array.c') diff --git a/array.c b/array.c index a2afc44..4a14ab9 100644 --- a/array.c +++ b/array.c @@ -78,4 +78,23 @@ scalarextend(Array *a, Array *b, Array **aa, Array **bb) }else return 0; return 1; +} + +Array * +arrayitem(Array *a, int index) +{ + Array *res = nil; + switch(a->type){ + case AtypeInt: + res = mkscalarint(a->intdata[index]); + break; + case AtypeArray: + res = a->arraydata[index]; + incref(res); + break; + default: + print("Unhandled case in arrayitem()\n"); + exits(nil); + } + return res; } \ No newline at end of file -- cgit v1.2.3