Recent

Author Topic: const declaration  (Read 5757 times)

freemind001

  • Jr. Member
  • **
  • Posts: 51
const declaration
« on: January 14, 2025, 03:07:30 pm »
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   SysUtils;
  7.  
  8. function GetC(): integer;
  9. begin
  10.   Result := 1 + 2;
  11. end;
  12.  
  13. const
  14.   a = 1;
  15.   b = a + 1;
  16.   c = GetC();
  17.  
  18. begin
  19.   writeln(inttostr(a));
  20.   writeln(inttostr(b));
  21.   writeln(inttostr(c));
  22. end.    
  23.  

ChatGPT says that c = GetC; is ok, but Lazarus doesn't argree, it says project1.lpr(16,11) Error: Illegal expression

How do I make it believe that it is ok? :)
function GetC is calculatable during compilation

TRon

  • Hero Member
  • *****
  • Posts: 3982
Re: const declaration
« Reply #1 on: January 14, 2025, 03:21:45 pm »
ChatGPT says that c = GetC; is ok, but Lazarus doesn't argree, it says project1.lpr(16,11) Error: Illegal expression
This is exactly the kind of AI generated crap that shouldn't be posted here...

Quote
How do I make it believe that it is ok? :)
Why is it that people ask chatGPT to create code for but not ask the responsible party how to fix it ?

If you want an answer then ask chatcrap to modify the compiler so that it will accept that nonsense  :)

Quote
function GetC is calculatable during compilation
No, it is not. The code implies that it wants to but it isn't valid pascal *period*.
I do not have to remember anything anymore thanks to total-recall.

Zvoni

  • Hero Member
  • *****
  • Posts: 2844
Re: const declaration
« Reply #2 on: January 14, 2025, 03:21:55 pm »
Code: Pascal  [Select][+][-]
  1. program project1;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$MACRO ON}
  5. uses
  6.   SysUtils;
  7.  
  8. //function GetC(): integer;
  9. //begin
  10. //  Result := 1 + 2;
  11. //end;
  12.  
  13. {$define GetC:=1+2}
  14.  
  15. const
  16.   a = 1;
  17.   b = a + 1;
  18.   c = GetC;
  19.  
  20. begin
  21.   writeln(inttostr(a));
  22.   writeln(inttostr(b));
  23.   writeln(inttostr(c));
  24.   Readln;
  25. end.
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Bart

  • Hero Member
  • *****
  • Posts: 5511
    • Bart en Mariska's Webstek
Re: const declaration
« Reply #3 on: January 14, 2025, 03:22:21 pm »
ChatGPT says that c = GetC; is ok, but Lazarus doesn't argree, it says project1.lpr(16,11) Error: Illegal expression

How do I make it believe that it is ok? :)

You cannot.
ChatGPT is wrong.

function GetC is calculatable during compilation
No, it is not.

There is a feature request for "pure functions", where functions declared to be "pure" (as in: can always be calculated at compiletime, and no side effects) will be calculated at compile time.

This opens a can of worms, including infinite loops and stack overflow due to recursion (see e.g. the Ackerman functio (google it): it's pure (a given input will always result in the same output), but it spirals out of control very, very fast).

Bart

BildatBoffin

  • New Member
  • *
  • Posts: 32
Re: const declaration
« Reply #4 on: January 14, 2025, 03:38:21 pm »
purity does not directly imply static evaluation it's more like a contract. Then based on that contract it makes sense to statically evaluate calls to pure functions.

freemind001

  • Jr. Member
  • **
  • Posts: 51
Re: const declaration
« Reply #5 on: January 14, 2025, 04:22:06 pm »
Code: Pascal  [Select][+][-]
  1. const
  2.  
  3.   UINPUT_IOCTL_BASE = Ord('U');
  4.  


why does this work then?

TRon

  • Hero Member
  • *****
  • Posts: 3982
Re: const declaration
« Reply #6 on: January 14, 2025, 04:35:07 pm »
why does this work then?
200 dollars a month and no answer from chatGPT ?

Instruct it to read the documentation
I do not have to remember anything anymore thanks to total-recall.

freemind001

  • Jr. Member
  • **
  • Posts: 51
Re: const declaration
« Reply #7 on: January 14, 2025, 06:01:53 pm »
200 dollars a month
That's an absolute fortune, dude.

Thaddy

  • Hero Member
  • *****
  • Posts: 16532
  • Kallstadt seems a good place to evict Trump to.
Re: const declaration
« Reply #8 on: January 14, 2025, 06:05:38 pm »
chatGPT is wrong again, but in this case you can use a macro. As you intended.
But I am sure they don't want the Trumps back...

TRon

  • Hero Member
  • *****
  • Posts: 3982
Re: const declaration
« Reply #9 on: January 14, 2025, 06:27:27 pm »
That's an absolute fortune, dude.
I would at least expect decent answers for that kind of money money (it is their Pro tier with no limits (within reason) )  :)

