Shop Learn
Forth for GUI programming on PC — Parallax Forums

Forth for GUI programming on PC

ErNaErNa Posts: 1,663
edited 2021-10-13 17:25 in ForthSpace

Why the hell I do not program my PC's with Forth? Wouldn't that improve experience and application within a short time and allow to programm PC and P2 and P1 in a common language, at least, in a type of dialect?
As I think about this question another one raises: Anyone around who does it and what system I should I use to share experiences and help?
Searching I found those answers I never asked.

And watching a a free man talking.

Comments

  • MaciekMaciek Posts: 506
    edited 2021-10-13 18:00

    It's a tough one.

    My answer is simple but many will not like it - I hate GUIs and I have tried more of them than that I actually wanted.
    Maybe it's just stupid me but for me GUIs are personal thing. Sooner or later I find some features of the GUI I'd like to have missing and other ones buried deep in the menus or simply hostile in use and that is annoying. After a while that unpleasant experience grows on me to a point that I can no longer stand using it and that's the end of the story for me. It might be I have not found my perfect GUI yet and writing my own is out of the question as I lack the right skills and patience.

    As to the Forth on the PC. This eventually comes to a point where an adoption of a common standard is necessary. And having a standard of some sort agreed on and adopted you just have to stick to it and that, again it's my personal view only, imposes some limitations and forces you to make choices you'd rather avoid if not for te standard. That kills the whole idea of Forth to me. Forth is a personal thing, tailored for a particular, often unique need or to solve some problem possibly no one else has. It's a way of thinking and doing things without being constrained to some, usually many, rules defined by a standard. Forth is different.

    Another thing is libraries. Libraries are fine as long as one can fully understand what exactly are they doing and when. The more universal the library the better chance more people will use it but it also means the library itself has a tendency to grow to cover more and more use cases and it gets to a point when one looses the track of what's actually in it so one needs to learn how to use the library for ones needs and that takes time. Sometimes a lot of time. And libraries have to adhere to some standard too to be easily included in a program and that means another overhead in them and a path to follow to write your own library.
    If such library is for something common the effort might be worth it but if it's a rarity nobody else needs it's a waste of time.

    Hopefully there are more optimistic and better answers to your questions than these.

  • ErNaErNa Posts: 1,663
    edited 2021-10-13 18:55

    There is no way around: people like clickybunti. What I miss is a very simple functionality: I want to control a PC via remote. From the Propeller. So the PC should just be a server to the P, were I can poll a mouse and keyboard, print output to a screen and work with files of the file system. Then I could forward the keyboard to the propeller and the propeller could open a file in the file system and read and write to it. What should I want more if the terminal can also do graphics?
    But to program such a program I have to use a common language, learn about the OS API and write this program, so I waste time I could have invested to broaden or even found Forth (Tachyon, TAQOZ) skills. So it's learning by doing. I do not know how responsive Forth on the PC will be, but I can imagine it will be better than any other interpreted language.
    Now I have to write code on a PC using an editor and to download it into TAQOZ. Then I would write write programs on the PC and TAQOZ could fetch them from file by itself, wherever in the world my FORTH-app is running. It's a small difference that makes a huge difference.
    And when it comes to the words of a language: German knows about 300.000 words the average man uses 3000 of. ;-) There is nothing bad in speaking Forth dialect if the app does what was intended.

    And to come to an decision I decided to use SwiftForth for now as it is free as long as it makes no sense to use it ;-) Otherwise it should be worth every buck spend.

  • MaciekMaciek Posts: 506
    edited 2021-10-13 20:26

    Ah, SwiftForth.
    I played with it some 4 or 5 years ago (windows version as I think only that was available back then) but IIRC, the free version was time limited with 30 days trial period so It was no enough time for me back then.
    Looks like a huge improvement in licensing these days but .... as you cleverly said

    it is free as long as it makes no sense to use it ;-)

    which may not be for long once you fall in love with it but it is certainly worth to try it out for free first.

    EDIT: bear in mind that SwiftForth produces binaries for x86 and not the P1or P2 architectures so you'd need a cross compiler for these but does it exist ?

  • ErNaErNa Posts: 1,663

    The PC words and the P words sometimes will be different, two dialects and two purposes. To me the GUI only is a frame that can, controlled by the propeller, create windows and widgets in the windows. So it's more or less a server. To me a main feature will be that I can select between RAM, FLASH, SD and PC whenever I read or write files

  • @ErNa said:
    Why the hell I do not program my PC's with Forth? Wouldn't that improve experience and application within a short time and allow to programm PC and P2 and P1 in a common language, at least, in a type of dialect?
    As I think about this question another one raises: Anyone around who does it and what system I should I use to share experiences and help?
    Searching I found those answers I never asked.

    And watching a a free man talking.

    Hi ErNa,
    just some days ago again I asked those questions myself, when I made the graphics frontend for my P2 project.

    I think the reasons to use forth are -at least for me:
    Have an operating system, which is interactive AND fast with very small resources.
    Speed and low resources make it necessary, that things have to be kept simple. So there are restrictions.
    The real benefit comes, if you can use the built in features for your application: It's interactivity, it's block file system,...

    A PC has got a lot of RAM and a lot of speed, so here Python is used often, which is very much slower and very much more complicated.
    I suspect, that you can achieve your goals faster, if you use Python.

    I did use Win32Forth, Version 6.05 (the last one, that does not alert virus defenders.) I like it. I got it from: http://www.inventio.co.uk/LegacyIndex.htm (Do you know it's editor? It is just great, because it can generate hypertext links to all word definitions. Automatic documentation! )
    There are documents for this forth available: http://win32forth.sourceforge.net/doc/p-index.htm
    When I did a little project with this Forth, I discovered, that using Windows graphics, you actually do not use the interactive console any more. It's more like the usual edit-compile (load)-run cycle, so the advantage of Forth for interactive debugging gets lost.

    Still I think, that it should be possible to achieve your goal of a server with Win32Forth.
    Perhaps things might be simpler, if you can use DosBox with FPC also by Tom Zimmer.

    Ah, I saw, that you decided to use Swift Forth. Can you recommend it?
    Christof

  • ErNaErNa Posts: 1,663

    Hi christof and the rest of the world: I was just looking for a currently supported system were I also could get some professional help, if needed and so I found Swift Forth. My goal is just to have a PC program as the server running that can evolve over the time. A step by step (word by word) approach. If you have something similar I also could bring it up running and start from there. Travelling by train I had a first look to the documentation. The goal is to do as much as possible on the P2 &TAQOZ path. Being back I'll see what I can do.

  • Hi ErNa,
    just 2 additional thoughts:
    1. As far as I can remember Peter already had a fileserver on the PC side. I think it was included into the download tool. I assume, it works with a second serial connection in parallel to the terminal.
    2. If the idea is to do as much as possible on the P2, an editor at P2 might be used. Did you already have a look at the editor of Taqoz? It uses fixed line lengths but it supports a lot of cursor movement. I did not yet find out, how to use it for source code. An other possibility is to port http://www.murphywong.net/hello/lf.htm . It can work with normal text files.

  • I think SED can be used on any file including the one residing on the SD, so possibly that is the way to go. Edit a source file on the SD and read it back to the P2 but I haven't tried that yet.

  • ErNaErNa Posts: 1,663

    I started to understand SED and stumbled about immediate instructions just before Peter went offline. Then I was busy but now I come back and will invest my time in programming what I need, using TAQOZ and the P2 as much as possible. I see a computer as a network of abilities and all those abilities are alway callable, so the concept of a data flow machine might be the right model. Piping at it's best ;-)

  • ErNaErNa Posts: 1,663

    I have the KISS boards, the carrier ManAtWork made for his testers and the same small displays with touch as the current hardware base. Later I will buy or make the P2D2 boards and companions. Many problems "we" face come from subtle differences in the hardware. As we try to keep the objects universal over the hardware we loose the focus on universality over problems to solve. We spent so much precious time over saving some bugs for hardware. grrr.
    Microsofts success is mainly based on Gates ability to force hardware manufacturers to follow his restrictions. CP/M failed not only from the fact, that every user had to modify the bios, the boot sector, to serve the different floppy drives and formats. As Gates could focus on business and had no skills related to the underlying technology, he won that war. It needed a genius to create the success of Apple. And a lot of luck. The first is easier the acquire ;-) So let's do it!

  • MaciekMaciek Posts: 506
    edited 2021-10-15 09:30

    Peter didn't go offline. He has just not been present here on the forum. To speed things up considerably I would suggest to maybe visit his sourceforge page or the one for Mecrisp Stellaris there too. Wouldn't hurt but could help. You will not know until you tried :).

    EDIT: from what I recall, he's not been very enthusiastic about forth on the PC and I happen to share his view as well but things might change...who knows.

  • ErNaErNa Posts: 1,663

    Went offline from the viewpoint of Parallax ;-) And: I see a forth on a pc as a way to bring the idea to others that don't have the P solution at hand yet or are reluctant and so can gain some first insight into the forth.

  • I hope you will not be disappointed in your efforts of bringing Forth to the broader audience. I really do, and I wish you best of luck and even I am eager to support that effort but...there is always that dreaded "but" and that is...
    Well, perhaps I will use an example to illustrate my thoughts.

    Pizza is what comes to my mind instantly. Most of the people I know like pizza and so do I. The majority of these people like just pizza. Some of them, and that is not a very large group, like a specific kind of pizza that is not all that common these days and let's call it a good pizza. Even smaller group likes, and buys, only the pizza they regard as being an excellent pizza. That is a rarity to get, believe me. The fraction of that last group would like to make their own, custom pizzas and I only know a single person from that tiny group who actually attempted to try it and it took him a few years of that said attempts to be satisfied with what he has made.

    But how that relates to Forth ?

    Windows is like just pizza, unix/linux/BSD systems are like good pizza and Forth is like an excellent, custom pizza that only a tiny fraction of pizza lovers are determined to make their own, personal system of choice.

    Why's that ?

    Because it takes an idea, a determination and discipline. And often you're left with no one around to ask a question or for help. And it needs lots of practice time people are rarely willing to dedicate to make their dreams come true these days .

    If one wants an easy way, one chooses the mainstream solution with all the conveniences and bloat too.
    If one wants more freedom and control, one choses the solution that gives him/her more or less what one wants, which is not that convenient or popular perhaps but does the job better.
    If one wants total control over everything he/she wants or needs to control, one must choose the solution that one can "talk to" and it understands the language and obeys the orders. And that often means one must create that solution on ones own, that is tailored to his/hers specific needs.

    And that is what I think Forth is all about.
    A personal solution to a personal problem done in a personal way. And because of that it has, unfortunately, very little chance to be a popular system/language of choice for an average user. It's not a fault or a bug. It is a characteristic or a feature.

    I've since long time accepted the fact that people have different needs and different ways of thinking or doing things and that is perfectly fine and inspiring.

  • Writing a more-than-trivial Windows application especially if it's one person takes a lot of effort. Forth would not be my first choice of language. It's possible to do, but a bit like driving all the time in first gear. You could say the same of assembly language. I would choose a language that had the most features to suit the application already done for me. In my case, for anything to do with control and measurement, I would choose LabVIEW, definitely driving in sixth gear with that. I wouldn't use LabVIEW to write a word processor though. Tools and libraries from the community are a big decider too. The Forth community is relatively poor in that respect. I therefore prefer forth for microcontroller projects but not for Windows.

  • ErNaErNa Posts: 1,663

    The goal (one of many) is to show the force of forth even on a pc. As I said before: fetch a command from a serial device and call a function of the OS eg Windows. Return the result to the serial device. Not to sophisticed as can be, just KISS

  • I can see yet another opportunity to speak my mind on the subject so I will.

    In my childhood I often visited my grandparents in the country. Among other things like helping them with their daily routines I have always managed to carve out some time for myself when I climbed the trees out of their sights. The taller the tree was, the better. I loved that and they hated when I did it for obvious reasons and I could never quite understand that back then.

    Now back to Forth - showing the power of Forth is like climbing a tall tree. It's fun, it's challenging and it gets peoples attention and mostly admiration (maybe some disbelief or even anger in some cases) but...convincing people to use Forth is like climbing down that tall tree - it's scary, it's difficult and dangerous.

    I have never fallen off the tree when climbing up but many times I have done so when on the way down. Did it hurt ? Yes, and sometimes much. Did I got discouraged by these unpleasant events ? Never !
    I love Forth but I also do not use forth on a PC. But why, one might ask ?
    Let's just say I grew up in exactly the same way I grew up from climbing the trees but ... I am going to give it a go one more time. Just like in the old days :).

  • ErNaErNa Posts: 1,663
    edited 2021-10-18 19:10

    Climbing a tree means to decide every furcation which branch to go. If you end up in a cul-de-sac you have to step back and start over. Once you decide to go FORTH you never should go below that level, but just make the tree grow where you want to go. As I downloaded Swiftforth and start to look, how the words are used, it's only slightly different from the way Peter showed us. It's still confusing too.
    But look here: I'll try to understand how this works and to me it look like a lot of work already done ;-)

    DIALOG SELCOM
    
    [ MODAL " Select ComPort" 20 20 80 63  ]
       [ DEFPUSHBUTTON     " OK"                         1    6    48   32   12 ]
       [ PUSHBUTTON        " Cancel"                     2    42   48   32   12 ]
       [ AUTORADIOBUTTON   " Com &1"                     101  6    14   32   10 ]
       [ AUTORADIOBUTTON   " Com &2"                     102  6    28   32   10 ]
       [ AUTORADIOBUTTON   " Com &3"                     103  42   14   32   10 ]
       [ AUTORADIOBUTTON   " Com &4"                     104  42   28   32   10 ]
       [ GROUPBOX          " Select ComPort"             -1   2    2    76   42 ]
    END-DIALOG
    
    : PICKED ( -- n )
       5 1 DO
          HWND I 100 + IsDlgButtonChecked IF I UNLOOP EXIT THEN
       LOOP 0 ;
    
    [SWITCH SELCOM-COMMANDS DROP ( wparam -- )
       IDOK RUN:
          HWND  PICKED  EndDialog ;
       IDCANCEL RUN:
          HWND 0 EndDialog ;
    SWITCH]
    
    [SWITCH SELCOM-MESSAGES ZERO ( msg -- res )
       WM_COMMAND RUN:
          WPARAM LOWORD SELCOM-COMMANDS ;
       WM_INITDIALOG RUN:
          HWND 101 104 LPARAM 1 MAX 4 MIN 100 + CheckRadioButton DROP ;
    SWITCH]
    
    :NONAME ( -- res )   MSG LOWORD SELCOM-MESSAGES ;  4 CALLBACK: SELCOM-CALLBACK
    
    : SELECT-PORT ( initial -- new )
    
    
      R HINST SELCOM HWND SELCOM-CALLBACK R> DialogBoxIndirectParam ;
    
    
    

    I can imagine this to be managable. At least, not more cryptic than what I'm used from Tachyon ;-)

  • ErNaErNa Posts: 1,663
    edited 2021-10-20 10:17

    I found some time to play with this word SELECT-PORT and at least I could modify the messages. Now more reading and looking what more is available to work with windows...
    For example, the GDITools file show this introduction:

    Miscellaneous graphic and window tools
    
    Copyright 2001  FORTH, Inc.
    ==================================================================== }
    
    OPTIONAL GDITOOLS Miscellaneous graphic and window tools
    
    { --------------------------------------------------------------------
    Graphics Device Interface (GDI)
    
    The GDI provides a set of generic graphics functionsthat can be used to
    draw to the screen, to memory, or even to printers.
    
    The GDI revolves around an object called the Device Context (DC),
    represented by the data type HDC (Handle to Device Context). An HDC is
    a handle to something you can draw on; it can represent the entire
    screen, an entire window, the client area of a window, a bitmap stored
    in memory, or a printer. You don't need to know which one it refers
    to, which is especially handy for writing custom drawing functions .
    
    An HDC, like most GDI objects, is opaque; you can't access its data
    directly, but you can pass it to various GDI functions that will
    operate on it, either to draw something, get information about it, or
    change the object in some way.
    -------------------------------------------------------------------- }
    

    Funny: where comes the bold face from ?

  • I use this "Forth-like" language for cross platform GUI development, It is well worth a look with heaps of in-built libraries and the support is excellent. The great advantage is, develop one set of code and then use the build tool to output to Windows, MacOS, Linux, Android, iOS and even raspberry pi!

    https://8th-dev.com/

    I pay for the professional version, but the free version is pretty capable, just misses some extra features like blue-tooth.

Sign In or Register to comment.