Forum > Beginners

ways to avoid begin-end’s?

<< < (5/10) > >>

Weiss:
actually, any bitwise operation would do the same thing, or xor not, shl etc.  I tried a few. Except "AND" is more readable, it kind of suggests addendum.

>> is cool too.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if X=a then X:=1  >>  increment(i);
Gentlemen, I totally understand that this is an unintended use of bitwise operators, that function returns no value and therefore value of X is not affected and solely side effect of function is used. It is a bona fide syntactic abuse, in a context of by-passing begin-end encapsulation.

MarkMLl:

--- Quote from: Weiss on May 09, 2024, 11:22:26 am ---actually, any bitwise operation would do the same thing, or xor not, shl etc.  I tried a few. Except "AND" is more readable, it kind of suggests addendum.

>> is cool too.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if X=a then X:=1  >>  increment(i);
Gentlemen, I totally understand that this is an unintended use of bitwise operators, that function returns no value and therefore value of X is not affected and solely side effect of function is used. It is a bona fide syntactic abuse, in a context of by-passing begin-end encapsulation.

--- End quote ---

The value of x WILL be affected: it will be ANDed (or whatever) with whatever rubbish the increment() function returns since the result is unassigned.

MarkMLl

alpine:

--- Quote from: Weiss on May 09, 2024, 11:22:26 am ---actually, any bitwise operation would do the same thing, or xor not, shl etc.  I tried a few. Except "AND" is more readable, it kind of suggests addendum.

>> is cool too.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---if X=a then X:=1  >>  increment(i);
Gentlemen, I totally understand that this is an unintended use of bitwise operators, that function returns no value and therefore value of X is not affected and solely side effect of function is used. It is a bona fide syntactic abuse, in a context of by-passing begin-end encapsulation.

--- End quote ---
This just can't be true!

The neutral operand for AND is all-ones, but for >> (perhaps shr) is a zero. The function has a result, most probably the incidental value of the AX register. It can't be all-ones and all-zeros in the same time.

Weiss:

--- Quote from: alpine on May 09, 2024, 10:29:04 am --- If it works it is a pure chance.

--- End quote ---

You are right. It doesn't. I forgot to check the value of X after bitwising it. Side effect of function works, whatever I make it do, it does. But value of X becomes "0" if I bitwise X with result of function that returns no value. End of story.

Weiss:
actually, also not true what I jsut said. They all return different value of X, from 658 to exit with code 201.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version