Recent

Author Topic: AI and Free Pascal  (Read 6530 times)

imekon

  • New Member
  • *
  • Posts: 26
AI and Free Pascal
« on: March 31, 2026, 12:09:06 pm »
So I've been on a bit of a journey.

What's all the fuss about with AI and coding?

Can I use it with Free Pascal to create audio units for use in a synthesizer?

The answer turns out to be yes, but with some gotchas.

I used Claude and Cursor with their free version.

The very first unit I asked for was to read a wave file. It generated one that worked and could read wave files, cool!

However:

  • It used magic numbers
  • It generated classes that were probably in a library unit somewhere

I got it to extend the unit to create wave files and allow for WAVEFORMATEXTENSIBLE, which supports more than two channels. I've tested it with mono and stereo but not anything multi channel.

I then got it to generate oscillators - sine, square, sawtooth, triangle. That worked well, though I noticed the code was pretty simple, I could do it myself.

I then asked Claude to create a resampler, to convert between sample rates. Oh dear... it had lots of syntax errors that needed fixing, then once I got it to build, the output was noisy. I looked at the waveform it created and noticed lots of zero crossing glitches. Three times Claude tried to fix the bug, three times it failed. I gave up and tried Cursor.

Cursor generated code with syntax errors but once fixed it could resample quite nicely. The code was muchg simpler and I adapted it to handle more general cases.

I went further and created filters, freeverb and so on, and noticed a pattern. It could generate Free Pascal just fine but sooo many syntax errors!

I did learn one or two things - you can put const in class definition making class constants. The AI just missed the 'var' declaration afterwards.

My conclusion from all this?

AI can generate code and is a useful tool for that. However... it often generates code full of silly mistakes, and sometimes outright doesn't work!

I did wonder how good it was at spotting mistakes so I asked it:

What's wrong with this C++ statement?
Code: C  [Select][+][-]
  1. p->next;

It did spot what the problem was... but how come it couldn't fix the glitch error in resampling?

I keep reading about how AI is replacing coding teams and generating code at high speed - yet my own simple research seems to indicate that it's not at that level yet. I'm not spending money on a tool that isn't 100% reliable, and generates code that won't compile, and in one case, doesn't work properly!

imekon

  • New Member
  • *
  • Posts: 26
Re: AI and Free Pascal
« Reply #1 on: March 31, 2026, 12:18:39 pm »
So why did I chose Free Pascal?

  • Because I used to be a Delphi fan until Borland dropped the ball.
  • Because Free Pascal can write GUI code that is cross platform.
  • Because it doesn't need a makefile generally.

I fugured using an 'out there' language might be difficult for AI as it's not mainstream. It does struggle with the language syntax but generally works - with me looking over its shoulder and spotting problems.


Fred vS

  • Hero Member
  • *****
  • Posts: 3945
    • StrumPract is the musicians best friend
Re: AI and Free Pascal
« Reply #2 on: March 31, 2026, 02:59:02 pm »
I have absolutely nothing against AI, quite the contrary, but they should learn their lessons better.
All of them (Claude, Gemini, Chatgpt, Grok, etc.) make glaring syntax errors in Pascal. And when I ask them to create a program that plays MP3s using UOS, they produce an unusable program, full of syntax mistakes. And even though I show them the errors (which they correct with profuse apologies), by the next session they've forgotten everything and make the same mistakes again.
« Last Edit: March 31, 2026, 03:18:21 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

imekon

  • New Member
  • *
  • Posts: 26
Re: AI and Free Pascal
« Reply #3 on: March 31, 2026, 03:31:29 pm »
I've put together a video here https://youtu.be/cmLB-e-x5Js - this is collecting together all the source code and bolting a UI on top with Free Pascal

backprop

  • Full Member
  • ***
  • Posts: 238
Re: AI and Free Pascal
« Reply #4 on: March 31, 2026, 07:12:28 pm »
What's all the fuss about with AI and coding?

Plain stupidity... All what AI can do is to gather a lot of info and process it in sense to give you "relevant" info. Can't make working code itself at all, nor based on any other code as it  can't understand and connect logically code. What it can do is to collect mishmash code from various sites and that is it.

