Here's a quick set of macros for comparing a value against multiple (1 through 256) other values (uses ext/Preprocessor). It uses counting_pine's suggestion as a primary behavior pattern. Other helper macros could be added, like
IsNotEqualTo or
IsLessThanAny, but most of the comparison operations probably have little value.
Code: Select all
# include once "ext/preprocessor.bi"
'' ( ( LHS opRHS0 ) andalso ( LHS opRHS1 ) ... )
# define AndAlsoMulti( LHS, opRHSs ) _
( fbextPP_SeqForEachI( AndAlsoMulti_M, LHS, opRHSs ) )
# define AndAlsoMulti_M( LHS, i, opRHS ) _
fbextPP_ExprIf( i, andalso ) ( (LHS) opRHS )
'' ( ( LHS opRHS0 ) orelse ( LHS opRHS1 ) ... )
# define OrElseMulti( LHS, opRHSs ) _
( fbextPP_SeqForEachI( OrElseMulti_M, LHS, opRHSs ) )
# define OrElseMulti_M( LHS, i, opRHS ) _
fbextPP_ExprIf( i, orelse ) ( (LHS) opRHS )
'' ( ( LHS = RHS0 ) andalso ( LHS = RHS1 ) ... )
# define IsEqualTo( LHS, RHSs ) _
AndAlsoMulti( LHS, fbextPP_SeqTransform( IsEqualTo_T, __, RHSs ) )
# define IsEqualTo_T(__, RHS ) = (RHS)
'' ( ( LHS = RHS0 ) orelse ( LHS = RHS1 ) ... )
# define IsEqualToAny( LHS, RHSs ) _
OrElseMulti( LHS, fbextPP_SeqTransform( IsEqualToAny_T, __, RHSs ) )
# define IsEqualToAny_T(__, RHS ) = (RHS)
ASSERT( AndAlsoMulti( 1, (>0)(=1)(<2) ) )
ASSERT( not IsEqualToAny( 0, (1)(2)(3)(4) ) )
Regarding adding more quirk behavior in the language, I really don't like the idea. Either "verbose" code, Select Case or macros can be used to accomplish the same goal, and many of the syntaxes in this thread look confusing, IMHO.