Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using ++ #157

Merged
merged 3 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/random/RandLC.sac
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ RandLC create_randlc(double x,double a)
t23 = 1d;
t46 = 1d;

for (i=0; i<23; i++){
for (i = 0; i < 23; i = _add_SxS_(i, 1)) {
r23 = 0.5d * r23;
t23 = 2d * t23;
}

for (i=0;i<46;i++){
for (i = 0; i < 46; i = _add_SxS_(i, 1)) {
r46 = 0.5d * r46;
t46 = 2d * t46;
}
Expand Down
24 changes: 12 additions & 12 deletions src/stdio/ListIO.sac
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ void fprint( File &stream, list L, int ElemsPerLine)
while ((! empty( L)) && (cnt < ElemsPerLine)) {
File::fprintf( stream, ": %d ", hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
while (! empty( L)) {
File::fprintf( stream, "\n");
cnt = 0;
while ((! empty( L)) && (cnt < ElemsPerLine)) {
File::fprintf( stream, ": %d ", hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
}
}
Expand All @@ -191,15 +191,15 @@ void fprint( File &stream, list L, int ElemsPerLine, int ColWidth)
while ((! empty( L)) && (cnt < ElemsPerLine)) {
File::fprintf( stream, ": %*d ", ColWidth, hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
while (! empty( L)) {
File::fprintf( stream, "\n");
cnt = 0;
while ((! empty( L)) && (cnt < ElemsPerLine)) {
File::fprintf( stream, ": %*d ", ColWidth, hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
}
}
Expand Down Expand Up @@ -239,15 +239,15 @@ void fprint( TermFile &stream, list L, int ElemsPerLine)
while ((! empty( L)) && (cnt < ElemsPerLine)) {
TermFile::fprintf( stream, ": %d ", hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
while (! empty( L)) {
TermFile::fprintf( stream, "\n");
cnt = 0;
while ((! empty( L)) && (cnt < ElemsPerLine)) {
TermFile::fprintf( stream, ": %d ", hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
}
}
Expand All @@ -268,15 +268,15 @@ void fprint( TermFile &stream, list L, int ElemsPerLine, int ColWidth)
while ((! empty( L)) && (cnt < ElemsPerLine)) {
TermFile::fprintf( stream, ": %*d ", ColWidth, hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
while (! empty( L)) {
TermFile::fprintf( stream, "\n");
cnt = 0;
while ((! empty( L)) && (cnt < ElemsPerLine)) {
TermFile::fprintf( stream, ": %*d ", ColWidth, hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
}
}
Expand Down Expand Up @@ -316,15 +316,15 @@ void print( list L, int ElemsPerLine)
while ((! empty( L)) && (cnt < ElemsPerLine)) {
TermFile::printf( ": %d ", hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
while (! empty( L)) {
TermFile::printf( "\n");
cnt = 0;
while ((! empty( L)) && (cnt < ElemsPerLine)) {
TermFile::printf( ": %d ", hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
}
}
Expand All @@ -345,15 +345,15 @@ void print( list L, int ElemsPerLine, int ColWidth)
while ((! empty( L)) && (cnt < ElemsPerLine)) {
TermFile::printf( ": %*d ", ColWidth, hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
while (! empty( L)) {
TermFile::printf( "\n");
cnt = 0;
while ((! empty( L)) && (cnt < ElemsPerLine)) {
TermFile::printf( ": %*d ", ColWidth, hd( L));
L = tl( L);
cnt++;
cnt = _add_SxS_(cnt, 1);
}
}
}
Expand Down
25 changes: 13 additions & 12 deletions src/structures/ArrayFormat.xsac
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ char[d:shp,m] format(bool[d:shp,n] arr)
| m == max(2 * n - 1, 0)
{
res = { iv -> arr[iv] ? ['1', ' '] : ['0', ' '] };
res = reshape(shp ++ [2 * n], res);
lastcol = genarray([d], 0) ++ [-1];
res = reshape(_cat_VxV_(shp, [2 * n]), res);
lastcol = _cat_VxV_(genarray([d], 0), [-1]);
res = drop(lastcol, res);
return res;
}
Expand Down Expand Up @@ -151,7 +151,7 @@ char[+] format(int[d:shp,n] arr)
zcols = sum(widths + 1) - 1;

res = { [i] -> formatrow(widths, m[i]) | [i] < [shpp] };
res = reshape(shp ++ [zcols], res);
res = reshape(_cat_VxV_(shp, [zcols]), res);
}

return res;
Expand Down Expand Up @@ -369,7 +369,7 @@ char[+] format(double[d:shp,n] arr, int precision)

res = { [i] -> alignrow(fry, i, widths, lodp, lodpmax, zcols)
| [i] < [shpp] };
res = reshape(shp ++ [zcols], res);
res = reshape(_cat_VxV_(shp, [zcols]), res);
}

return res;
Expand Down Expand Up @@ -412,7 +412,8 @@ char[+] format(double[d:shp] arr, int[2] w)
{
res = { iv -> format(arr[iv], w) | iv < shp };
zshp = shape(res);
zshp = drop([-2], zshp) ++ [prod(take([-2], zshp))];
zshp = _cat_VxV_(drop([-2], zshp),
[prod(take([-2], zshp))]);
res = reshape(zshp, res);
return res;
}
Expand All @@ -438,12 +439,12 @@ char[olen] formatrow(int[vlen] wid, int[vlen] arr)

// Can't use WL because widths may differ
sink = 0;
for (i = 0; i < vlen; i++) {
for (i = 0; i < vlen; i = _add_SxS_(i, 1)) {
w = [wid[i], 1];
curz = format(arr[i], w);
lim = shape(curz)[0];

for (src = 0; src < lim; src++) {
for (src = 0; src < lim; src = _add_SxS_(src, 1)) {
res = modarray(res, src + sink, curz[src]);
}

Expand Down Expand Up @@ -511,7 +512,7 @@ char[zcols] alignrow(char[.,.] fry, int i, int[cols] widths,
res = genarray([zcols], ' ');

zci = 0;
for (ci = 0; ci < cols; ci++) {
for (ci = 0; ci < cols; ci = _add_SxS_(ci, 1)) {
fi = ci + cols * i; // Source item index
sc = lodp[fi] - lodpmax[ci]; // Shift count to align decimal
sefe = thCharsTo([' ', ' '], fry[fi]);
Expand Down Expand Up @@ -553,7 +554,7 @@ int thCharsTo(char[n] ch, char[lim] fry)
| n > 1
{
res = lim;
for (i = 0; i < lim; i++) {
for (i = 0; i < lim; i = _add_SxS_(i, 1)) {
if (fry[i] == ch[0] || fry[i] == ch[1]) {
res = i;
i = lim;
Expand All @@ -574,9 +575,9 @@ inline
char[d], int thrnAppend(char[d] vec, int sink, char[n] arr)
{
res = vec;
for (src = 0; src < n; src++) {
for (src = 0; src < n; src = _add_SxS_(src, 1)) {
res[sink] = arr[src];
sink++;
sink = _add_SxS_(sink, 1);
}

return (res, sink);
Expand Down Expand Up @@ -611,7 +612,7 @@ char[.] killPlusSign(char[n] arr)
{
res = arr;
sink = 1;
for (src = 1; src < n; src++) {
for (src = 1; src < n; src = _add_SxS_(src, 1)) {
res[sink] = arr[src];
sink += toi(res[sink] != '+');
}
Expand Down
9 changes: 5 additions & 4 deletions src/structures/StringArray.sac
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ stringArray modarray(stringArray arr, int[n] idx, stringArray val)
o, indices = getIndices(val_shp);
for (i = 0; i < o; i += 1) {
selection = Array::sel([i], indices);
modarrayidx = idx Array::++ selection;
modarrayidx = _cat_VxV_(idx, selection);
modArrVal = _sel(Array::sel([i], indices), val);
res = _modarray(res, modarrayidx, modArrVal);
}
Expand Down Expand Up @@ -120,7 +120,8 @@ stringArray sel(int[n] idx, stringArray arr)
for (i = 0; i < o; i += 1) {
res = modarray(res,
Array::sel([i], indices),
sel(idx Array::++ Array::sel([i], indices), arr));
sel(_cat_VxV_(idx, Array::sel([i], indices)),
arr));
}
}
else {
Expand Down Expand Up @@ -150,7 +151,7 @@ stringArray to_stringArray(string s)

stringArray genarray(int[.] shp, stringArray s)
{
new_shp = shp Array::++ shape(s);
new_shp = _cat_VxV_(shp, shape(s));
res = _to_stringArray(new_shp, "");

o, indices = getIndices(shp);
Expand Down Expand Up @@ -214,7 +215,7 @@ stringArray ++(stringArray m1, stringArray m2)

m1Len = Array::sel([0], shape(m1));
m2Len = Array::sel([0], shape(m2));
resShape = [m1Len + m2Len] Array::++ m1InnerShape;
resShape = _cat_VxV_([m1Len + m2Len], m1InnerShape);
res = genarray(resShape, to_stringArray(""));

for (i = 0; i < m1Len; i += 1) {
Expand Down
9 changes: 5 additions & 4 deletions src/utrace/UTrace.sac
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ void indentedShow(a[d:shp] arr) \
' '); \
carr = format(arr); \
ext_carr = with { \
(. <= iv <= . ) : spaces Array::++ carr[iv]; \
(. <= [i] <= . ) : Array::++(spaces, carr[[i]]); \
} : genarray(drop([-1], shape(carr)), \
(spaces Array::++ genarray(take([-1], shape(carr)), ' '))); \
Array::++(spaces, \
genarray(take([-1], shape(carr)), ' '))); \
\
show(ext_carr); \
incIndent(offset, strlen(cshape) + 16); \
Expand All @@ -43,8 +44,8 @@ void indentedShow(a[n,m] arr) \
spaces = genarray([getIndent() + getIndent(offset)], ' '); \
carr = format(arr); \
ext_carr = { [i] -> _eq_SxS_(i, 0) \
? carr[[i]] Array::++ spaces \
: spaces Array::++ carr[[i]] }; \
? Array::++(carr[[i]], spaces) \
: Array::++(spaces, carr[[i]]) }; \
show(ext_carr); \
} \
\
Expand Down