BlitzCoder Essentials
•
Home Page
•
About BlitzCoder
•
Contributors
•
Terms of Use
•
Email Us
Main Areas
•
BlitzCoder Chat
•
Discussions
•
Articles/Tutorials
•
Code Database
•
Link Database
•
Showcase Area
•
Worklogs
•
Competitions
Special Areas
•
Undocumented
Other Blitz Sites
•
Blitz Basic Home
•
Blitz Showcase
•
BlitzPlay Library
Forum Login
Username:
Password:
•
Register Now!
BlitzCoder Code Archives Page
Main Codes Page
"The use of parentheses () when calling functions"
, by thechange
This includes the basic rules when using your own custom commands e.g. calling your own functions.
Code
;------------------------------------------------------------------------------; ; Blitz Basic (and most other Basics) features omitting parentheses when calling ; functions, unlike other languages like C++. The arising problem is the ; seemless mixing of functions with variables. For example: x = MouseX y = MouseY ; It's quite common to forget the parentheses when calling functions. When ; functions have to return a value, you have to specify parentheses. Otherwise ; you can just call them like this: f ; Where 'f' is a function, defined elsewhere. f() ; Here 'f()' is that same function. v = f ; And here 'f' is a variable, its value being assigned to variable 'v'. v = f() ; But this time 'f()' is the same function again, assigning its returning value ; to variable 'v'. ; The latter goes also for the use of parameters. f( 1 ) ; Here 'f( 1 )' is a function 'f()' with '1' as a parameter. v = f( 1 ) ; And there the same thing as before, but with the '1' parameter again. ; However, in this case, 'f( 1 )' could also be an array, defined elsewhere. a( 1 ) = f( 1 ) ; And that's an example of a function, with parameters, returning a value, to an ; array, at a specific index. ; There are internal Blitz commands and internal Blitz functions. Those internal ; functions have to be handled in the same way as your own custom functions. ; But the internal Blitz commands can be or have to be handled differently, such ; as the For command. The funny thing is that you can add parentheses to some of ; these commands as well. Here's an example of excessive parentheses: Graphics( 640 , 480 ) Dim a( 1 ) Repeat a( 1 ) = f( a( 1 ) ) Print( a( 1 ) ) Flip() Cls() Until( KeyHit( 1 ) ) EndGraphics() End() Function f( n ) Return( Rnd( n )+1 ) End Function ; As you can see, things can look as confusing as C++ when you use parentheses ; where possible :) ; There exists an exception of the use of parentheses in the Object command. ; Maybe because this command is actually a keyword. Advanced example: Type Struct Field Value% End Type Local Pointer.Struct Local Address% Pointer = New Struct Address = Handle( Pointer ) Pointer = Object.Struct Address ; <- without the parentheses Delete Pointer ; EDIT: Object and Handle for pointers are the equivalent of ; Int, Float and Str for other variables. ; They all behave in the same way. ; Have fun :D ;------------------------------------------------------------------------------;
Copyright(c) 2000-2004, BlitzCoder. All Rights Reserved.
Code software created by Krylar's Kreations