<pre><code>// #include &lt;stdio.h&gt;
// #include &lt;unistd.h&gt;

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



// I main(){C b[99];C*s=b;while(read(0,s,98))printf(&quot;%s&quot;,s);}
</code></pre>
<p>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.</p>
<pre><code>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 &quot;&quot;, 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)
</code></pre>
<p>Arrays are the core variables in array language it could be implemented for example with:</p>
<pre><code>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;
</code></pre>
<p>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)?</p>
<p>There is some information about it here <a href="https://aplwiki.com/wiki/Array_model" rel="nofollow noreferrer">https://aplwiki.com/wiki/Array_model</a> but it is all talk and no <code>code</code>.</p>
<p>I am not sure what I need for what functionality of my array language, I could use some explanation and example. If I enter <code>a:[1,2,3]</code> or <code>b:[1,[2,3]]</code> in the REPL I would like to do <code>2*a</code> and get <code>[2,4,6]</code> or <code>2*b</code> and get <code>[2,[4,6]]</code>.</p>
<p>Thanks you</p>
<p>ps:I edited the question and removed the part about REPL variables because @kaya3 point me to a good answer.</p>

<language-design><implementation><arrays><pointers><apl>
Implementing a Array programming language in C. What is the best and most efficient struct for the arrays?
CC BY-SA 4.0
2023-08-23T11:02:14.307Z
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](https://langdev.stackexchange.com/q/1176/89) ─ if that's not what you're looking for, please edit to clarify.
kaya3
CC BY-SA 4.0
2023-08-23T12:52:39.987Z
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.
Christian Lindig
CC BY-SA 4.0
2023-08-23T14:52:39.807Z
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](https://en.wikipedia.org/wiki/Array_slicing), which are in several modern languages.
Erik Eidt
CC BY-SA 4.0
2023-08-23T15:14:45.923Z
*"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](http://stackoverflow.com/) is a better bet, but make sure to read their [help pages](https://stackoverflow.com/help/how-to-ask) before asking.
kaya3
<p>If you do not share the data part, the most efficient layout is moving the data to the end as zero-sized array and <em>implement</em> the arrays with generated struct definition appending the correct array size after the common header struct.</p>

CC BY-SA 4.0
2023-08-23T16:09:27.990Z
2023-08-23T16:09:27.990Z
feldentm
# Implementing a Array programming language in C. What is the best and most efficient struct for the arrays?
Posted by: username_0 on 2023-08-23
// #include 
// #include 

// 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.
**Tags:** language-design implementation arrays pointers apl
> **Comments:**
> **username_1**: 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](https://langdev.stackexchange.com/q/1176/89) ─ if that's not what you're looking for, please edit to clarify.  
> **username_2**: 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.  
> **username_3**: 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](https://en.wikipedia.org/wiki/Array_slicing), which are in several modern languages.  
> **username_1**: *"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](http://stackoverflow.com/) is a better bet, but make sure to read their [help pages](https://stackoverflow.com/help/how-to-ask) before asking.  
---
## 1 answers
### Answer by username_4 on 2023-08-23. Score: 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.
---