Recently I did some plain utility in C which suppose to read device identity and S.M.A.R.T data (from HDD, SSD and NVMe drives) and I played also with Google Ai to minimize coding time... But without "Information technology - ATA Command Set - 4 (ACS-4)" I would plainly stuck with code found "who knows where".

« Last Edit: March 31, 2026, 07:35:10 pm by backprop »

440bx

  • Hero Member
  • *****
  • Posts: 6536
Re: AI and Free Pascal
« Reply #5 on: March 31, 2026, 08:05:47 pm »
Can't make working code itself at all, nor based on any other code as it  can't understand and connect logically code. What it can do is to collect mishmash code from various sites and that is it.
I don't believe that would be enough to write a working C compiler in Rust that can compile the Linux kernel.

I also had a very low opinion of A.I until recently when I saw that it can write a C compiler, something which, likely less than 1% of programmers, can do (I'm not talking about some toy compiler, I'm talking about a full fledged C compiler that can compile the Linux kernel to produce a correctly working version of the kernel.)

There may still be a lot of problems/deficiencies with A.I but, it has been demonstrated that in the hands of knowledgeable people, it is an impressive tool.

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Thausand

  • Hero Member
  • *****
  • Posts: 560
Re: AI and Free Pascal
« Reply #6 on: March 31, 2026, 09:34:53 pm »
I don't believe that would be enough to write a working C compiler in Rust that can compile the Linux kernel.
Is not alone you who write but also other.

You have try and download compiler and see you self ?

That is all compiler do, compile Linux kernel. Make try compile hello world and see what do.

AI not /know/ anything. It is make up source-code that is most like for to be (prediction and random/biased because not know learn data). It was read source other compiler and may be even copy-paste source. It not make up compile. AI not have brains, not think and have other human behavior that peope is write about. AI is dumb as copy-machine that have random pixel copy (sometime it copy, sometime it not copy si complete random. No copy is same).

claude is write this for attrac attention because AI bubble is popping balloon. Is same reason why is stop sora. There no compute and money for buy compute because AI dumb and need more and more compute to have pretent it smart. Please have read paper for how implement LLM and see self how AI (today is LLM) is pretend make belief.

If claim for AI true today then life simple but all write please have wait 6 months for have more compute then all world problem is solve by use AI. I wait for competition MS office is write by AI (not have mention all other commercial software and support).
A docile goblin always follow HERMES.md

440bx

  • Hero Member
  • *****
  • Posts: 6536
Re: AI and Free Pascal
« Reply #7 on: March 31, 2026, 09:47:22 pm »
You have try and download compiler and see you self ?
I've read some of the code and, it certainly looks like a  bona-fide compiler to me.

That is all compiler do, compile Linux kernel. Make try compile hello world and see what do.
I admit that I have not tried compiling a "hello world" program with it but, I have no reason to believe it couldn't.  Like FPC can compile Lazarus, it's rather likely that if it can compile Lazarus, it can also compile a trivial "hello world" program.

AI not /know/ anything.
But, that's not a good argument.  A text editor or word processor knows nothing about literature but, in the hands of a capable individual, they can be used to write a great novel or a great program.  It's just a helpful tool and, that's all A.I is.


If claim for AI true today then life simple but all write please have wait 6 months for have more compute then all world problem is solve by use AI. I wait for competition MS office is write by AI (not have mention all other commercial software and support).
A.I isn't going to solve the world's software problems anymore than word processors are going to spontaneously write novels and scripts for Hollywood movies.  A.I is like a hammer, hammers are not going to build skyscrapers all by themselves.

It's just a tool, which in the hands of someone who knows how to use it, can be very helpful.

FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Joanna

  • Hero Member
  • *****
  • Posts: 1460
Re: AI and Free Pascal
« Reply #8 on: April 01, 2026, 02:43:52 am »
lol 44bx AI did not write a c compiler at all, it got code created by real programmers and plagiarized it.