(hint: if you are a sucker for these kind of things any other tier will in the end cost you more than that, or be limited quick)

fwiw if too many people post these kind of things in the forums it will eventually trash the forums so such extend that they practically become useless. Hence my somewhat moody response, apologies for that.
I do not have to remember anything anymore thanks to total-recall.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8221
Re: const declaration
« Reply #10 on: January 14, 2025, 06:39:54 pm »
fwiw if too many people post these kind of things in the forums it will eventually trash the forums so such extend that they practically become useless. Hence my somewhat moody response, apologies for that.

I've grumbled about it ad nauseam. It's not just the forum that'll get trashed, it's the corpus that the various AI systems are using for training since by and large they'll be unable to distinguish between working code and their own exudations.

And that's particularly the case for a lesser-known language like Pascal, since while the "AIs" might conceivably embed a C compiler to check fragments it's unlikely they'd bother with anything less popular.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Thaddy

  • Hero Member
  • *****
  • Posts: 16532
  • Kallstadt seems a good place to evict Trump to.
Re: const declaration
« Reply #11 on: January 14, 2025, 07:00:20 pm »
What is so difficult to understand that you can not instantiate a variable at declaration time by calling a function?
chatGPT has a lot to learn.
But I am sure they don't want the Trumps back...

Curt Carpenter

  • Hero Member
  • *****
  • Posts: 594
Re: const declaration
« Reply #12 on: January 14, 2025, 07:02:36 pm »

And that's particularly the case for a lesser-known language like Pascal, since while the "AIs" might conceivably embed a C compiler to check fragments it's unlikely they'd bother with anything less popular.

MarkMLl

I think the "right" answer to "function GetC(): integer;" defined here is "Why would anybody ever DO that???"  But from what I've seen the AIs are really not equipped to ask questions like that.  I don't think they do sarcasm either  ::)

end;

Thaddy

  • Hero Member
  • *****
  • Posts: 16532
  • Kallstadt seems a good place to evict Trump to.
Re: const declaration
« Reply #13 on: January 14, 2025, 07:06:46 pm »
I think my last reply was clear?
You can't use functions at declaration time.
Period.
« Last Edit: January 14, 2025, 07:20:35 pm by Thaddy »
But I am sure they don't want the Trumps back...

TRon

  • Hero Member
  • *****
  • Posts: 3982
Re: const declaration
« Reply #14 on: January 14, 2025, 07:44:58 pm »
I've grumbled about it ad nauseam. It's not just the forum that'll get trashed, it's the corpus that the various AI systems are using for training since by and large they'll be unable to distinguish between working code and their own exudations.
It is even worse. because they also believe their own fantasy and preach it to anyone who wants to hear it (the FOMO's) and coming generations of people (those after us but perhaps even our own) that do not know better will accept it as a truth. Never mind the data they were trained on to manipulate and the PC sauce poured on top of it.

Quote
And that's particularly the case for a lesser-known language like Pascal, since while the "AIs" might conceivably embed a C compiler to check fragments it's unlikely they'd bother with anything less popular.
Everything not mainstream and PC will die in that concept/model that is currently used. But, let the ones in power just sleep and sip their beverage and all is good. AI will solve every problem in this world.

To think I am genuinely impressed by this iteration but imho it is truly spinning out of control. I believe more bad than good will come from this iteration (yes I turned into a pessimist on this topic purely because what I encounter/notice around me and the speed in which that is happening) . For sure Asimov must be having a ball.
I do not have to remember anything anymore thanks to total-recall.

 

TinyPortal © 2005-2018