Recent

Author Topic: [NO SOLUTION] Case with string in Delphi mode  (Read 6690 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6646
Re: Case with string in Delphi mode
« Reply #30 on: March 20, 2022, 03:04:05 pm »
FPC Macros - with its halfway implementation, no parameters - you mean? Even those are more powerful than many people think. But I agree on your remark regarding generics.
(My C++ work relies on its macro features, bad, but it does)

I think it's interesting that Rust distinguishes between declarative and procedural macros.

One of the more interesting bits of macro-implemented code that I've seen recently is this:

Code: C  [Select][+][-]
  1. #define Py_BEGIN_ALLOW_THREADS { \
  2.                         PyThreadState *_save; \
  3.                         _save = PyEval_SaveThread();
  4.  
  5. #define Py_END_ALLOW_THREADS    PyEval_RestoreThread(_save); \
  6.                  }
  7.  

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

MarkMLl

  • Hero Member
  • *****
  • Posts: 6646
Re: Case with string in Delphi mode
« Reply #31 on: March 20, 2022, 03:05:59 pm »
An inlined function can't influence the code flow of the function it's inlined into either (aside from exceptions, but those work the same as if the inlined function was called). And while the compiler currently can't inline function pointers there is nothing in principle that would stop it from inlining functions passed in as parameters as long as the function that is being called is inlined as well.

Sorry, poor terminology on my part. I was thinking of inline or immediate expansion, rather than an inline (i.e. out-of-body) function.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 5444
  • Compiler Developer
Re: Case with string in Delphi mode
« Reply #32 on: March 21, 2022, 11:25:36 am »
One of the more interesting bits of macro-implemented code that I've seen recently is this:

Code: C  [Select][+][-]
  1. #define Py_BEGIN_ALLOW_THREADS { \
  2.                         PyThreadState *_save; \
  3.                         _save = PyEval_SaveThread();
  4.  
  5. #define Py_END_ALLOW_THREADS    PyEval_RestoreThread(_save); \
  6.                  }
  7.  

What I consider quite a bit more impressive is how the developers of ReactOS managed to implement Structured Exception Handling in GCC using a support library and quite a bunch of macros.

An inlined function can't influence the code flow of the function it's inlined into either (aside from exceptions, but those work the same as if the inlined function was called). And while the compiler currently can't inline function pointers there is nothing in principle that would stop it from inlining functions passed in as parameters as long as the function that is being called is inlined as well.

Sorry, poor terminology on my part. I was thinking of inline or immediate expansion, rather than an inline (i.e. out-of-body) function.

Anonymous functions don't do anything remotely related to immediate expansion.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6646
Re: Case with string in Delphi mode
« Reply #33 on: March 21, 2022, 11:45:29 am »
What I consider quite a bit more impressive is how the developers of ReactOS managed to implement Structured Exception Handling in GCC using a support library and quite a bunch of macros.

...although I agree wholeheartedly with you that there's a lot of things attempted with macros that would be better done with a more modern technique: they're a 55 years old concept and the art has moved on substantially.

But that's not to say that there aren't areas where they're not the best or only tool for the job.

Quote
Anonymous functions don't do anything remotely related to immediate expansion.

Don't worry, I get it.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Seenkao

  • Hero Member
  • *****
  • Posts: 545
    • New ZenGL.
Re: [NO SOLUTION] Case with string in Delphi mode
« Reply #34 on: March 21, 2022, 11:58:48 am »
Когда я столкнулся с подобной проблемой я просто перенёс кусок необходимого мне кода в другой модуль.
google translate:
When I ran into a similar problem, I simply moved the piece of code I needed to another module.
Rus: Стремлюсь к созданию минимальных и достаточно быстрых приложений.

Eng: I strive to create applications that are minimal and reasonably fast.
Working on ZenGL

lagprogramming

  • Sr. Member
  • ****
  • Posts: 404
Re: Case with string in Delphi mode
« Reply #35 on: April 09, 2022, 05:49:15 pm »
Noting Thaddy's comment that something like this should have no place in the language: I've got reservations, but it's undeniably useful when writing command parsers etc.
Indeed. Modifying a routine with lots of "if...then...else"s is a nightmare. A "case string of" would remove a level of ifs and would also make the code easier to be read and modified.
Code: Pascal  [Select][+][-]
  1. Case lowercase(trim(stringvariable)) of
  2. 'string1':
  3. begin
  4. //lots of if...then if....else..if...then...else...else;
  5. end;
  6.  
  7. 'string2':
  8. begin
  9. //lots of if...then if....else..if...then...else...else;
  10. end;
  11.  
  12. ...
  13.  
  14. 'string100':
  15. begin
  16. //lots of if...then if....else..if...then...else...else;
  17. end;
  18.  
  19. else
  20. //lots of if...then if....else..if...then...else...else;
  21. end;

Moving the chain of if...then...elses code in a distinctive chainofifthenelses.inc include file is of little help.
Adding libraries to the executable and dynamically calling function names based on the string value is of little help because it complicates things in other parts of the code.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6646
Re: Case with string in Delphi mode
« Reply #36 on: April 09, 2022, 06:50:46 pm »
Indeed. Modifying a routine with lots of "if...then...else"s is a nightmare.

In that case drop the else. See https://forum.lazarus.freepascal.org/index.php/topic,58917.msg439012.html#msg439012 but basically have a sequence of ifs, the one that's taken exits or breaks (e.g. out of a run-once loop), and there's an exception to make sure that control doesn't fall through unexpectedly.

It's maintainable, albeit upsetting to purists.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018