Recent

Author Topic: const declaration  (Read 5723 times)

Warfley

  • Hero Member
  • *****
  • Posts: 1865
Re: const declaration
« Reply #15 on: January 14, 2025, 07:55:38 pm »
ChatGPT says that c = GetC; is ok, but Lazarus doesn't argree, it says
This is because large language models are not really good at being correct. They often hallucinate (the actual academic term) things which look correct and are great for producing a lot of stuff thats mostly correct. But they are not reliable in questions of details.

So while you can ask ChatGPT to generate you some code, or to explain to you something, it will only be like 80% correct. To efficiently use AI for programming you must know more about programming than the AI model. You can then delegate some of the tasks to the AI model, but must be prepared to spend some time correcting it.

silvestre

  • Jr. Member
  • **
  • Posts: 80
Re: const declaration
« Reply #16 on: January 14, 2025, 08:24:32 pm »
Warfley, what you describe is exactly how the situation is today and some people are not very aware of it. AI has yet to evolve to understand the “small” details that make the differences, and programmers, need to continue to have a solid foundation in coding to use AI correctly.


ChatGPT says that c = GetC; is ok, but Lazarus doesn't argree, it says
This is because large language models are not really good at being correct. They often hallucinate (the actual academic term) things which look correct and are great for producing a lot of stuff thats mostly correct. But they are not reliable in questions of details.

So while you can ask ChatGPT to generate you some code, or to explain to you something, it will only be like 80% correct. To efficiently use AI for programming you must know more about programming than the AI model. You can then delegate some of the tasks to the AI model, but must be prepared to spend some time correcting it.

Sieben

  • Sr. Member
  • ****
  • Posts: 372
Re: const declaration
« Reply #17 on: January 14, 2025, 10:01:17 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.  

Where's the pleasure in that...? Why would you want to do that? Why not just:

Code: Pascal  [Select][+][-]
  1. const
  2.   a = 1;
  3.   b = a + 1;
  4.   c = 3;

and in any scenario when you would call GetC() just use c...?
Lazarus 2.2.0, FPC 3.2.2, .deb install on Ubuntu Xenial 32 / Gtk2 / Unity7

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1326
Re: const declaration
« Reply #18 on: January 15, 2025, 12:42:02 am »
Why are discussions about chatgpt and AI still happening here ?
 It’s completely off topic and has nothing to do with fpc .

It should be obvious to anyone who bothers to learn pascal that a function result is not a constant.  >:(
« Last Edit: January 15, 2025, 12:43:50 am by Joanna from IRC »
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Thaddy

  • Hero Member
  • *****
  • Posts: 16532
  • Kallstadt seems a good place to evict Trump to.
Re: const declaration
« Reply #19 on: January 15, 2025, 05:54:35 am »
It is not off- topic when people actually use it and chatGPT comes up with an answer that we have to correct. By now I have instructed chatGPT to not use functions in variable declarations with default values.(yes, you can do that). Takes some time but it will use that knowledge eventually.
But I am sure they don't want the Trumps back...

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1326
Re: const declaration
« Reply #20 on: January 15, 2025, 06:17:28 am »
Why on earth would someone rather use chatgpt instead of learning to code properly??  :o and moreover it is not our responsibility to act as unpaid volunteers to help improve the product of a for profit company that wants to put all creators of intellectual property out of business!

Nobody should be encouraged to use this AI garbage at all.
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

Zvoni

  • Hero Member
  • *****
  • Posts: 2844
Re: const declaration
« Reply #21 on: January 15, 2025, 08:05:29 am »
Where's the pleasure in that...? Why would you want to do that? Why not just:

Code: Pascal  [Select][+][-]
  1. const
  2.   a = 1;
  3.   b = a + 1;
  4.   c = 3;

and in any scenario when you would call GetC() just use c...?

Because in C you can pass values for defined Symbols during compilation, so TS labours under the misconception that it's possible in FPC, and that those passed values are THEN used during Compilation, to "calculate" the value for the constant
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

Thaddy

  • Hero Member
  • *****
  • Posts: 16532
  • Kallstadt seems a good place to evict Trump to.
Re: const declaration
« Reply #22 on: January 15, 2025, 09:59:43 am »
More in general, if chatGPT makes a mistake, point that out and show the code that is wrong to chatGPT.
The model will adapt itself.
But I am sure they don't want the Trumps back...

MarkMLl

  • Hero Member
  • *****
  • Posts: 8221
Re: const declaration
« Reply #23 on: January 15, 2025, 10:17:41 am »
More in general, if chatGPT makes a mistake, point that out and show the code that is wrong to chatGPT.
The model will adapt itself.

But other models, which by now are using this forum as an authoritative reference, will not.

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 #24 on: January 15, 2025, 10:24:07 am »
Mark, it will eventually sort itself out.
But I am sure they don't want the Trumps back...

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10811
  • Debugger - SynEdit - and more
    • wiki
Re: const declaration
« Reply #25 on: January 15, 2025, 10:28:55 am »
Mark, it will eventually sort itself out.
Hopefully... And in the sense "sort out" meaning "remove from availability"? I.e. the LLMs will (remove) sort themself out from the list of useful tools.

If they do, that may be their first smart move. ;)

