Recent

Author Topic: Nested declarations inside advanced record  (Read 25167 times)

simone

  • Hero Member
  • *****
  • Posts: 649
Nested declarations inside advanced record
« on: January 08, 2025, 03:49:14 pm »
As is known, it is possible to nest the declarations of constants and types (as well as obviously variables) within a class. So we can write code like the following:

Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$mode objfpc}
  3. {$modeswitch advancedrecords}
  4.  
  5. type
  6.  
  7.   { MyRec }
  8.  
  9.   TMyRec=class
  10.     private
  11.       const
  12.         C=5;
  13.       var
  14.         X, Y : integer;
  15.       type
  16.         TB=integer;
  17.     public
  18.       procedure Proc;
  19.   end;
  20.  
  21. { MyRec }
  22.  
  23. procedure TMyRec.Proc;
  24. begin
  25.  
  26. end;
  27.  
  28. begin
  29. end.

This syntax is expressly admittedfor by the diagram shown here:

https://www.freepascal.org/docs-html/current/ref/refse35.html#x70-940006.1

While testing a parser, I wondered if this was also possible for advanced records.

From the syntax diagrams shown here:

https://www.freepascal.org/docs-html/current/ref/refse61.html#x120-1440009.1

it would appear not.

To my surprise, I saw that the compiler accepts this syntax instead:

Code: Pascal  [Select][+][-]
  1. program Project1;
  2. {$mode objfpc}
  3. {$modeswitch advancedrecords}
  4.  
  5. type
  6.  
  7.   { MyRec }
  8.  
  9.   TMyRec=record
  10.     private
  11.       const
  12.         C=5;
  13.       var
  14.         X, Y : integer;
  15.       type
  16.         TB=integer;
  17.     public
  18.       procedure Proc;
  19.   end;
  20.  
  21. { MyRec }
  22.  
  23. procedure TMyRec.Proc;
  24. begin
  25.  
  26. end;
  27.  
  28. begin
  29. end.

Therefore, should I assume that nested declarations of types and constants are also possible with advanced records?

Thanks in advance.



Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

440bx

  • Hero Member
  • *****
  • Posts: 5139
Re: Nested declarations inside advanced record
« Reply #1 on: January 08, 2025, 04:04:09 pm »
Therefore, should I assume that nested declarations of types and constants are also possible with advanced records?

Thanks in advance.
In theory it should because objects and classes are just extensions of advanced records.

Advanced records are the "seed" of OOP.  That's where it all starts.  Conceptually, Classes/Objects = Advanced records + inheritance + polymorphism.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

simone

  • Hero Member
  • *****
  • Posts: 649
Re: Nested declarations inside advanced record
« Reply #2 on: January 08, 2025, 04:19:04 pm »
I agree from a conceptual point of view, reasoning by analogy. My surprise comes from the fact that this is not documented.
« Last Edit: January 08, 2025, 04:57:36 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

Warfley

  • Hero Member
  • *****
  • Posts: 1872
Re: Nested declarations inside advanced record
« Reply #3 on: January 08, 2025, 04:59:16 pm »
Record and Object/Class parsing is kindof independent in the fpc source. (Advanced) Records are parsed in parse_record_members and objects are parsed in parse_object_members.
So this is not a situation that one works because the other one works and they just share the same code (which happens quite often with records and objects, e.g. parse_record_fields is used by both objects and records).

Advanced Records allows type, var, threadvar and const blocks, as well as property, (class) procedure/functions, constructor and destructor definitions.

I'm not sure if it's documented tho
« Last Edit: January 08, 2025, 05:11:18 pm by Warfley »

simone

  • Hero Member
  • *****
  • Posts: 649
Re: Nested declarations inside advanced record
« Reply #4 on: January 08, 2025, 05:26:24 pm »
Thanks Warfley.

Your clarification is especially important for what I'm doing. In the fcl-passrc parser, which I'm investigating for some personal projects, in line with what has been confirmed, in PasTree unit, TPasMembersType is the base type for TPasRecordType and TPasClassType.
« Last Edit: January 08, 2025, 05:30:39 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 16781
  • Ceterum censeo Trump esse delendam
Re: Nested declarations inside advanced record
« Reply #5 on: January 09, 2025, 12:02:06 pm »
In theory it should because objects and classes are just extensions of advanced records.

Advanced records are the "seed" of OOP.  That's where it all starts.  Conceptually, Classes/Objects = Advanced records + inheritance + polymorphism.
Well, that is not true, although it might be conceptually true.
Originally there was no such thing as advanced records. That concept was a very much later addition to the language and even fairly recent. So your statement does not fit the time line.
History is records -> objects -> classes ->advanced records, in that order.
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

440bx

  • Hero Member
  • *****
  • Posts: 5139
Re: Nested declarations inside advanced record
« Reply #6 on: January 09, 2025, 03:17:34 pm »
Well, that is not true, although it might be conceptually true.
There is no "might" about it. 

Apparently you're another one of those that thinks that what happens in FPC is how the world turns.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Warfley

  • Hero Member
  • *****
  • Posts: 1872
