Request : if local myint:int = somefunc()
BlitzMax Forums/BlitzMax Programming/Request : if local myint:int = somefunc()
| ||
Just a small request. It would be great (for shorthand) if blitz were able to do this..function SomeFunc() return rand(0,9) end function if local myint:int = SomeFunc() = 1 print "the myint was initialized with the number 1" end if This is how you have to do it at the moment local myint:int = SomeFunc() if myint = 1 print "the myint was initialized with the number 1" end if Currently you can do it with for loops: for local:i = 0 to 10 print "i = "+i next It is purely for shorthand, but it would be nice. |
| ||
Won't this cause some scope issues. In the first code example, myint belongs to the IF statement, doesn't that mean that it will 'die' before any ELSE or ELSEIF statements? |
| ||
Well it is upto the creator of the language. I assume that anything "inside" the block is local to the block. The local declaration should belong to the parent block of that if. |
| ||
How aboutfunction SomeFunc() return rand(0,9) end function Local myint:int=1 if myint & SomeFunc() = myint 'if both are 1 print "the myint was initialized with the number 1" end if Or is that not what you want to do? Otherwise why not do: function SomeFunc() return rand(0,9) end function Local myint:int if SomeFunc() = 1 myint=1 print "the myint was initialized with the number 1" end if ?? I kind of see what you're saying... you want to be able to test the value of SomeFunc() at the same time as putting that value into the myint variable? Umm.... function SomeFunc(myint var) myint=rand(0,9) end function if SomeFunc() = 1 print "the myint was initialized with the number 1" end if ??????? |
| ||
Read what I said :) local myint:int = SomeFunc() if myint = 1 print "the myint was initialized with the number 1" end if I was suggesting that it be possible to set a variable and test the value set on the same line, yes. |
| ||
No, I wont be doing this. The problem is the dual use of '=' to mean both assignment and comparison. For/Next is 'special' because it already uses '=' to mean assignment, therefore adding the 'Local' bit doesn't change the semantics of it at all. However, having... If a=x ...mean something entirely different from... If Local a=x ...is not cool. |
| ||
I agree, it just adds some unecessary shortcut that really makes your code a bit harder to read. This isnt C++ :) Might be a bit faster to type, but there's not too much point. |
| ||
Ok :) I guess my suggestion can only really work if the language incases expressions in () |
| ||
Or give us macro's ;-) |