home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.os.vms      DEC's VAX* line of computers & VMS.      264,096 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 263,093 of 264,096   
   =?UTF-8?Q?Arne_Vajh=C3=B8j?= to Simon Clubley   
   Re: BASIC (was Re: extending MySQL on VM   
   26 Aug 25 19:38:40   
   
   From: arne@vajhoej.dk   
      
   On 8/26/2025 8:30 AM, Simon Clubley wrote:   
   > On 2025-08-25, Arne Vajhøj  wrote:   
   >> On 8/24/2025 10:34 PM, Lawrence D?Oliveiro wrote:   
   >>> One trick they missed was allowing interval comparisons like this:   
   >>>   
   >>>       if "0" <= ch <= "9" or "a" <= ch <= "f" or "A" <= ch <= "F" :   
   >>>   
   >>> I think only Python has that.   
   >>   
   >> Yes.   
   >>   
   >> But note that the feature is not "interval comparison" but   
   >> "chaining comparison operators".   
   >>   
   >> The above example is very readable and makes sense.   
   >   
   > Just don't try getting that code past me without first having used   
   > brackets around the subexpressions. :-)   
      
   I would also do:   
      
   ('0' <= ch <= '9') or ('A' <= ch <= 'F') or ('a' <= ch <= 'f')   
      
   But the problem is not in the OR of 3, but in the chaining comparison   
   (special interpretation of two comparisons)   
      
   >> But it is less obvious with other operators.   
   >>   
   >> Example:   
   >>   
   >> 4 == 4 == True   
   >>   
   >> Most languages (possible all exception Python) evaluate   
   >> that to True, because it is treated like:   
   >>   
   >> (4 == 4) == True   
   >>   
   >> But it is False in Python because it is treated like:   
   >>   
   >> (4 == 4) and (4 == True)   
   >>   
   >> Which feels less natural.   
   >   
   > And _this_ is an example of why Simon's policy of backets around   
   > everything makes it explicitly clear what was intended. :-)   
      
   I am all for shoveling lots of parenthesis's all over the code to   
   make it really obvious.   
      
   But in this case the chaining comparison itself provide some   
   weird cases.   
      
   I prefer the alternative of:   
      
   (ch in '0'..'9') || (ch in 'A'..'F') || (ch in 'a'..'f')   
      
   or maybe:   
      
   ch in [*'0'..'9', *'A'..'F', *'a'..'f']   
      
   if the language support that (Groovy does).   
      
   I think it is just as readable and it does not require   
   the chaining comparison (special interpretation of two   
   comparisons) that result in some weird cases.   
      
   The chaining comparison does have one advantage though - it   
   works with floating point. But I can live with having to   
   write floating point intervals the traditional way.   
      
   Arne   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca