$LET: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
Line 14: | Line 14: | ||
* You can check a precompiler variable against special values '''DEFINED''' and '''UNDEFINED''', in order to assess whether the variable has already been assigned a value. Useful for code in libraries which may be repeated. | * You can check a precompiler variable against special values '''DEFINED''' and '''UNDEFINED''', in order to assess whether the variable has already been assigned a value. Useful for code in libraries which may be repeated. | ||
* The precompiler comes with some preset values which can be used to help determine which code blocks to include/exclude. These are: | * The precompiler comes with some preset values which can be used to help determine which code blocks to include/exclude. These are: | ||
** '''WIN''' or '''WINDOWS''' is -1 | ** '''WIN''' or '''WINDOWS''' is ''true(-1)'' if the user is running QB64 in a Windows environment, it is ''false(0)'' otherwise. | ||
** '''LINUX''' is -1 | ** '''LINUX''' is ''true(-1)'' if the user is running QB64 in a Linux environment, it is ''false(0)'' otherwise. | ||
** '''MAC''' or '''MACOSX''' is -1 | ** '''MAC''' or '''MACOSX''' is ''true(-1)'' if the user is running QB64 in a macOS environment, it is ''false(0)'' otherwise. | ||
** '''32BIT''' is -1 | ** '''32BIT''' is ''true(-1)'' if the user is running a 32-bit version of QB64., it is ''false(0)'' otherwise. | ||
** '''64BIT''' is -1 | ** '''64BIT''' is ''true(-1)'' if the user is running a 64-bit version of QB64., it is ''false(0)'' otherwise. | ||
** '''VERSION''', which is set to the version of the QB64 compiler. | ** '''VERSION''', which is set to the version of the QB64 compiler. | ||
* Some new presets have been introduced with QB64-PE v4.0.0, these are: | * Some new presets have been introduced with QB64-PE v4.0.0, these are: | ||
** '''_QB64PE_''' is always -1 | ** '''_QB64PE_''' is always ''true(-1)'', it indicates the use of the QB64 Phoenix Edition compiler at least v.4.0.0 | ||
** '''_ASSERTS_''' is 1 | ** '''_ASSERTS_''' is ''one(1)'' if [[$ASSERTS]] or [[$ASSERTS|$ASSERTS:CONSOLE]] is used, it is ''zero(0)'' otherwise. | ||
** '''_CONSOLE_''' is 1 | ** '''_CONSOLE_''' is ''one(1)'' if a console is active either by using [[$CONSOLE]] directly or implied by [[$ASSERTS|$ASSERTS:CONSOLE]], it is ''two(2)'' if [[$CONSOLE|$CONSOLE:ONLY]] is set, it is ''zero(0)'' if no console is available (both console variants may appear multiple times in a program, the last found one determines the final state). | ||
** '''_DEBUG_''' is 1 | ** '''_DEBUG_''' is ''one(1)'' if [[$DEBUG]] is used, it is ''zero(0)'' otherwise. | ||
** '''_EXPLICIT_''' is 1 | ** '''_EXPLICIT_''' is ''one(1)'' if the program uses [[OPTION EXPLICIT|OPTION _EXPLICIT]], it is ''zero(0)'' otherwise (note OE also implies '''OPTION _EXPLICITARRAY'''). | ||
** '''_EXPLICITARRAY_''' is 1 | ** '''_EXPLICITARRAY_''' is ''one(1)'' if the program uses [[OPTION EXPLICITARRAY|OPTION _EXPLICITARRAY]] or [[OPTION EXPLICIT|OPTION _EXPLICIT]], it is ''zero(0)'' otherwise. | ||
; Important notes regarding the preset values | ; Important notes regarding the preset values | ||
:* Although there's for simplicity no internal protection against it, don't overwrite the presets using [[$LET]], always consider the presets as {{Text|'''read-only'''|red}}. | :* Although there's for simplicity no internal protection against it, don't overwrite the presets using [[$LET]], always consider the presets as {{Text|'''read-only'''|red}}. |
Revision as of 00:32, 18 November 2024
$LET is a precompiler metacommand. It is used to define or redefine precompiler variables for use in the $IF...$ELSE...$END IF block statements.
Syntax
- $LET variable = value
Description
- Unlike LET, $LET is not optional.
- $LET a = 12 sets a precompiler variable "a" to the value of 12. This variable is only valid for the precompiler itself and does nothing to affect the values of any variable/constant which might also be called "a" in the program.
- Variable names must follow QB64's variable naming conventions. They will be capitalized automatically.
- Values may contain any number of periods to separate numbers or words in a string, e.g. in version numbers such as 3.14.1 or strings like MARY.HAD.A.LITTLE.LAMB etc..
- Note that strings may not contain spaces and therefore may be given without leading/trailing quotes.
- You can check a precompiler variable against special values DEFINED and UNDEFINED, in order to assess whether the variable has already been assigned a value. Useful for code in libraries which may be repeated.
- The precompiler comes with some preset values which can be used to help determine which code blocks to include/exclude. These are:
- WIN or WINDOWS is true(-1) if the user is running QB64 in a Windows environment, it is false(0) otherwise.
- LINUX is true(-1) if the user is running QB64 in a Linux environment, it is false(0) otherwise.
- MAC or MACOSX is true(-1) if the user is running QB64 in a macOS environment, it is false(0) otherwise.
- 32BIT is true(-1) if the user is running a 32-bit version of QB64., it is false(0) otherwise.
- 64BIT is true(-1) if the user is running a 64-bit version of QB64., it is false(0) otherwise.
- VERSION, which is set to the version of the QB64 compiler.
- Some new presets have been introduced with QB64-PE v4.0.0, these are:
- _QB64PE_ is always true(-1), it indicates the use of the QB64 Phoenix Edition compiler at least v.4.0.0
- _ASSERTS_ is one(1) if $ASSERTS or $ASSERTS:CONSOLE is used, it is zero(0) otherwise.
- _CONSOLE_ is one(1) if a console is active either by using $CONSOLE directly or implied by $ASSERTS:CONSOLE, it is two(2) if $CONSOLE:ONLY is set, it is zero(0) if no console is available (both console variants may appear multiple times in a program, the last found one determines the final state).
- _DEBUG_ is one(1) if $DEBUG is used, it is zero(0) otherwise.
- _EXPLICIT_ is one(1) if the program uses OPTION _EXPLICIT, it is zero(0) otherwise (note OE also implies OPTION _EXPLICITARRAY).
- _EXPLICITARRAY_ is one(1) if the program uses OPTION _EXPLICITARRAY or OPTION _EXPLICIT, it is zero(0) otherwise.
- Important notes regarding the preset values
-
- Although there's for simplicity no internal protection against it, don't overwrite the presets using $LET, always consider the presets as read-only.
- The presets shall mainly serve the ability, for library makers, to check what features are active in a program, don't misuse it to enforce certain features, e.g.
- don't check for _CONSOLE_ and force to open one, if none is there already
- don't check for _EXPLICIT_ and force it, if it's not in effect already
- Think of it like checking for WINDOWS and if it's not forcing the user to buy a Windows system or checking for 32BIT and if it's not forcing the user to downgrade his 64-bit system. You wouldn't do that, right? And by that you should not enforce things, which the user did not use in his program already.
Availability
- In QB64-PE v4.0.0 several new presets got added into the precompiler (see above).
Examples
- See example 1 in $IF.
See also