Re: Nested declarations inside advanced record
« Reply #7 on: January 09, 2025, 04:26:57 pm »
There is no "might" about it. 
Except that the language that introduced OOP was SmallTalk, which didn't have records. Infact SmallTalk is not a classical procedural language to begin with (SmallTalk is Expression based not Statement based).

So it was first Smalltalk and then it was retrofitted to the structured type system of Algol style language like C and Pascal.

So sorry but the idea that there were first advanced records and then OOP developed from that is just completely ahistorical.

If you want to learn a bit about the original OOP, check out GNU SmallTalk. You'll see that it's typesystem has absolutely no resemblence of Pascal (or Algols) structured record types
« Last Edit: January 09, 2025, 04:32:53 pm by Warfley »

simone

  • Hero Member
  • *****
  • Posts: 649
Re: Nested declarations inside advanced record
« Reply #8 on: January 09, 2025, 04:43:33 pm »
Except that the language that introduced OOP was SmallTalk

Historically this is not true: the first language that introduced OOP was Simula

(https://en.wikipedia.org/wiki/Object-oriented_programming)
« Last Edit: January 09, 2025, 04:45:36 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

Warfley

  • Hero Member
  • *****
  • Posts: 1872
Re: Nested declarations inside advanced record
« Reply #9 on: January 09, 2025, 04:58:13 pm »
Historically this is not true: the first language that introduced OOP was Simula

(https://en.wikipedia.org/wiki/Object-oriented_programming)
Right my mistake, SmallTalk was the first OOP language (i.e. including all the concepts like meta classes and stuff like that) , but the first language to introduce objects and the basic OOP concepts was Simula you are right.

Still Simula introduced already classes in full with most of the features we know today. "Advanced Records" where never a step in between

440bx

  • Hero Member
  • *****
  • Posts: 5139
Re: Nested declarations inside advanced record
« Reply #10 on: January 09, 2025, 05:00:15 pm »
So sorry
You are rather sorry... you got that right.

Try to figure this out.. what critical characteristic of OOP do advanced records showcase ? 

reply when AND IF you figure out the answer.   Ask ChatGPT, it might be able to find the answer for you (and Thaddy.)

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 16781
  • Ceterum censeo Trump esse delendam
Re: Nested declarations inside advanced record
« Reply #11 on: January 09, 2025, 05:03:47 pm »
Apparently you're another one of those that thinks that what happens in FPC is how the world turns.
Well, that is the order in which they were introduced in delphi/freepascal and TurboPascal does not even have advanced records, like it or not.
Provide evidence to  the contrary, you can't. Advanced records are a recent bolt-on. Noon of the major dialects know advanced records, just delphi and freepascal.
« Last Edit: January 09, 2025, 05:07:48 pm by Thaddy »
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

alpine

  • Hero Member
  • *****
  • Posts: 1376
Re: Nested declarations inside advanced record
« Reply #12 on: January 09, 2025, 05:19:16 pm »
Try to figure this out.. what critical characteristic of OOP do advanced records showcase ? 
Arghhhh, encapsulation, isn't it?

Stop nagging, Thaddy is right about that - most of us have experienced that transition while programming since the TP era.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

440bx

  • Hero Member
  • *****
  • Posts: 5139
Re: Nested declarations inside advanced record
« Reply #13 on: January 09, 2025, 05:26:44 pm »
There is one thing that has been clearly re-enforced by a select few forums participants and that is that, some people are surprisingly resistant to acquiring knowledge.  I guess it might have something to do with the fact that most of them seem to believe they know everything and were born that way (or got their "infinite" knowledge from reading FPC source code <chuckle>.)

The conclusion is: the results, which are usually very poor, are not worth my time.

I understand that you (Thaddy) like to argue anything, no matter how pointless, it makes your post count go up which seems to be important to you. ;)  Cheap thrills.




Try to figure this out.. what critical characteristic of OOP do advanced records showcase ? 
Arghhhh, encapsulation, isn't it?

Stop nagging, Thaddy is right about that - most of us have experienced that transition while programming since the TP era.
Yes, encapsulation.

Additionally, just because the grouping of variables (they become fields or some other fancy name) isn't called a "record" or "advanced record" in some other language, doesn't mean the language does not provide the mechanism.    It's a concept not a name.

Thaddy is _always_ right... haven't you figured that out yet ? ... and he is not the only one.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 16781
  • Ceterum censeo Trump esse delendam
Re: Nested declarations inside advanced record
« Reply #14 on: January 09, 2025, 05:31:20 pm »
Where is the proof? You are talking hot air.
Back to the topic:
All records can be nested, advanced or not. Simple answer and correct.
Since the inception of Pascal.

I ever claimed to be always right, but neither are you. I usually correct myself.
« Last Edit: January 09, 2025, 05:36:54 pm by Thaddy »
Changing servers. thaddy.com may be temporary unreachable but restored when the domain name transfer is done.

 

TinyPortal © 2005-2018