Joanna from IRC

  • Hero Member
  • *****
  • Posts: 1326
Re: const declaration
« Reply #26 on: January 15, 2025, 11:10:33 am »
People are infinitely gullible when it comes to trying to get something for nothing...
✨ 🙋🏻‍♀️ More Pascal enthusiasts are needed on IRC .. https://libera.chat/guides/ IRC.LIBERA.CHAT  Ports [6667 plaintext ] or [6697 secure] channel #fpc  #pascal Please private Message me if you have any questions or need assistance. 💁🏻‍♀️

freemind001

  • Jr. Member
  • **
  • Posts: 51
Re: const declaration
« Reply #27 on: January 15, 2025, 02:41:14 pm »
"Why would anybody ever DO that???"
i'm trying to make a wrapper for iunput.h in pascal for a personal project.

there are things like
Code: C  [Select][+][-]
  1. /* ioctl */
  2. #define UINPUT_IOCTL_BASE       'U'
  3. #define UI_DEV_CREATE           _IO(UINPUT_IOCTL_BASE, 1)
  4. #define UI_DEV_DESTROY          _IO(UINPUT_IOCTL_BASE, 2)
which seem to be not implementable in pascal, as you can't pass a value to macros.

As the project is for fun, talking about salary doesn't make sense. As well as discussing the knowledge of Pascal of forum members.
And yes, I agree, ChatGPT is pretty stupid when dealing with pascal. :)
« Last Edit: January 15, 2025, 02:47:32 pm by freemind001 »

Thaddy

  • Hero Member
  • *****
  • Posts: 16532
  • Kallstadt seems a good place to evict Trump to.
Re: const declaration
« Reply #28 on: January 15, 2025, 02:54:23 pm »
They are perfectly implementable, but you need to implement them as inlined functions.
That is no different from the C implementation, it is only that C macro's allow for parameters, but in effect they end up as a function anyway.

Also note that C macro's are notoriously unsafe!, no type checking is done.
I think that was one of the reasons to not expand Freepascal's macro capabilities.

Just write the macro as a function.
For a real programmer that is easy. Very easy.
« Last Edit: January 15, 2025, 03:01:05 pm by Thaddy »
But I am sure they don't want the Trumps back...

MarkMLl

  • Hero Member
  • *****
  • Posts: 8221
Re: const declaration
« Reply #29 on: January 15, 2025, 03:16:14 pm »
which seem to be not implementable in pascal, as you can't pass a value to macros.

Looks as though it's related to this that I did for talking over SPI:

Code: Pascal  [Select][+][-]
  1. function _IOC(dir, _type, nr: Longword; size: SizeInt): TIOCtlRequest;
  2.  
  3. begin
  4. {$push }{$R- } // If dir is 2 (_IOC_READ) this will set the MSB hence a range error
  5.   _IOC := (dir  shl _IOC_DIRSHIFT) or
  6.           (_type shl _IOC_TYPESHIFT) or
  7.           (nr   shl _IOC_NRSHIFT) or
  8.           (size shl _IOC_SIZESHIFT);
  9. {$pop }
  10. end { _IOC } ;
  11.  
  12.  
  13. function _IOR(_type, nr: Cardinal; size: SizeInt): TIOCtlRequest;
  14.  
  15. begin
  16.   _IOR := _IOC(_IOC_READ, _type, nr, size);
  17. end { _ IOR } ;
  18.  
  19.  
  20. function _IOW(_type, nr: cardinal; size: SizeInt): TIOCtlRequest;
  21.  
  22. begin
  23.   _IOW := _IOC(_IOC_WRITE, _type, nr, size);
  24. end { _IOW } ;
  25.  
  26.  
  27. function SPI_MSGSIZE(n: SizeInt): SizeInt; inline;
  28.  
  29. begin
  30.   if (n * sizeof(spi_ioc_transfer)) < (1 shl _IOC_SIZEBITS) then
  31.     SPI_MSGSIZE := n * sizeof(spi_ioc_transfer)
  32.   else
  33.     SPI_MSGSIZE := 0;
  34. end { SPI_MSGSIZE } ;
  35.  
  36.  
  37. function SPI_IOC_MESSAGE(N: SizeInt): Cardinal; inline;
  38.  
  39. begin
  40.   SPI_IOC_MESSAGE := _IOW(SPI_IOC_MAGIC, 0, SPI_MSGSIZE(N));
  41. end { SPI_IOC_MESSAGE } ;
  42.  

So, not really any problem at all (provided that you're absolutely rigorous with parameter sizes) even if there I've not inlined the functions.

/However/, I refuse to be an apologist for Pascal's lack of parameterised macros, which are even- IIUC- implemented by Rust.

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

 

TinyPortal © 2005-2018