The Macro's I am talking about here are more like what C calls Inline Functions, than what they call macro's
BASIC's total lack of macro's is out and out shameful.
Macros are functions that get expanded into the code that uses them instead of being in a separate location that gets called.
If a macro is never called, then it takes up no space in your end program, because the code for the macro never gets expanded into "actual" code.
On the other hand, if it is used more than a few times, then it takes up more space because it is inserted into your code over and over, and the code grows with each use (unless the macro is incredibly small)
Macro's also have the added convenience of not having to know what type's their parameters are. This is because they will be expanded out in the code, and if the macro doesnt know what type a parameter is, the compiler will be able to sort it out in the resulting code.
Enough on macros, lets see some
Macro Max(? x, y) Returns ?
If x <= y : RetVal = x
Else : RetVal = y
End If
End Macro
We can use ? in the place of a variable_type as a way of saying "we dont care" or, you can specify a variable type so that the macro expansion can validate things for you
This Macro is much more robust than the old Max function, because it can take Floats or any other type we want to send it.
Anyone want to comment on macro's?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The Macro's I am talking about here are more like what C calls Inline Functions, than what they call macro's
BASIC's total lack of macro's is out and out shameful.
Macros are functions that get expanded into the code that uses them instead of being in a separate location that gets called.
If a macro is never called, then it takes up no space in your end program, because the code for the macro never gets expanded into "actual" code.
On the other hand, if it is used more than a few times, then it takes up more space because it is inserted into your code over and over, and the code grows with each use (unless the macro is incredibly small)
Macro's also have the added convenience of not having to know what type's their parameters are. This is because they will be expanded out in the code, and if the macro doesnt know what type a parameter is, the compiler will be able to sort it out in the resulting code.
Enough on macros, lets see some
Macro Max(? x, y) Returns ?
If x <= y : RetVal = x
Else : RetVal = y
End If
End Macro
We can use ? in the place of a variable_type as a way of saying "we dont care" or, you can specify a variable type so that the macro expansion can validate things for you
This Macro is much more robust than the old Max function, because it can take Floats or any other type we want to send it.
Anyone want to comment on macro's?