Another thing if you use code that is not open source that is fed to you by AI, intellectual property laws still apply and you can still be sued in court. Unlike the wealthy owners of AI companies who have many attorneys, you will probably lose a lawsuit.

Even if AI didn’t produce horrible code, the legal hazard of intellectual property infringement remains.

speter

  • Hero Member
  • *****
  • Posts: 532
Re: AI and Free Pascal
« Reply #9 on: April 01, 2026, 03:00:04 am »
lol 44bx AI did not write a c compiler at all, it got code created by real programmers and plagiarized it.
Do you know this for a fact, Joanna? Or are you simply assuming that it is so?

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Lauriet

  • New Member
  • *
  • Posts: 45
Re: AI and Free Pascal
« Reply #10 on: April 01, 2026, 03:01:59 am »
From what I see, when I have tried it, is that it just summerizes what is on the net. You could solve your programing problem using a google search and reading some of the pages.
You still need to think about its solution, because many pages on the net have errors.
It has been somewhat helpful when I am reading an obscure datasheet and need an example to clarify things.

440bx

  • Hero Member
  • *****
  • Posts: 6536
Re: AI and Free Pascal
« Reply #11 on: April 01, 2026, 03:24:44 am »
lol 44bx AI did not write a c compiler at all, it got code created by real programmers and plagiarized it.
Really ?... please show the code A.I plagiarized to create that compiler.   You're even better than a bad A.I model at making stuff up.  When you make an accusation, it is considered appropriate to have some foundation for it.

If A.I had just plagiarized code created by some programmers, those programmers and many more would have pointed it out and discredited the result.  Guess what ?... that didn't happen and, the code is public for everyone to inspect and log a complaint if appropriate.

A.I is just a tool, which like all tools, can be misused but, it certainly looks like in the right hands, it can be very helpful.
FPC v3.2.2 and Lazarus v4.0rc3 on Windows 7 SP1 64bit.

Joanna

  • Hero Member
  • *****
  • Posts: 1460
Re: AI and Free Pascal
« Reply #12 on: April 02, 2026, 12:27:12 am »
lol 44bx AI did not write a c compiler at all, it got code created by real programmers and plagiarized it.
Do you know this for a fact, Joanna? Or are you simply assuming that it is so?
cheers
S.
Do you know for a fact that a monkey with a typewriter can’t write novels?
Please provide proof that a monkey can’t type the same things as a human! It has ten fingers doesn’t it?

Where did you think the magic AI comes from? Were you not aware that this forum has been plagued with AI companies and their  thousands scraping bots  collecting information to plagiarize?  :P

jamie

  • Hero Member
  • *****
  • Posts: 7770
Re: AI and Free Pascal
« Reply #13 on: April 02, 2026, 12:50:43 am »
From what I see, when I have tried it, is that it just summerizes what is on the net. You could solve your programing problem using a google search and reading some of the pages.
You still need to think about its solution, because many pages on the net have errors.
It has been somewhat helpful when I am reading an obscure datasheet and need an example to clarify things.

 I for one don't like the concept of AI trying to be wonderful and making people believe they need it, when in fact it's mostly those that have interest in lining their pockets because at some point someone or everyone ends up paying for it. So, because of that, I try my best at campaigning to posting bad code, so AI gets crap. I have also been told that I don't need to work that hard to create bad code because it comes naturally :o

Jamie


The only true wisdom is knowing you know nothing

speter

  • Hero Member
  • *****
  • Posts: 532
Re: AI and Free Pascal
« Reply #14 on: April 02, 2026, 02:25:59 am »
Where did you think the magic AI comes from? Were you not aware that this forum has been plagued with AI companies and their  thousands scraping bots  collecting information to plagiarize?  :P
I've often use AI to translate from material from one programming language to another. The AI in this case, can't just "find" the pascal code, it must (and does) translate the original code into pascal. Most recently, I've been noticing that the AI is producing less garbage and more correctly written code.

cheers,
S.
PS: My previous question was serious, I wasn't "attacking" you, I was truely interested to know if the AI generated compiler was plagiarised.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

 

TinyPortal © 2005-2018