Mustafif / MufiZ

Mufi Lang with Ziggyness
GNU General Public License v2.0
1 stars 0 forks source link

Indexing syntax for Mufi Lang Arrays/FVec #22

Open Mustafif opened 2 months ago

Mustafif commented 2 months ago

We hope to introduce native indexing for arrays and float vectors, since we still have pending work on Matrix, and many things can change with that, its better to bring the initial support for arrays/float vectors.

Syntax:

We will follow similar to Matlab, and reduces the need for extra tokens to declare.

var first_element = arr(0);

Stack Representation:

We will need to introduce a new instruction OP_INDEX that will be when we have an indexable type ObjArray/FloatVector on the left, follow by Left Paten, an integer constant, then right parent.

So we expect:

<indexable> (   <int const> ) => get mutable ref to indexable 

First thing to figure out, how can we reproduce this by the following:

var a = array(5);
push(a, 1, 2, 3, 4, 5);

nth(a, 0) = 201;

Once we can make this possible, then we can have the same behaviour called to the OP_INDEX instruction

Mustafif commented 2 months ago

Further details were explained in https://mufiz.hashnode.dev/indexing-proposal-in-jade-release

Mustafif commented 2 months ago

Initial support of indexing for setting and getting is at https://github.com/Mustafif/MufiZ/commit/b581abda6fcb09608434c17d89ef6401cd60490d