From 7a6f975dc77608f01570c7710ce9342776437985 Mon Sep 17 00:00:00 2001 From: Peter Mikkelsen Date: Fri, 28 Jan 2022 19:15:22 +0000 Subject: =?UTF-8?q?Extend=20monadic=20=E2=8D=B3=20to=20work=20with=20lists?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'functions.c') diff --git a/functions.c b/functions.c index 3b32cca..1479af0 100644 --- a/functions.c +++ b/functions.c @@ -571,14 +571,24 @@ fnGradeDown(Array *right) Array * fnIndexGenerator(Array *right) { - /* TODO only works for creating vectors */ - vlong n = right->intdata[0]; - Array *res = allocarray(AtypeInt, 1, n); - res->shape[0] = n; - vlong io = globalIO(); - for(vlong i = 0; i < n; i++) - res->intdata[i] = i + io; - return res; + Array *result = nil; + if(right->rank == 0){ + vlong n = right->intdata[0]; + if(n < 0) + throwerror(nil, EDomain); + result = allocarray(AtypeInt, 1, n); + result->shape[0] = n; + vlong io = globalIO(); + for(vlong i = 0; i < n; i++) + result->intdata[i] = i + io; + }else if(right->rank == 1){ + if(right->size == 0) + return rundfn(L"⊂⍬", nil, nil, nil, nil); + else + result = rundfn(L"↑,⌾⌿⍳¨⍵", nil, nil, nil, right); + }else + throwerror(nil, ERank); + return result; } Array * -- cgit v1.2.3