AI Assist Python - to - Pascal? lazarus / 83-Pascal and AI ---------------------------------------------------------------------- Curt Carpenter · 2026-04-07 03:32 I have a programmable instrument (vector network analyzer) that is supported by a bunch of python code.  I would like to convert the python code to Pascal -- a fairly routine project but my first starting from python source (a new and unfamiliar language to me).  Can anyone give me an idea of if/how AI might help me with this translation effort, and if so -- first steps in undertaking its use?   This is strictly a personal interest/hobby project that's been in my project backlog for a few years. (I can use the instrument as a "black box" using the python-based GUI, but I would like to be able to add some features and get a better view of what's going on in that box.) ---------------------------------------------------------------------- 440bx · 2026-04-07 04:09 I am very "green" with A.I but, one thing I have found useful is to use the free Claude Code to get an idea of how well and how much A.I can contribute to a project. If I were you, I'd start with the simplest piece of Python code, the one you believe is the easiest to port and go through the process of getting Claude Code to produce a Pascal port.  I am sure you'll learn a number of useful things in the process, such as, what it can and cannot do well, as well as how to present/phrase your request to get the best results (that's actually very important.) I don't know how much experience you have with A.I but, it you are a beginner (like me), I suggest you follow the tutorials offered by Anthropics.  While they are a bit slow paced for my taste, I have found them useful. HTH. ---------------------------------------------------------------------- egsuh · 2026-04-07 05:30 I tried to convert a C/C++ program (quite large) to pascal, but not very successful yet. AI gives a whole framework or structure, which is not much helpful. ---------------------------------------------------------------------- Wallaby · 2026-04-07 06:37 It depends. Something like AI chat wouldn't be helpful much, however using something like Claude Code or Codex could have done it in hours, depending on the size of it. It would have to be a rewrite rather than conversion, but yes very doable and very easy especially if you have some testable input/output. ---------------------------------------------------------------------- gidesa · 2026-04-07 11:22 I think that, when using AI tools, you have to know the argument, at a minimum in general mode. You say not knowing anything of Python (although knowing well Pascal), so you haven't great chances to verify the correctness of translation Python-Pascal. That is, maybe Pascal code is formally correct, but it hasn't correct match with Python one. ---------------------------------------------------------------------- Thaddy · 2026-04-07 12:56 Unless you also translate the myriad of standard libraries (written in other languages than python) this is a huge task: compared to FreePascal, with even just the system unit, Python on its own is very, very limited. FreePascal on its own is already very powerful. ---------------------------------------------------------------------- LeP · 2026-04-07 13:13 Is not what OP asked, but may I suggest this: https://github.com/lmbelo/python4delphi It's a component that allows the use of Python within Delphi or Lazarus. I used it to build a DLL in Delphi (python module .pyd) for a project that Python can uses (i.e., exactly the opposite of what it was designed to do). ---------------------------------------------------------------------- marcov · 2026-04-07 17:00 Quote from: LeP on April 07, 2026, 03:13:16 pmIs not what OP asked, but may I suggest this: https://github.com/lmbelo/python4delphi It's a component that allows the use of Python within Delphi or Lazarus. I used it to build a DLL in Delphi (python module .pyd) for a project that Python can uses (i.e., exactly the opposite of what it was designed to do). There are several bugreports for python4delphi related to custom variants. So I wouldn't assume it working ---------------------------------------------------------------------- LeP · 2026-04-07 17:49 Quote from: marcov on April 07, 2026, 07:00:19 pmThere are several bugreports for python4delphi related to custom variants. So I wouldn't assume it working Where are those ? ---------------------------------------------------------------------- marcov · 2026-04-07 19:10 Quote from: LeP on April 07, 2026, 07:49:22 pmQuote from: marcov on April 07, 2026, 07:00:19 pmThere are several bugreports for python4delphi related to custom variants. So I wouldn't assume it working Where are those ? Jus throw "custom variant(s)" into the bugtracker and you'll find nuggets like https://gitlab.com/freepascal.org/fpc/source/-/work_items/20849 ---------------------------------------------------------------------- speter · 2026-04-07 23:18 In regard to the original question:Quote from: Curt Carpenter on April 07, 2026, 05:32:09 am...  I would like to convert the python code to Pascal... I have had a lot of success getting BASIC (from the 1980s Spectrum pc) translated to pascal. The original code was quite short though (<200 lines); but the AI was able to understand the idiosyncrasies of the old version of basic. The original code did a lot of screen positioning to write the map & messages, I requested this be changed into a 2d array to represent the "screen"... the AI was able to handle all that quite well. I would expect (modern) python to be much easier to translate than 48 year old basic; but I think it depend a lot of the length of the script (and the phase of the moon  ). cheers S. ---------------------------------------------------------------------- schuler · 2026-04-08 00:17 Regarding "programmable instrument (vector network analyzer) that is supported by a bunch of python code", is this open source? If yes, is it on github/gitlab? ---------------------------------------------------------------------- Curt Carpenter · 2026-04-08 03:02 Thanks for all the inputs.  I signed up for Claude101 today (https://anthropic.skilljar.com/claude-101) and watched the first video.  Wish there was a "Hello, world!" sort of thing    Also looked briefly at the python code for my hardware and I see that a lot of it is buried in libraries which will complicate things as Thaddy mentioned, but that's normal for this sort of project.  No idea how many levels of nested library code may be involved, but maybe the AI can tell me if I ever get that far. Quote from: schuler on April 08, 2026, 02:17:23 amRegarding "programmable instrument (vector network analyzer) that is supported by a bunch of python code", is this open source? If yes, is it on github/gitlab? The python for the VNA has been sitting in my download folder for a few years  so I don't remember where it came from.  It's called "pynanovna."  I would guess it was from github -- certainly somewhere on the web. ---------------------------------------------------------------------- gidesa · 2026-04-08 09:39 Quote from: speter on April 08, 2026, 01:18:45 amI would expect (modern) python to be much easier to translate than 48 year old basic. Python is much more complicated than Basic of '80. Think only to object oriented part, or functional constructs. Including (importing) external files add other complexity (Spectrum Basic can include external files? I think no). ---------------------------------------------------------------------- Thaddy · 2026-04-08 13:08 Quote from: gidesa on April 08, 2026, 11:39:25 amPython is much more complicated than Basic of '80. Think only to object oriented part, or functional constructs. It is the Python ecosystem that can be complicated, not the language as such, because most of Python's real functionality lies in its extensive use of libraries mostly written in other, much more low- level languages. Which also makes it much harder to port: in effect you have to port the - interface to - those libraries too. ---------------------------------------------------------------------- Thausand · 2026-04-08 13:56 Quote from: Curt Carpenter on April 08, 2026, 05:02:50 amThe python for the VNA has been sitting in my download folder for a few years  so I don't remember where it came from.  It's called "pynanovna."  I would guess it was from github -- certainly somewhere on the web. Here is program for nanovna and is write in cpp/windows and may be can help ( https://github.com/OneOfEleven/NanoVNA-App ) I no think rewrite mathplot and numphy for pascal is work (like write other: is many complicate translate). ---------------------------------------------------------------------- Curt Carpenter · 2026-04-08 16:13 Thanks for the link to the C code, I downloaded the zip and will have a look.  I've done C++ conversions before in projects like this.  Huge time sinks!  Really interested in how much help Claude AI can be but am finding it hard to gain traction on where to start.  (I'm sure it's not that hard -- I just don't have the energy I used to.) ---------------------------------------------------------------------- gidesa · 2026-04-08 16:42 Quote from: Thaddy on April 08, 2026, 03:08:36 pmIt is the Python ecosystem that can be complicated, not the language as such, because most of Python's real functionality lies in its extensive use of libraries mostly written in other, much more low-level languages. Which also makes it much harder to port: in effect you have to port the - interface to - those libraries too. Absolutely. But was a comparison between Spectrum Basic and Python as a languages :-) Python simply is much popular among people that work in some software areas, as: AI, big data, scientific/research, and others. It's not so popular in other  areas, for example Android development. EDIT: it's also popular as a scripting language in many complex softwares, as Blender for 3D graphic. ---------------------------------------------------------------------- Thausand · 2026-04-08 17:41 @Curt May be I not understand correct. VNA protocol is have 2 version, version 1 and version 2. version 1 ascii and version 2 binary. When read it say it is use serial device and send data (have baudrate, stopbits etc) and use version 1 protocol (please have make self verification that true. I only have make quick look so may be I wrong). BTW source for python pynanovna is https://github.com/PICC- Group/pynanovna Then I think is easy and all have do is port protocol. Can use python version or cpp version and should be same. Maybe cpp version tiny better for understand how port protocol for Pascal (may be also for LLM). Then have receive data test. When have data receive then have see how is make code for process data. Then data is process for display graphics. Python is use mathplot library for draw graph data. Cpp version have use own solution. Lazarus have TAChart graphic that make graphic like mathplot. Then I think is may be good idea and learn how is work TAChart and how is organize data for make graphic with TAChart. Then have find how make serial data and make code convert and store properties for have draw for TAChart. Information TACHArt https://wiki.freepascal.org/TAChart and https://wiki.freepascal.org/TAChart_Demos May be have make more small step for LLM for help. If lucky then may be LLM understand protocol and not have need source-code and can ask for please have write pascal implementation for protocol for VNA device. Have note that is available free AI online and can have ask question about protocol. May be one have knowledge and can help for that and not have pay LLM use. I have ask duck AI "what protocol is use nanovna device for communicate computer" and it have write information. QuoteThe NanoVNA device typically communicates with a PC using a USB connection and employs a serial communication protocol. This allows users to control the device and retrieve data through software applications. Communication Protocol for NanoVNA Connection Method The NanoVNA device communicates with a PC using a USB connection. This allows for easy data transfer and control of the device. Protocol Details The communication between the NanoVNA and the PC utilizes a serial communication protocol. This protocol enables users to send commands to the NanoVNA and receive measurement data through compatible software applications. Summary of Features FeatureDescriptionConnection TypeUSBCommunication protocolSerial communication protocolFunctionalityControl device and retrieve data This setup allows users to effectively manage the NanoVNA and analyze data on their computers. You can have ask LLM for write what is step for make plan. Then have make plan execute small step 1, then small step 2 etc. So no have think anything. That is why I not have like AI: it have make lazy ---------------------------------------------------------------------- Curt Carpenter · 2026-04-08 20:32 Thank you for the information Thausand.  The nanovna project is more a way to try and learn something about AI than to build a Lazarus/Pascal interface for the hardware (which can be used with no PC connection at all and has it's own GUI of sorts).  My only contact with AI is via google, so it's all unknown territory for me.  I am lazy though, so if ClaudeAI can poop out a working program for me, I won't say no    -- it would be a good starting point.   We'll see.  For now, it's just an adventure. ---------------------------------------------------------------------- PascalDragon · 2026-04-10 05:25 Quote from: marcov on April 07, 2026, 07:00:19 pmQuote from: LeP on April 07, 2026, 03:13:16 pmIs not what OP asked, but may I suggest this: https://github.com/lmbelo/python4delphi It's a component that allows the use of Python within Delphi or Lazarus. I used it to build a DLL in Delphi (python module .pyd) for a project that Python can uses (i.e., exactly the opposite of what it was designed to do). There are several bugreports for python4delphi related to custom variants. So I wouldn't assume it working Considering that the one you linked later on is closed, I'd say that 3.3.1 is better in that regard than 3.2.2 (and I think the fix is also in 3.2.3) and as long as one doesn't rely on implicit casts (the bug report referenced in the end of that bug report) then one should be able to use it rather well... 🤔 ---------------------------------------------------------------------- kirtu · 2026-06-15 22:57 As noted the main issue with python is the extensive environment. To get started you could simply write a python to Pascal parser using the standard tools (in the old days: Bison, yacc, lex, flex).  These will work to get you started. But you also have software controlling or interfacing with hardware.  Likely the hardware interfaces were written in C or maybe asm.  Pretty much the only way to tackle it is to translate as much as possible and then to see where it fails and then see what you need to do from there. The other way is to take a very trivial operation that the current software executes, nd implement that in Pascal directly.  Then you expand that functionality as you go. I would imagine that Claude could translate the python to Pascal and might have useful clues on the lower level stuff just because the documentation might b available somewhere.  However I haven't tried this myself yet.