Recent

Author Topic: Why are constants not constant - or not known...?  (Read 1641 times)

440bx

  • Hero Member
  • *****
  • Posts: 1995
Re: Why are constants not constant - or not known...?
« Reply #15 on: May 25, 2020, 12:30:17 am »
Or maybe they simply had the/a "const" segment in mind. Keep in mind that TP lived in a segmented world.
But, there was no "const" segment back then.  It was all you can read and write as long as it's not more than 64K.

It really makes no sense to declare a variable in the constant declaration part.  It's a Homer Simpson thing.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

winni

  • Hero Member
  • *****
  • Posts: 1803
Re: Why are constants not constant - or not known...?
« Reply #16 on: May 25, 2020, 12:52:54 am »
Hi!

Sometimes it is good to know the (weird) history of Turbo Pascal and Bolands (un) logic:

Code: Text  [Select][+][-]
  1. Because a typed constant is actually a variable with a constant
  2. value, it can't be interchanged with ordinary constants. For
  3. example, it can't be used in the declaration of other constants or
  4. types:
  5. const
  6. Min: Integer = 0;
  7. Max: Integer = 99;
  8. type
  9. TVector = array [Min .. Max] of Integer;
  10. The TVector declaration is invalid, because Min and Max are typed
  11. constants.
  12.  

Fom : Turbo_Pascal_Version_7.0_Language_Guide_1992.pdf page 59

Winni
« Last Edit: May 25, 2020, 12:57:41 am by winni »

MarkMLl

  • Hero Member
  • *****
  • Posts: 1225
Re: Why are constants not constant - or not known...?
« Reply #17 on: May 25, 2020, 08:54:53 am »
Or maybe they simply had the/a "const" segment in mind. Keep in mind that TP lived in a segmented world.
But, there was no "const" segment back then.  It was all you can read and write as long as it's not more than 64K.

The object files had various segments which were typically grouped and used for different things: embedded systems wanted read-only data to be in ROM as an example.

And you also have to allow that in the 90s people expected segmented architictures to be used properly, and the x86 descriptor specifically had a r/w bit for data.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

440bx

  • Hero Member
  • *****
  • Posts: 1995
Re: Why are constants not constant - or not known...?
« Reply #18 on: May 25, 2020, 09:03:42 am »
The object files had various segments which were typically grouped and used for different things: embedded systems wanted read-only data to be in ROM as an example.

And you also have to allow that in the 90s people expected segmented architictures to be used properly, and the x86 descriptor specifically had a r/w bit for data.
Yes but, when I wrote about there not being "const" segments, I was thinking about Turbo Pascal in the MS-DOS world.  That's where the "typed constants" fantasy originated.
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8729
  • FPC developer.
Re: Why are constants not constant - or not known...?
« Reply #19 on: May 25, 2020, 11:34:52 am »
Yes but, when I wrote about there not being "const" segments, I was thinking about Turbo Pascal in the MS-DOS world.  That's where the "typed constants" fantasy originated.

There was a m68k version of TP for versions 1-3.

And I meant const as the initialized part of the datasegment.
« Last Edit: May 25, 2020, 11:41:35 am by marcov »

Thaddy

  • Hero Member
  • *****
  • Posts: 10468
Re: Why are constants not constant - or not known...?
« Reply #20 on: May 25, 2020, 11:39:42 am »
Not to mention CP/M http://www.digitalresearch.biz/CPM.HTM
For which the original TP was written by Anders.
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

MarkMLl

  • Hero Member
  • *****
  • Posts: 1225
Re: Why are constants not constant - or not known...?
« Reply #21 on: May 25, 2020, 11:48:07 am »
The object files had various segments which were typically grouped and used for different things: embedded systems wanted read-only data to be in ROM as an example.

