Forum > Beginners

ways to avoid begin-end’s?

<< < (3/10) > >>

Weiss:
unreal

440bx:

--- Quote from: dbannon on May 09, 2024, 07:13:47 am ---That means the compiler sees x:=2 as something that returns an ordinal value ? But not (x:=2) ?

--- End quote ---
The compiler sees:
--- 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=1 then x:= (2 AND DoSomething(x));
It doesn't see the assignment as an operation that is separate from the "and".  It sees (as it should) whatever is right of the assignment as a statement.  integer AND integer is a valid statement therefore x := integer and integer (result from the function) is perfectly valid and really, totally run of the mill (though that may not be apparent at first sight.)

Khrys:

--- Quote from: 440bx on May 09, 2024, 07:54:02 am ---
--- Quote from: dbannon on May 09, 2024, 07:13:47 am ---That means the compiler sees x:=2 as something that returns an ordinal value ? But not (x:=2) ?

--- End quote ---
The compiler sees:
--- 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=1 then x:= (2 AND DoSomething(x));
It doesn't see the assignment as an operation that is separate from the "and".  It sees (as it should) whatever is right of the assignment as a statement.  integer AND integer is a valid statement therefore x := integer and integer (result from the function) is perfectly valid and really, totally run of the mill (though that may not be apparent at first sight.)



--- End quote ---

Better make sure  DoSomething  doesn't just return some garbage from the stack. Throw in an  Exit(not 0)  and enjoy abusing the syntax, I guess...

440bx:

--- Quote from: Khrys on May 09, 2024, 07:56:17 am ---Better make sure  DoSomething  doesn't just return some garbage from the stack. Throw in an  Exit(not 0)  and enjoy abusing the syntax, I guess...

--- End quote ---
I believe that for that definition of "DoSomething" the compiler emits a note or warning stating that the function isn't assigned a result (something which is not a good thing regardless of how the function is used.)

Just for the record, it is not syntactic abuse to have a statement such as "x := <some integer> and SomeFunction();" SomeFunction could simply be a function that returns the correct mask to use in that situation.  Quite run of the mill stuff.

MarkMLl:

--- Quote from: Weiss on May 08, 2024, 11:39:51 pm ---ok. Point taken. I agree, I was wrong. In retrospect, it was probably begin-end’s that made me like Pascal in first place.

--- End quote ---

It was a fair question, and the discussion has highlighted the ways in which even apparently innocuous "features" of a language can get messy.

Chained assignments, automatic type conversion, confusion between logical and bitwise operations...

Considering this reading of your example


--- Code: ---    if x=1 then x:= (2 AND DoSomething(x));

--- End code ---

the real question is whether DoSomething() returns an integer or a boolean. If it's an integer then that AND might work... but then the compiler could reasonably ask itself whether the sizes are compatible. If it's a Boolean it shouldn't work, but there's a chance of things going wrong if the compiler tries to promote DoSomething()'s result to an integer. So in either case that literal 2, which is clearly numeric but hasn't been explicitly given a type, /should/ at least result in a warning which the user /should/ take note of.

MarkMLl

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version