Recent

Author Topic: Very unimportant, small request..  (Read 7071 times)

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Very unimportant, small request..
« Reply #15 on: April 27, 2018, 06:21:39 pm »
The current behaviour of trunk is a bug, the 3.0.4 behaviour is correct.
Fpc devel Sven confirmed this and will fix it.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Very unimportant, small request..
« Reply #16 on: April 28, 2018, 12:05:13 am »
Sven fixed it in r38860.

Bart

darksky666

  • New Member
  • *
  • Posts: 38
Re: Very unimportant, small request..
« Reply #17 on: April 28, 2018, 01:15:54 pm »
I tested it's if then else equivalent and what you said is right, it evaluates to true for all strings that start with a..y (regardless of what the rest of the characters in that string are.. even string amBER_%%%@ worked).

It works for string 'z' as well. But why don't strings like zoom, z' or 'z ' (z+space) or any string that starts with character 'z' and length > 1 work?  %)

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Very unimportant, small request..
« Reply #18 on: April 28, 2018, 02:20:22 pm »
I tested it's if then else equivalent and what you said is right, it evaluates to true for all strings that start with a..y (regardless of what the rest of the characters in that string are.. even string amBER_%%%@ worked).

It works for string 'z' as well. But why don't strings like zoom, z' or 'z ' (z+space) or any string that starts with character 'z' and length > 1 work?  %)

Because it is, as you said, if-then-else equivalent, so, let's take a look at eg. string 'za' -- the question is:
Code: Pascal  [Select][+][-]
  1. if ('za' >= 'a') // (1)
  2.   and ('za' <= 'z') // (2)
  3. then
  4.   ...
  5.  
And the string starting with 'z' and with length > 1, eg. 'za' is greater then 'z', so, the result of (2) is false, it does not fall in the range 'a'..'z'.

Zoran

  • Hero Member
  • *****
  • Posts: 1829
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Very unimportant, small request..
« Reply #19 on: April 28, 2018, 02:34:12 pm »
The result which you expect can be achieved with:
Code: Pascal  [Select][+][-]
  1.   case s1 of
  2.   'Hello', 'Hello2' : begin
  3.                       Writeln ('Hello or Hello2');
  4.                       Writeln ('IInd Statement');
  5.                       end;
  6.   else
  7.     case S1[1] of
  8.     'A', 'a'..'z' : begin
  9.                   Writeln ('A or a..z');
  10.                   Writeln ('Ch IInd Statement');
  11.                   end;
  12.     else
  13.       Writeln ('Neither HAHA!');
  14.       Writeln ('NONE OF THOSE HAHA');
  15.     end;
  16.   end;

Please just take Bart's advise -- avoid using ranges with strings in a case statement.
As I agree with Thaddy, I'll go even further and stay away from case with strings completely.

darksky666

  • New Member
  • *
  • Posts: 38
Re: Very unimportant, small request..
« Reply #20 on: April 28, 2018, 02:57:11 pm »
Ah thanks, that makes sense, a complete ban of char range inside case string of statements would have been much better but it seems that 'feature' isnt going anywhere.

I'll do the wise thing and pretend its not allowed at all..

 

TinyPortal © 2005-2018