Recent

Author Topic: LIKE operator for Pascal  (Read 15521 times)

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Re: LIKE operator for Pascal
« Reply #15 on: September 16, 2017, 03:26:44 am »
Thanks for the code Thaddy. Will look at it, although the TMask code is working (still to place the hyphen - I am busy replying).

B
Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Re: LIKE operator for Pascal
« Reply #16 on: September 16, 2017, 03:48:10 pm »
I upload modified version of masks-file.

Quote
masks2.pas(380,10) Error: Illegal expression

Error points to:
    I++;   

Arr me laddie, that be C coding if I am not mistaken.
Should it be
  Inc(I,1)?

B
Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

bytebites

  • Hero Member
  • *****
  • Posts: 632
Re: LIKE operator for Pascal
« Reply #17 on: September 16, 2017, 09:07:02 pm »
Inc(I,1) or Inc(I).
My customized compiler understands i++ and i--. 

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Re: LIKE operator for Pascal
« Reply #18 on: September 17, 2017, 04:47:45 am »
I upload modified version of masks-file.
No need to use string replace function.
Create tmask-instance for each mask-string.

Code: Pascal  [Select][+][-]
  1. uses masks2;
  2.  
  3. var
  4.   msk: TMask;
  5. begin  
  6.   msk := Tmask.Create('-123 45.678');
  7.   Result := msk.Matches('{/-}### ##.###');
  8.   msk.free;
  9. end.
  10.  

Arrr me laddie. You be had the strings the wrong way. No wonder the ship wouldn't sail.

But swapped properly and decustomised  ;)  it works.

Inc(I,1) or Inc(I).
My customized compiler understands i++ and i--.

That silly language. Full of squiggly worms wiggling around "void"s.  :D

Give me a manly begin ... end any day.

Many thanks for your help.

Bazza


Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Re: LIKE operator for Pascal
« Reply #19 on: September 17, 2017, 05:55:44 am »
I tried to add a new procedure to update the mask, using the same process as Create.

Code: Pascal  [Select][+][-]
  1. procedure TMask.UpdateMask(const AValue: String; const CaseSensitive: Boolean=true);
  2. begin
  3.   fInitialMask := AValue;
  4.   fCaseSensitive := CaseSensitive;
  5.   InitMaskString(AValue, CaseSensitive);
  6. end;

However I was unsuccessful.

Oh well. I have to [re]learn about classes.

B


Save creating / destroying the mask every time.

Bazzao

Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

bytebites

  • Hero Member
  • *****
  • Posts: 632
Re: LIKE operator for Pascal
« Reply #20 on: September 17, 2017, 08:59:28 am »
Perhaps clear previous mask? Not tested.

Code: Pascal  [Select][+][-]
  1. procedure TMask.UpdateMask(const AValue: String; const CaseSensitive: Boolean=true);
  2. begin
  3.   ClearMaskString;
  4.   fInitialMask := AValue;
  5.   fCaseSensitive := CaseSensitive;
  6.   InitMaskString(AValue, CaseSensitive);
  7. end;

CaseSensitive=false should work too. There was bug in the original mask-file that it didn't.

I agree about C-language, but in this case c-style inc is easier to write than pascal inc.
« Last Edit: September 17, 2017, 09:02:25 am by bytebites »

Bazzao

  • Full Member
  • ***
  • Posts: 178
  • Pies are squared.
Re: LIKE operator for Pascal
« Reply #21 on: September 20, 2017, 03:22:01 am »
The error is a class issue. Something about only known procedures & functions.

So compile is not successful.

B
Bazza

Lazarus 2.0.10; FPC 3.2.0; SVN Revision 63526; x86_64-win64-win32/win64
Windows 10.

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: LIKE operator for Pascal
« Reply #22 on: September 20, 2017, 08:57:58 am »
Inc(I,1) or Inc(I).
My customized compiler understands i++ and i--.
Well, last time (2 years ago) I submitted a request for that it was refused. Not only for language reasons, but also technical.
If you have it working, why not submit a patch? This looks more like a "The Donald Tweet" to me, to be frank. :P
Specialize a type, not a var.

fred

  • Full Member
  • ***
  • Posts: 201
Re: LIKE operator for Pascal
« Reply #23 on: September 20, 2017, 01:47:54 pm »
There is something in between, the += operator as in i += 1;
https://www.freepascal.org/docs-html/3.0.2/prog/progsu10.html
I have used += a lot in C but never in Pascal :)

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: LIKE operator for Pascal
« Reply #24 on: September 20, 2017, 04:44:18 pm »
There is something in between, the += operator as in i += 1;
https://www.freepascal.org/docs-html/3.0.2/prog/progsu10.html
I have used += a lot in C but never in Pascal :)
Short answer : I was referring to that, long answer:
Yes, that's why I asked to implement the reverse order as well (=+, increment after use and the likes) It was refused.
Actually I agreed with that decision, because it is easy to do yourself and the source is more readable.
Note increment/decrement/multiply/divide AFTER use are completely different beasts from a compiler perspective:
It is *a lot* more difficult to implement, since initial state needs to be preserved until after the initial operation.
And e.g. that operation can be lengthy.
That's harder to do in what is basically still a single pass compiler (it isn't quite a single pass compiler anymore, but anyway it still has the characteristics ).
« Last Edit: September 20, 2017, 06:39:57 pm by Thaddy »
Specialize a type, not a var.

