// #include <stdio.h>
// #include <unistd.h>

// typedef int I;
// typedef char C;

// I main(){C b[99];C*s=b;while(read(0,s,98))printf("%s",s);}

That is my REPL for now, I need to create a struct to hold my arrays and allocate memory for them. As well as make a parser.

Let say I will use only Int and String type for now.
Let say array are formed like that [1,2,3] or even 1,2,3 and string are just inside "", char inside '' and a string is an array of Char.
Then I need to define some operation like + * and -
About defining variables (let say I use : so x:3 is creating the x variable and x is a int with value 3)

Arrays are the core variables in array language it could be implemented for example with:

typedef struct a {
    int32_t rank;         // number of dimensions
    int32_t *shape;       // array of dimension sizes
    void *data;           // pointer to array data
    int32_t element_size; // size of each element in bytes
} *A;

What struct should I define for arrays for it to be practical en efficient(I want to support multidimensional array, reduce, map and so on)?

There is some information about it here https://aplwiki.com/wiki/Array_model but it is all talk and no code.

I am not sure what I need for what functionality of my array language, I could use some explanation and example. If I enter a:[1,2,3] or b:[1,[2,3]] in the REPL I would like to do 2*a and get [2,4,6] or 2*b and get [2,[4,6]].

Thanks you

ps:I edited the question and removed the part about REPL variables because @kaya3 point me to a good answer.

  • 1
    $\begingroup$ This is really two separate questions, though "What is the best and most efficient struct for the arrays?" doesn't make sense to me, because an array is a data structure. The main question about REPLs seems to be answered here ─ if that's not what you're looking for, please edit to clarify. $\endgroup$
    – kaya3
    Aug 23, 2023 at 11:02
  • 3
    $\begingroup$ An "Array Programming Language" has a specific meaning and it not just a language that has arrays but is a language whose operators take arrays as arguments. Is this indeed what this is about? If, by any chance, this is a homework assignment it should be disclosed. $\endgroup$ Aug 23, 2023 at 12:52
  • 1
    $\begingroup$ You will need to enumerate what operations and capabilities you want to support and then design your internal data structures to support them. For example, slices, which are in several modern languages. $\endgroup$
    – Erik Eidt
    Aug 23, 2023 at 14:52
  • $\begingroup$ "There is some information about it here ... but it is all talk and no code." ─ any answer you get here is likely to also be "all talk and no code". If your question expects an answer that is mostly code, Stack Overflow is a better bet, but make sure to read their help pages before asking. $\endgroup$
    – kaya3
    Aug 23, 2023 at 15:14

1 Answer 1


If you do not share the data part, the most efficient layout is moving the data to the end as zero-sized array and implement the arrays with generated struct definition appending the correct array size after the common header struct.


Not the answer you're looking for? Browse other questions tagged .