Syntax for arrays?
I'm a little confuzzled on what my syntax for my language should be. Mainly when it comes to arrays.
I don't know if I want predefined functions, or built in syntax. Like this:
The built in syntax definitely looks shorter, but it doesn't really look clean when you're working with an r-value array:
I personally prefer the built in functions for r-value arrays, but the built in syntax for variables.
So which one should I chose? I can't do both
Totally random, but I barely remembered this.
You might be interested in this piece of knowledge since you're making an interpreted, memory-managed language.
Some random search results:
The concept can be applied to arrays as well as strings.
@DynamicSquid I had already conceptually thought of the idea before, but I guess it already existed, and it had a name, and it was already in use.
I guess my thoughts aren't that original :(
Data structures are weird at times, I've heard of plenty, but there's an infinite more that exist.
I think dynamically reallocating arrays is just a bad idea.
Unless... you implement arrays as linked lists, in which case I recommend syntax.
@DynamicSquid Nevermind, the first 'S' in SLL threw me off.
It depends, you can save memory depending on the specific situation.
Usually, you might lose on memory though.
Appending and prepending are always very fast operations.
Iterating is slow.
Take, for example, concatenation between three arrays, ex:
If you were required to have contiguous blocks of memory, then you would have to allocate memory by summing the lengths of all of the individual arrays, then copy the memory into the new array, and assign the variable.
If instead, it was implemented as SLL or DLL, you would simply modify the value that the first array pointed to, and so on. No copies, no reallocations, no variable reassignment.
But I hear that, for complex, performance-critical operations, the performance is terrible.
Ex: Haskell uses LL strings and is a compiled language, but, Python uses blocks, and is interpreted, yet is more performant.
@fuzzyastrocat Now that's where things change.
If you include the length as part of the type, then it is an intricate part of the type, you cannot accept
int in place of an
C/C++ already have this concept though:
At that point, you might as well just degrade to using pointers.
In C, it would just automatically cast to a pointer if the function accepts
In a strongly typed language, the case would have to be explicit, likely through slicing, which is what I intend to do.
Entirely depends on your language paradigm. If it's OO in some capacity then builtin functions is the way to go. If it's not, then the custom syntax might be a better option. However, even if your language isn't OO you could also make it so that
x.y(<params>) is sugar for
You could also go haskell-style and make it so that custom syntax is basically just defining another function. I really like approaches like this since custom syntax is so arbitrary and not extendable.
well, it depends on your paradigm, I would definitely go for classes
make sure your arrays aren't pointers that is all
I'd say built in tbh. It is just so much easier and will become less of a hassle on behalf of the people using your language.
You don't wanna be like C where you need to literally create your own concept of arrays.
Also, Good job on your language. You should attempt to convert it into a compiled language over time! It sure would be a cool compiled language!
@MocaCDeveloper Oh, it's not C like at all! I think I forgot to update you on this, but for version 4 (coming soon), Night's going to be dynamically typed. It's also going to be really similar to Python, but it will have compile time checks making it safer.
So basically Python but it's safe
@MocaCDeveloper Oh, I meant that this language would interpreted, but I'll make another language and that language will be compiled, so I'll have two languages, one interpreted (this one), and one compiled.
And yeah, I'm shifting the concept of the language. I think that now with my language being interpreted and dynamically typed I'll stick to that. I kind of want to make something like Python, but like I said a major difference is the safety.
@MocaCDeveloper Nope, they'll all be inferred automatically.
Variables use the
And functions use the
It's going to be hard to implement type checking for function parameters at compile time, but I think that's doable (I think)
Edit: Oh whoops forgot, there's no semicolons
Ye I've attempted to do it 3 times lol and I gave up. I'm sure you'll be able to do just fine though. You have a better attention span than me!
Also, stop copying my idea BRO. Me and @realTronsi were creating a language one time and we were going to use the set keyword as a variable declaration like seriously bro stop copying us lol
Lol no me and @realTronsi literally just run together on repl and do a whole bunch of coding projects together.
I seriously don't know where this friendship started between me and him but uhh ye we just tend to work together allot and manage to just talk to each other on literally everyones post lol
Also, stair sis is a inside joke. Don't ask how we came up with it lol