hello, can you tell me why the output is not suppressed here? from the 'err' function as in $, I added a semi-colon below so it shouldn't print "Upper limit should be greater than lower limit"? but it does - can you help me understand why please
randomList : {[n;lowlimit;upplimit]
if[-7h <> type n; err "ERROR : First Argument should be a long integer"];
if[(-7h <> type lowlimit) or ((-7h <> type upplimit)); err "ERROR : Lower and Upper limits should be long integers"];
$[upplimit > lowlimit;
n?lowlimit+til 1+upplimit-lowlimit;
err "Upper limit should be greater than lower limit";]
};
getCorrelation : {
a:randomList[10;15;14];
/b:randomList[10;15;20];
.[cor;(a;b);{err "Error running main: ",x}];
out "the correlation is = ", string cor[a;b]
};
You have an explicit -2 in the err function. That means print the string to standard error. There is no way to "suppress" this in this form. However, you could add a global variable for whether to print errors or not, check it in the err function, and only do -2 if the check passes.
You are probably confusing this with the behavior of q where typing an expression prints the result on the console, and adding a semicolon suppresses that output. In that case what's actually happening is that the semicolon is creating a sequence, where each element of the sequence is evaluated for side effects, but the intermediate results are discarded, and the overall result is the result of the last expression in the sequence. If the semicolon is at the end of the line, that creates an invisible expression at the end, which evaluates to a null, and that results in nothing being printed on the console. But if you have -2 somewhere in the sequence, that will print the string to the standard error anyway, because that's a side effect, not a result.