Recent

Author Topic: [Solved] Generics fighting back.  (Read 3415 times)

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1353
  • Professional amateur ;-P
Re: Generics fighting back.
« Reply #15 on: August 04, 2025, 08:33:51 pm »
Hey avk,

Code: Pascal  [Select][+][-]
  1. function CompareTMyRecord({$IF FPC_FULLVERSION<30204}constref{$ELSE}const{$ENDIF}L, R: TMyRecord): Integer;
  2. begin
  3.   Result := Ord(L.ID > R.ID) - Ord(L.ID < R.ID);
  4. end;

UHHHHHH-UUUHHHH, this is just the type of math and boolean magic that I thrive for !!!
This is defo going in my toolbox!! With a mnemonic: They point at the middle minus.

Cannot thank you enough @avk, really !!!

Cheers,
Gus

avk

  • Hero Member
  • *****
  • Posts: 826
Re: Generics fighting back.
« Reply #16 on: August 04, 2025, 09:31:21 pm »
... With a mnemonic: They point at the middle minus...

This is just a centripetal form, but there is also a centrifugal one:
Code: Pascal  [Select][+][-]
  1.   Result := Ord(R.ID < L.ID) - Ord(R.ID > L.ID);
  2.  

Gustavo 'Gus' Carreno

  • Hero Member
  • *****
  • Posts: 1353
  • Professional amateur ;-P
Re: Generics fighting back.
« Reply #17 on: August 04, 2025, 09:42:47 pm »
Hey avk,

... With a mnemonic: They point at the middle minus...

This is just a centripetal form, but there is also a centrifugal one:
Code: Pascal  [Select][+][-]
  1.   Result := Ord(R.ID < L.ID) - Ord(R.ID > L.ID);
  2.  

Hummm... Yeah, sorry, I'm a Left-to-Right person. Nothing against Right-to-Left'ies, for sure!! ;)

And I love the centrifugal, centripetal mnemonics !!! While I'm not gonna swipe that from you, I'll put a pin on it for future reference :D

Cheers,
Gus

PascalDragon

  • Hero Member
  • *****
  • Posts: 6381
  • Compiler Developer
Re: Generics fighting back.
« Reply #18 on: August 05, 2025, 10:32:13 pm »
Let me test something.


begin
  for i := 1 to 10 do
  begin
    myvar[i] := i;
  end;
end;

P.S.: No italics :)
So we can also use [nobbc] and [/nobbc] if we doesn't want to use [code] tags and we won't get code interpreted by forum software. :)

And that will still make me complain to you about not using [code][/code]-tags, because they simply make the code better readable.

 

TinyPortal © 2005-2018