$LET: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
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 (true) if the user is running QB64 in a Windows environment, it is 0 (false) otherwise.
** '''WIN''' or '''WINDOWS''' is ''true(-1)'' if the user is running QB64 in a Windows environment, it is ''false(0)'' otherwise.
** '''LINUX''' is -1 (true) if the user is running QB64 in a Linux environment, it is 0 (false) otherwise.
** '''LINUX''' is ''true(-1)'' if the user is running QB64 in a Linux environment, it is ''false(0)'' otherwise.
** '''MAC''' or '''MACOSX''' is -1 (true) if the user is running QB64 in a macOS environment, it is 0 (false) otherwise.
** '''MAC''' or '''MACOSX''' is ''true(-1)'' if the user is running QB64 in a macOS environment, it is ''false(0)'' otherwise.
** '''32BIT''' is -1 (true) if the user is running a 32-bit version of QB64., it is 0 (false) otherwise.
** '''32BIT''' is ''true(-1)'' if the user is running a 32-bit version of QB64., it is ''false(0)'' otherwise.
** '''64BIT''' is -1 (true) if the user is running a 64-bit version of QB64., it is 0 (false) 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.
** '''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 (true), it indicates the use of the QB64 Phoenix Edition compiler at least v.4.0.0
** '''_QB64PE_''' is always ''true(-1)'', 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.
** '''_ASSERTS_''' is ''one(1)'' if [[$ASSERTS]] or [[$ASSERTS|$ASSERTS:CONSOLE]] is used, it is ''zero(0)'' 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).
** '''_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 (one) if [[$DEBUG]] is used, it is 0 (zero) otherwise.
** '''_DEBUG_''' is ''one(1)'' if [[$DEBUG]] is used, it is ''zero(0)'' otherwise.
** '''_EXPLICIT_''' is 1 (one) if the program uses [[OPTION EXPLICIT|OPTION _EXPLICIT]], it is 0 (zero) otherwise (note OE also implies '''OPTION _EXPLICITARRAY''').
** '''_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 (one) if the program uses [[OPTION EXPLICITARRAY|OPTION _EXPLICITARRAY]] or [[OPTION EXPLICIT|OPTION _EXPLICIT]], it is 0 (zero) otherwise.
** '''_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}}.
:* All presets are {{Text|'''read-only'''|red}} values and cannot be redefined by using [[$LET]] on it.
:* 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.
:* The presets shall just serve the ability, for library makers, to easily check what features are active in a program, they shall otherwise not be {{Text|'''misused 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 '''_CONSOLE_''' and force one to open, if none is there,
::* don't check for '''_EXPLICIT_''' and force it, if it's not in effect already
::* don't check for '''_EXPLICIT_''' and force it, if it's not in effect, etc.
:* 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.
:* 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 means you also should not enforce things, which the user did not already use in his program.





Latest revision as of 11:02, 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
  • All presets are read-only values and cannot be redefined by using $LET on it.
  • The presets shall just serve the ability, for library makers, to easily check what features are active in a program, they shall otherwise not be misused to enforce certain features, e.g.
  • don't check for _CONSOLE_ and force one to open, if none is there,
  • don't check for _EXPLICIT_ and force it, if it's not in effect, etc.
  • 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 means you also should not enforce things, which the user did not already use in his program.


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



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link