Gotchas: Difference between revisions

4,002 bytes added ,  1 year ago
Line 111:
end
</pre>
 
=={{header|Phix}}==
Once I hear about a gotcha, I usually just fix it, so this might be a bit of a struggle...
 
There are however a few things to bear in mind for running under p2a/p2js (and sadly I can't "just fix JavaScript"):
 
In JavaScript, true!=1 and false!=0. Thankfully, there are very few places
anyone ever actually compares bools against 0 and 1 using an infix operator,
but occasionally you may need to use equal() and compare() instead, for true
compatibility between desktop/Phix and p2js.
 
Likewise negative subscripts simply do not work in JavaScript Array destructuring,
but you can however use $ and negative subscripts in non-destructuring operations.
 
One case that proved very difficult to track down was the statement
<code>tree[node+direction] = insertNode(tree[node+direction], key)</code>.
As said elsewhere you should never attempt to modify the same thing in the
same line twice. Breaking it into <code>atom tnd = insertNode(tree[node+direction], key)</code>
and <code>tree[node+direction] = tnd</code> was needed to fix the issue.
 
See also [[Variable_declaration_reset]] - in particular the Phix and JavaScript entries.
 
'''Somewhat more tongue in cheek''':
 
There is no difference between if a=b then and if a==b then, and neither modifies a.<br>
It is not posible to compose a dangling else in Phix.<br>
Phix has no macros. Or any that can make innocent-looking code "mean just about anything".<br>
041 is the same number as 41, whereas 0o41 is the octal representation of 33 decimal.<br>
"Hello" is not really the same as {'H','e','l','l','o'} but they are treated that way.<br>
zero minus one is always -1 instead of the traditionally expected 4,294,967,295.<br>
Indexes are 1-based and s[0] triggers a run-time error.<br>
<small> (It surprises me to read Andrew Koenig in ctraps.pdf saying
"In most languages, an array with n elements normally has subscripts ranging from 1 to n inclusive.")</small><br>
Novice users often confuse a &= b with a = append(a,b):
 
* When b is an atom (aka number) they mean the same thing.<br>
* When b is a sqeuence (or string) they are not the same:<br>
* a &= b can increase the length of a by any amount, including 0.<br>
* a = append(a,b) always increases the length of a by 1.<br>
 
An expression such as s+1 can, with a suitable warning message, be auto-corrected to sq_add(s,1).<br>
Block comments ''can'' be nested, <code>a and b or c</code> is illegal and demands extra parenthesis be used.<br>
Forward calls may thwart constant setup, eg:
<!--<lang Phix>(phixonline)-->
<span style="color: #008080;">forward</span> <span style="color: #008080;">procedure</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">()</span>
<span style="color: #000000;">p</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">f</span><span style="color: #0000FF;">(</span><span style="color: #004080;">object</span> <span style="color: #000000;">o</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #000000;">o</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">hello</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">f</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"hello"</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">p</span><span style="color: #0000FF;">()</span>
<span style="color: #0000FF;">?</span><span style="color: #000000;">hello</span> <span style="color: #000080;font-style:italic;">-- fatal error: hello has not been assigned a value</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<!--</lang>-->
Not a problem if the first executed statement in your program is a final main().
 
=={{header|Raku}}==
Line 194 ⟶ 247:
''extremely'' confusing to early Perl / Raku crossover programmers. Larry Wall
came up with single argument to reduce confusion and increase DWIMiness, and it
has overall, but it still leads to the occasional WAT when programmers first bump up against it.
 
 
=={{header|Wren}}==
7,806

edits