bytebites

  • Hero Member
  • *****
  • Posts: 632
Re: LIKE operator for Pascal
« Reply #25 on: September 20, 2017, 06:58:30 pm »
i++; i--; attached.

Breaks code. i++2 causes error.

Send it to Trump or whatever.

File removed to avoid more disappointments.
« Last Edit: September 21, 2017, 07:18:01 am by bytebites »

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: LIKE operator for Pascal
« Reply #26 on: September 20, 2017, 08:35:12 pm »
That's not what was asked..
+= increment before use
=+ increment after use
Etc.
++ and -- are already covered by for to and for downto.
Increment after use in your patch doesn't work. Not in for to and not in for downto.
I reverted the patch.
Plz IF you create a compiler patch, make sure it works AND fails as intended. In this case make sure it works like its C equivalent.
Make sure it can not overflow and underflow.
What is your intended code? I don't see the point with your patch. Examples? What works? I can only show it doesn't work:
Code: Pascal  [Select][+][-]
  1. // very basic fail:
  2. var i:integer = 0;
  3. begin
  4. while i < 10 do
  5.  writeln(i++); // should be 0..9
  6. i := 0;
  7. while i < 10 do
  8.  writeln(++i); //should be 1..10
  9. end.
And what is the equivalent for
Code: C  [Select][+][-]
  1. for(i=0;i<10;i++){printf("i");};
  2. for(i=0;i<10;++i){printf("i");};

Now please explain if your patch actually does anything?.. useful...<grumpy... >:D>

The patch is harmless for one try if someone wants to test it, but revert it immediately after the test... 8-) O:-)
I did, see test code.
It is utter nonsense because it is not thought through and poorly implemented if at all sound.
More basic fail:
Code: Pascal  [Select][+][-]
  1. // very basic fail 2:
  2. var i:integer = 0;
  3. begin
  4. while i++ < 10 do
  5.  writeln(i); // should be 0..9
  6. i := 0;
  7. while ++i < 10 do
  8.  writeln(i); //should be 1..9! // 9 not 10
  9. end.

Does not work, does it? ;D >:(

Mind you, I want all of this to work, but it is far more complex to implement than your try and than you think. Try again.... :D
« Last Edit: September 20, 2017, 10:31:10 pm by Thaddy »
Specialize a type, not a var.

bytebites

  • Hero Member
  • *****
  • Posts: 632
Re: LIKE operator for Pascal
« Reply #27 on: September 21, 2017, 07:16:03 am »
Sorry to hear that you was disappointed  >:D
In this way it was designed to work. You can write inc(i) instead of it.
Code: Pascal  [Select][+][-]
  1. var i:integer = 0;
  2. begin
  3. while i < 10 do begin
  4.  writeln(i); // should be 0..9
  5.  i++;
  6. end;
  7. i := 0;
  8. while i < 10 do begin
  9.  i++;
  10.  writeln(i); //should be 1..9! // 9 not 10
  11. end;
  12. end.
« Last Edit: September 21, 2017, 09:33:07 am by bytebites »

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: LIKE operator for Pascal
« Reply #28 on: September 21, 2017, 08:35:37 am »
Well, a simple replacement for inc()/dec() has imho little real value.
I encourage you to implement it properly. (Difficulty between 1..10 is 11, though).
It is a feature I requested at least 2 times in the past years, both requests were rejected.
I still think a full implementation is a highly desirable feature. See my test examples why I think so.
So a full set of use then modify, modify then use etc. Note: use then modify is the culprit.
« Last Edit: September 21, 2017, 08:38:54 am by Thaddy »
Specialize a type, not a var.

bytebites

  • Hero Member
  • *****
  • Posts: 632
Re: LIKE operator for Pascal
« Reply #29 on: September 21, 2017, 01:36:22 pm »
Code: C  [Select][+][-]
  1. #include <stdio.h>
  2. int main(void)
  3.         {
  4. int i=0;
  5. while (i++<10)
  6.   printf("%d\n",i);
  7. return 0;
  8. }

Prints numbers 1-10.

Code: C  [Select][+][-]
  1. #include <stdio.h>
  2. int main(void)
  3.         {
  4. int i=0;
  5. while (++i<10)
  6.   printf("%d\n",i);
  7. return 0;
  8. }

Prints numbers 1-9.
Java does the same.
And now Pascal:

Code: Pascal  [Select][+][-]
  1. program inctest;
  2.  
  3. {$mode delphi}
  4.  
  5. function preinc(var i:integer):integer;inline;
  6. begin
  7.   inc(i);
  8.   result:=i;
  9. end;
  10.  
  11. function postinc(var i:integer):integer;inline;
  12. begin
  13.   result:=i;
  14.   inc(i);
  15. end;
  16.  
  17. var i:integer;
  18. begin
  19.   writeln('i++ simulation');
  20.   i:=0;
  21.   while postinc(i)<10 do
  22.     writeln(i);
  23.  
  24.   writeln('++i simulation');
  25.   i:=0;
  26.   while preinc(i)<10 do
  27.     writeln(i);
  28.  
  29. end.


 

TinyPortal © 2005-2018