variables/fields definition by ","

BlitzMax Forums/BlitzMax Beginners Area/variables/fields definition by ","

johnnyfreak(Posted 2010) [#1]
I don't know if this is the right forum to post this but...
i like you can define different variables of the same type using
...
local x:int, y:int, z:int
...

But why'd be impossible to write
...
local x, y, x:int
...
?
Yes, i know, it's a small thing but i'd prefer to write the second manner.
Maybe this little change to the parser will be available in the next update?

(Sorry for my english)


Czar Flavius(Posted 2010) [#2]
If you use Strict, rather than SuperStrict, all variables are assumed to be Int unless stated otherwise. So then you can write
Local x, y, f:Float, z

and x, y and z are Ints.

You can also use the symbols %, # and $ to refer to integers, floats and strings respectively. (Note: I don't use these often so I might have remembered wrong). Then you can write
Local an_int%, a_float#, a_string$

which is at least less typing. If you are using the Blide editor, it can automatically expand these symbols to :Int etc for you in the code as you write them.

Otherwise, I don't know of any more shortcuts.


johnnyfreak(Posted 2010) [#3]
i already know %,$,# but i prefer Int, string, float, double.
my aim isn't to have variables of different types but
SuperStrict
...
field x, y, z:Int 'these are all integers
fields a, b, c:String 'these are all strings
...

It's a useful shorthand shorthand to me.
It isn't critical but nice.
Take it as a suggestion or a little wish ;)


Warpy(Posted 2010) [#4]
Because unless you're in Strict mode, you can only have one or the other kind of syntax, so Mark went with having to define each field's type individually.


markcw(Posted 2010) [#5]
Well if we're asking for stuff it would be nice to have a true newline ";" character so I could write If/Else/ElseIf/Endif blocks *and* their statements on the same line ie.
Local a:Int = 0
If a = 1 ; Print "What gives?" ; Print " a="+a
ElseIf a = 2 Then Print "What gives?" ; Print " a="+a
Else Print "What gives?" ; Print " a="+a
Endif



degac(Posted 2010) [#6]
I think Johnnyfreak means the possibilty to write the type of many variables once for all.
I wrote - time ago - a modified version of MaxIDE that 'supported' type definition for multiple item.
For info http://www.blitzbasic.com/Community/posts.php?topic=66944#806575
So a line like
Global window:tgadget,btn_ok:tgadget,btn_close:tgadget

could be written as
DEFINE GLOBAL:Tgadget
   window, btn_ok, btn_close
END DEFINE


Unfortunately the resulting source code is not *standard* so no shareable with none else...
but if someone want to make a PREPROCESSOR and make is 'standard' please consider something like this above!


*(Posted 2010) [#7]
tbh I like it as it is :), I normally have one variable per line with a remark telling me what its for and why :)


johnnyfreak(Posted 2010) [#8]
i mean what like degac said.
Also somethig for inline commands (if,for,while) via new line char would be interensting.


Czar Flavius(Posted 2010) [#9]
You can do this
Strict
Local a:Int = 0
If a = 1 ; Print "What gives?" ; Print " a=" + a ..
ElseIf a = 2 Then Print "What gives?" ; Print " a=" + a ..
Else Print "What gives?" ; Print " a=" + a



markcw(Posted 2010) [#10]
Oh wierd, I'm sure I tried that too. Every time I tried something like that the compiler choked.

Well thanks but it needs documented cause the docs make it look like it's either all on one line or new lines for every condition or statement.