SRL Archive - Suggestions

Add..Arrays


Shuttleu

2010-07-29 15:52:06

i made these functions because i needed them but found no function that could do it for me, i also couldnt find a way to return the same trype of array that was put in
function AddStringArrays(Array1, Array2: TStringArray): TStringArray;
var
x, y, z: Integer;
begin
x:= Length(Array1);
y:= Length(Array2);
SetArrayLength(Result, x+y);

for z:= 0 to High(Array1) do
Result[z]:= Array1[z];

for z:= 0 to y-1 do
Result[(x+y)-(y-z)]:= Array2[z];
end;

function AddExtendedArrays(Array1, Array2: TExtendedArray): TExtendedArray;
var
x, y, z: Integer;
begin
x:= Length(Array1);
y:= Length(Array2);
SetArrayLength(Result, x+y);

for z:= 0 to High(Array1) do
Result[z]:= Array1[z];

for z:= 0 to y-1 do
Result[(x+y)-(y-z)]:= Array2[z];
end;

function AddBooleanArrays(Array1, Array2: TBooleanArray): TBooleanArray;
var
x, y, z: Integer;
begin
x:= Length(Array1);
y:= Length(Array2);
SetArrayLength(Result, x+y);

for z:= 0 to High(Array1) do
Result[z]:= Array1[z];

for z:= 0 to y-1 do
Result[(x+y)-(y-z)]:= Array2[z];
end;
i probably forgot a couple :redface:

~shut

MylesMadness

2010-07-29 15:54:50

CombineIntArray
CombineTPA?

Heavenguard

2010-07-29 15:55:18

^^ Was about to say that, but they look entirely useful. Great job dude.

Shuttleu

2010-07-29 15:55:29

From: MylesMadness
CombineIntArray
CombineTPA?


wha?! where are they, i looked for them for ages!!!

~shut

MylesMadness

2010-07-29 15:55:52

In wizzyplugin

Shuttleu

2010-07-29 15:56:58

what about the string and extended ones?

~shut

MylesMadness

2010-07-29 15:58:01

Those don't exist, so those were nice to make.

Shuttleu

2010-07-29 16:01:22

:), well i might as well remove the integer and tpoint ones then

~shut

Nava2

2010-07-29 17:19:25

I wish we could overload operators..

Coh3n

2010-07-29 18:49:33

Shut, there's a search bar at the bottom of the Simba function list that searches through all the functions you have included (plus the MML ones).

Shuttleu

2010-07-29 18:52:13

From: Coh3n
Shut, there's a search bar at the bottom of the Simba function list that searches through all the functions you have included (plus the MML ones).


well thats another small little useful feature that i never knew about… :/

wish i knew about it earlier, thanks

~shut

Coh3n

2010-07-29 19:02:14

From: Shuttleu
well thats another small little useful feature that i never knew about… :/

wish i knew about it earlier, thanks

~shut

No problem. I just found it a couple days ago myself. :p It's quite handy.

MylesMadness

2010-07-29 19:42:57

From: Coh3n
Shut, there's a search bar at the bottom of the Simba function list that searches through all the functions you have included (plus the MML ones).
Wtfhax. Thats sweet

Method

2010-07-29 19:44:49

It seems like you have some unnecessary arithmetic in the Result calculation.

Result[(x+y)-(y-z)]:= Array2[z];

could be

Result[x + z]:= Array2[z];

nielsie95

2010-07-30 17:19:05

I guess we could overload the operators, but it'd require hacking the engine. (un)equal operator would be nice too. For records it's easy to do the above, so I guess arrays aren't that hard either.

Nava2

2010-07-30 20:06:04

From: nielsie95
I guess we could overload the operators, but it'd require hacking the engine. (un)equal operator would be nice too. For records it's easy to do the above, so I guess arrays aren't that hard either.


So you think this could be done? I'm not sure what the function of `-' would be though, adding is obvious enough.

nielsie95

2010-07-30 21:37:23

You don't have to support everything :)

EvilChicken!

2010-07-30 23:05:04

Overloading support would be awesome, I've wished for that quite a lot of times!

E: By "support", I just meant that the engine would support overloading.

nielsie95

2010-08-02 11:14:19

I wouldn't be overloading support, it would be an addition to the scripting engine.

nielsie95

2010-08-06 09:49:53


program new;
var
a, b, c: TPointArray;
begin
a := [Point(1, 2), Point(3, 4)];
b := [Point(5, 6)];
WriteLn(a = b);
c := a + b;
WriteLn(c);
WriteLn(c = a + b);
end.


Compiled succesfully in 15 ms.
False
[(1, 2), (3, 4), (5, 6)]
True
Successfully executed.

Added some basic support. Still needs to be tested and static arrays need to be added. Anybody feel like writing a file with test cases that should work/compile?

nielsie95

2010-08-07 10:00:58

I was thinking, array + 1 could expand the length with 1 (same story for -) and "not" could delete an index? There are lots of possibilities, but I'm not sure how far we want to go.. All these features can be made in separate (exported) functions too.

Another thought: "in" can be made to check if a value exists in an array(or record or string?).
What do you think of all this? Do? Don't? Stop with adding arrays? Another idea?

Nava2

2010-08-07 10:39:07

I love the `in' keyword. Very python like. :)
Also `not in' would be nice too :p

I was thinking Array += X would add X to the array, but I think thats too far as assignment operators are not present yet.

nielsie95

2010-08-07 10:42:50

+ could also mean add X to array and the "and" keyword could combine them?

Nava2

2010-08-07 15:12:02

When you concatenate two arrays though, you are essentially just adding all the different parts of the arrays.

Shuttleu

2010-08-30 18:44:45

From: nielsie95

program new;
var
a, b, c: TPointArray;
begin
a := [Point(1, 2), Point(3, 4)];
b := [Point(5, 6)];
WriteLn(a = b);
c := a + b;
WriteLn(c);
WriteLn(c = a + b);
end.


Compiled succesfully in 15 ms.
False
[(1, 2), (3, 4), (5, 6)]
True
Successfully executed.

Added some basic support. Still needs to be tested and static arrays need to be added. Anybody feel like writing a file with test cases that should work/compile?


has this actually been added?
or is it in the latest unstable release?

~shut

Tniffoc

2010-08-30 23:24:42

Well personally, I think that the '+' operator on arrays would be more useful as adding them in terms of matrices but that's just me.

I.E.

[[3,4,5], [[1,2,3],
[6,7,8]] + [4,5,6]] =

[[4,6,8],
[10,12,14]]

This would be very useful for solving some simpler algebraic problems.

This would also go for the other operators '*' '/' '-' etc.

Note that multiplying matrices is not as simple as one would imagine. Nor is dividing for that matter.

Wizzup?

2010-08-31 12:30:07

From: Shuttleu
has this actually been added?
or is it in the latest unstable release?

~shut


It'll be added in the next build.

Shuttleu

2010-08-31 15:31:37

From: Wizzup?
It'll be added in the next build.


thank you a million!

~shut

nielsie95

2010-08-31 16:21:05

It still hasn't been properly tested, nor static array support has been added, as far as I know?

Wizzup?

2010-08-31 17:00:29

From: nielsie95
It still hasn't been properly tested, nor static array support has been added, as far as I know?


Well it lives in the current source master branch, so I assumed it would be in in the next build. :redface: