$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 Tag: Manual revert |
No edit summary |
||
Line 1: | Line 1: | ||
[[$LET]] is a precompiler | [[$LET]] is a precompiler [[Metacommand|metacommand]]. It is used to define or redefine precompiler variables for use in the [[$IF]]...[[$ELSE]]...[[$END IF]] block statements. | ||
{{PageSyntax}} | {{PageSyntax}} | ||
: [[$LET]] variable = | : [[$LET]] variable = value | ||
{{PageDescription}} | {{PageDescription}} | ||
* Unlike [[LET]], [[$LET]] is not optional. | * Unlike [[LET]], [[$LET]] is not optional. | ||
* $LET a = 12 sets a precompiler variable "a" to the value of 12. | * $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. | * 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. | * 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''' if the user is running QB64 in a Windows environment. | ** '''WIN''' or '''WINDOWS''' is -1 (true) if the user is running QB64 in a Windows environment, it is 0 (false) otherwise. | ||
** '''LINUX''' if the user is running QB64 in a Linux environment. | ** '''LINUX''' is -1 (true) if the user is running QB64 in a Linux environment, it is 0 (false) otherwise. | ||
** '''MAC''' or '''MACOSX''' if the user is running QB64 in a macOS environment. | ** '''MAC''' or '''MACOSX''' is -1 (true) if the user is running QB64 in a macOS environment, it is 0 (false) otherwise. | ||
** '''32BIT''' if the user is running a 32-bit version of QB64. | ** '''32BIT''' is -1 (true) if the user is running a 32-bit version of QB64., it is 0 (false) otherwise. | ||
** '''64BIT''' if the user is running a 64-bit version of QB64. | ** '''64BIT''' is -1 (true) if the user is running a 64-bit version of QB64., it is 0 (false) 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: | |||
** '''_QB64PE_''' is always -1 (true), it indicates the use of the QB64 Phoenix Edition compiler at least v.4.0.0 | |||
** '''_ASSERTS_''' is 1 (one) if [[$ASSERTS]] or [[$ASSERTS|$ASSERTS:CONSOLE]] is used, it is 0 (zero) otherwise. | |||
** '''_CONSOLE_''' is 1 (one) if a console is active either by using [[$CONSOLE]] directly or implied by [[$ASSERTS|$ASSERTS:CONSOLE]], it is 2 (two) if [[$CONSOLE|$CONSOLE:ONLY]] is set, it is 0 (zero) 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 (one) if [[$DEBUG]] is used, it is 0 (zero) otherwise. | |||
** '''_EXPLICIT_''' is 1 (one) if the program uses [[OPTION EXPLICIT|OPTION _EXPLICIT]], it is 0 (zero) otherwise (note OE also implies '''OPTION _EXPLICITARRAY'''). | |||
** '''_EXPLICITARRAY_''' is 1 (one) if the program uses [[OPTION EXPLICITARRAY|OPTION _EXPLICITARRAY]] or [[OPTION EXPLICIT|OPTION _EXPLICIT]], it is 0 (zero) 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 {{Text|'''read-only'''|red}}. | |||
:* The presets shall mainly serve the ability, for library makers, to check what features are active in a program, {{Text|'''don't misuse it to enforce'''|red}} 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. | |||
{{PageAvailability}} | |||
<!-- QB64 = a version or none, QBPE = a version or all, Platforms = yes or no --> | |||
<gallery widths="48px" heights="48px" mode="nolines"> | |||
File:Qb64.png|'''v1.0''' | |||
File:Qbpe.png|'''all''' | |||
File:Apix.png | |||
File:Win.png|'''yes''' | |||
File:Lnx.png|'''yes''' | |||
File:Osx.png|'''yes''' | |||
</gallery> | |||
<!-- Additional availability notes go below the gallery, e.g. --> | |||
* In '''QB64-PE v4.0.0''' several new presets got added into the precompiler (see above). | |||
Revision as of 22:06, 17 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 -1 (true) if the user is running QB64 in a Windows environment, it is 0 (false) otherwise.
- LINUX is -1 (true) if the user is running QB64 in a Linux environment, it is 0 (false) otherwise.
- MAC or MACOSX is -1 (true) if the user is running QB64 in a macOS environment, it is 0 (false) otherwise.
- 32BIT is -1 (true) if the user is running a 32-bit version of QB64., it is 0 (false) otherwise.
- 64BIT is -1 (true) if the user is running a 64-bit version of QB64., it is 0 (false) 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 -1 (true), it indicates the use of the QB64 Phoenix Edition compiler at least v.4.0.0
- _ASSERTS_ is 1 (one) if $ASSERTS or $ASSERTS:CONSOLE is used, it is 0 (zero) otherwise.
- _CONSOLE_ is 1 (one) if a console is active either by using $CONSOLE directly or implied by $ASSERTS:CONSOLE, it is 2 (two) if $CONSOLE:ONLY is set, it is 0 (zero) 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 (one) if $DEBUG is used, it is 0 (zero) otherwise.
- _EXPLICIT_ is 1 (one) if the program uses OPTION _EXPLICIT, it is 0 (zero) otherwise (note OE also implies OPTION _EXPLICITARRAY).
- _EXPLICITARRAY_ is 1 (one) if the program uses OPTION _EXPLICITARRAY or OPTION _EXPLICIT, it is 0 (zero) 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