From 1faec884362e27b873f537c3a1215be43f2141b0 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Mon, 3 Feb 2025 15:54:21 +0100 Subject: [PATCH 1/3] Avoid using '++' where possible --- src/random/RandLC.sac | 4 ++-- src/stdio/ListIO.sac | 24 ++++++++++++------------ src/structures/ArrayFormat.xsac | 25 +++++++++++++------------ src/structures/StringArray.sac | 9 +++++---- src/utrace/UTrace.sac | 9 +++++---- 5 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/random/RandLC.sac b/src/random/RandLC.sac index 2b1ed21b..d74b07b8 100644 --- a/src/random/RandLC.sac +++ b/src/random/RandLC.sac @@ -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; } diff --git a/src/stdio/ListIO.sac b/src/stdio/ListIO.sac index 2f95f186..0d209639 100644 --- a/src/stdio/ListIO.sac +++ b/src/stdio/ListIO.sac @@ -162,7 +162,7 @@ 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"); @@ -170,7 +170,7 @@ 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); } } } @@ -191,7 +191,7 @@ 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"); @@ -199,7 +199,7 @@ 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); } } } @@ -239,7 +239,7 @@ 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"); @@ -247,7 +247,7 @@ 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); } } } @@ -268,7 +268,7 @@ 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"); @@ -276,7 +276,7 @@ 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); } } } @@ -316,7 +316,7 @@ 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"); @@ -324,7 +324,7 @@ 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); } } } @@ -345,7 +345,7 @@ 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"); @@ -353,7 +353,7 @@ 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); } } } diff --git a/src/structures/ArrayFormat.xsac b/src/structures/ArrayFormat.xsac index 76501eec..ecbfbad8 100644 --- a/src/structures/ArrayFormat.xsac +++ b/src/structures/ArrayFormat.xsac @@ -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; } @@ -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; @@ -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; @@ -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; } @@ -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]); } @@ -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]); @@ -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; @@ -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); @@ -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] != '+'); } diff --git a/src/structures/StringArray.sac b/src/structures/StringArray.sac index 3b75ebae..9a689d7b 100644 --- a/src/structures/StringArray.sac +++ b/src/structures/StringArray.sac @@ -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); } @@ -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 { @@ -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); @@ -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) { diff --git a/src/utrace/UTrace.sac b/src/utrace/UTrace.sac index ff478e60..e73e578f 100644 --- a/src/utrace/UTrace.sac +++ b/src/utrace/UTrace.sac @@ -26,9 +26,10 @@ void indentedShow(a[d:shp] arr) \ ' '); \ carr = format(arr); \ ext_carr = with { \ - (. <= iv <= . ) : spaces Array::++ carr[iv]; \ + (. <= iv <= . ) : _cat_VxV_(spaces, carr[iv]); \ } : genarray(drop([-1], shape(carr)), \ - (spaces Array::++ genarray(take([-1], shape(carr)), ' '))); \ + _cat_VxV_(spaces, \ + genarray(take([-1], shape(carr)), ' '))); \ \ show(ext_carr); \ incIndent(offset, strlen(cshape) + 16); \ @@ -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]] }; \ + ? _cat_VxV_(carr[[i]], spaces) \ + : _cat_VxV_(spaces, carr[[i]]) }; \ show(ext_carr); \ } \ \ From 7ad58ee6d0558291a460e9d20bf31b19fe4eeab1 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Mon, 3 Feb 2025 19:03:39 +0100 Subject: [PATCH 2/3] replace iv with [i] --- src/utrace/UTrace.sac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utrace/UTrace.sac b/src/utrace/UTrace.sac index e73e578f..6cbd1e12 100644 --- a/src/utrace/UTrace.sac +++ b/src/utrace/UTrace.sac @@ -26,7 +26,7 @@ void indentedShow(a[d:shp] arr) \ ' '); \ carr = format(arr); \ ext_carr = with { \ - (. <= iv <= . ) : _cat_VxV_(spaces, carr[iv]); \ + (. <= [i] <= . ) : _cat_VxV_(spaces, carr[[i]]); \ } : genarray(drop([-1], shape(carr)), \ _cat_VxV_(spaces, \ genarray(take([-1], shape(carr)), ' '))); \ From f9e00e7cf0c1751aa08bc3a363dc1dc5c0ab6343 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Tue, 4 Feb 2025 08:32:49 +0100 Subject: [PATCH 3/3] Avoid using '++' where possible --- src/utrace/UTrace.sac | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utrace/UTrace.sac b/src/utrace/UTrace.sac index 6cbd1e12..47b9cdff 100644 --- a/src/utrace/UTrace.sac +++ b/src/utrace/UTrace.sac @@ -26,9 +26,9 @@ void indentedShow(a[d:shp] arr) \ ' '); \ carr = format(arr); \ ext_carr = with { \ - (. <= [i] <= . ) : _cat_VxV_(spaces, carr[[i]]); \ + (. <= [i] <= . ) : Array::++(spaces, carr[[i]]); \ } : genarray(drop([-1], shape(carr)), \ - _cat_VxV_(spaces, \ + Array::++(spaces, \ genarray(take([-1], shape(carr)), ' '))); \ \ show(ext_carr); \ @@ -44,8 +44,8 @@ void indentedShow(a[n,m] arr) \ spaces = genarray([getIndent() + getIndent(offset)], ' '); \ carr = format(arr); \ ext_carr = { [i] -> _eq_SxS_(i, 0) \ - ? _cat_VxV_(carr[[i]], spaces) \ - : _cat_VxV_(spaces, carr[[i]]) }; \ + ? Array::++(carr[[i]], spaces) \ + : Array::++(spaces, carr[[i]]) }; \ show(ext_carr); \ } \ \