And you also have to allow that in the 90s people expected segmented architictures to be used properly, and the x86 descriptor specifically had a r/w bit for data.
Yes but, when I wrote about there not being "const" segments, I was thinking about Turbo Pascal in the MS-DOS world.  That's where the "typed constants" fantasy originated.

Knowing a bit about Borland's early politics, I can assure you that they had an eye on future architectures and in their compilers' potential for embedded systems.

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

440bx

  • Hero Member
  • *****
  • Posts: 1995
Re: Why are constants not constant - or not known...?
« Reply #22 on: May 25, 2020, 12:06:25 pm »
Whatever their "reasons" may have been, it simply makes no sense whatsoever to create variables in the constant declaration part of a compiler. 
FPC v3.0.4 and Lazarus 1.8.2 on Windows 7 64bit.

Zoran

  • Hero Member
  • *****
  • Posts: 1590
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: Why are constants not constant - or not known...?
« Reply #23 on: May 25, 2020, 02:17:02 pm »
Yes, whatever they had in mind for the future, a new keyword (or keywords, like "static var") would be an elegant solution.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8729
  • FPC developer.
Re: Why are constants not constant - or not known...?
« Reply #24 on: May 25, 2020, 02:24:02 pm »
Yes, whatever they had in mind for the future, a new keyword (or keywords, like "static var") would be an elegant solution.

You can use VAR for initialized constants since D4/FPC2.

MarkMLl

  • Hero Member
  • *****
  • Posts: 1225
Re: Why are constants not constant - or not known...?
« Reply #25 on: May 25, 2020, 02:42:26 pm »
Yes, whatever they had in mind for the future, a new keyword (or keywords, like "static var") would be an elegant solution.

You can use VAR for initialized constants since D4/FPC2.

But are they static, i.e. does the value persist next time control returns in-scope?

MarkMLl
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.

lucamar

  • Hero Member
  • *****
  • Posts: 3025
Re: Why are constants not constant - or not known...?
« Reply #26 on: May 25, 2020, 02:47:21 pm »
But are they static, i.e. does the value persist next time control returns in-scope?

IIRC, they have always been (re-)initialized on (re-)entering the scope. That's what distinguish them (from the programmer's p.o.v.) from (writeable) typed constants, which keep always the latest value set.
« Last Edit: May 25, 2020, 02:49:06 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Thaddy

  • Hero Member
  • *****
  • Posts: 10468
Re: Why are constants not constant - or not known...?
« Reply #27 on: May 25, 2020, 03:16:06 pm »
You can use VAR for initialized constants since D4/FPC2.
Make that TP1. And forget about var.
AFAIK it was Anders who introduced it. Correct me if I am wrong again.

The only reason they exist is to maintain state (as per question) and existed before OOP pascal.
Code: Pascal  [Select][+][-]
  1. {$modeswitch result}{$J+}
  2. function countmeuntilieventuallyoverfloworthecompilerdoesnotknowwhatImean:integer;
  3. const
  4.   a:integer = 0;
  5. begin
  6.    Result := a;
  7.    inc(a);
  8. end;
  9. var i:integer;
  10. begin
  11.  for i := 0 to 9 do
  12.    writeln(countmeuntilieventuallyoverfloworthecompilerdoesnotknowwhatImean);
  13. end.
   
« Last Edit: May 25, 2020, 03:38:24 pm by Thaddy »
When you ask a question that is actually answered in the documentation, you are either lazy or a moron.

lucamar

  • Hero Member
  • *****
  • Posts: 3025
Re: Why are constants not constant - or not known...?
« Reply #28 on: May 25, 2020, 04:24:36 pm »
You can use VAR for initialized constants since D4/FPC2.
Make that TP1. And forget about var.
AFAIK it was Anders who introduced it. Correct me if I am wrong again.

I think he means this:
Code: Pascal  [Select][+][-]
  1. var something: Integer = 321;
which was introduced in one of the earlier Delphi 32 bit (3? 4? I don't remember which).
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

 

TinyPortal © 2005-2018